Skip to content

Commit

Permalink
update amount
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-hany-elsaid committed Dec 8, 2022
1 parent 015ed1c commit babf9d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
97 changes: 51 additions & 46 deletions src/Paymob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Alaa\Paymob;

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Exception;

class Paymob
{
Expand All @@ -23,40 +23,56 @@ class Paymob
"created_at" => 0
];


/**
* @param PaymobClient $paymobClient
* @return array
*/
public static function setPaymobClient(PaymobClient $paymobClient)
public static function getConfig()
{
self::$paymobClient = $paymobClient;
return self::$config;
}

/**
* @return PaymobClient
* @param array $config
*/
public static function getPaymobClient()
public static function setConfig(array $config)
{
if (self::$paymobClient == null) self::$paymobClient = new PaymobClient();
return self::$paymobClient;
self::$config = $config;
}

/**
* @return array
* @throws GuzzleException
* @throws Exception
*/
public static function getConfig()
public static function card($amount, $billing_data, $items = [], $delivery_needed = false, $additional_info = [], $lock_order_when_paid = false)
{
return self::$config;
if (!(isset(self::$config['cards_iframe']) || isset(self::$config['default_iframe']))) throw new Exception("please set a valid cards iframe or default iframe");
if (!(isset(self::$config['card_integration']))) throw new Exception("please set a valid card_integration");
$res = self::generatePaymentKeyWithOrderId(self::$config['card_integration'], $billing_data, $amount, $items, $delivery_needed, $additional_info, $lock_order_when_paid);
$res["url"] = "https://accept.paymobsolutions.com/api/acceptance/iframes/" . (isset(self::$config['cards_iframe']) ? self::$config['cards_iframe'] : self::$config['default_iframe']) . "?payment_token=" . $res["payment_key"];
return $res;
}

/**
* @param array $config
* @throws GuzzleException
*/
public static function setConfig(array $config)
private static function generatePaymentKeyWithOrderId($integration_id, $billing_data, $amount, $items = [], $delivery_needed = false, $additional_info = [], $lock_order_when_paid = false)
{
self::$config = $config;
}
$order = self::getPaymobClient()->registerOrder(self::getAuthToken(), array_merge([
"amount_cents" => $amount,
"items" => $items,
"delivery_needed" => $delivery_needed,

], $additional_info));
return ["payment_key" => self::getPaymobClient()->generatePaymentKey(self::getAuthToken(), $order->id, $integration_id, $billing_data, [
"amount_cents" => $amount,
"expiration" => isset(self::$config["expiration"]) ? self::$config["expiration"] : 60 * 30,
"currency" => isset(self::$config['currency']) ? self::$config['currency'] : "EGP",
"lock_order_when_paid" => $lock_order_when_paid
]),
"order_id" => $order->id

];
}

/**
* @return string
Expand All @@ -75,18 +91,21 @@ public static function getAuthToken()
}

/**
* @throws GuzzleException
* @throws Exception
* @return PaymobClient
*/
public static function card($amount, $billing_data, $items = [], $delivery_needed = false, $additional_info = [], $lock_order_when_paid = false)
public static function getPaymobClient()
{
if (!(isset(self::$config['cards_iframe']) || isset(self::$config['default_iframe']))) throw new Exception("please set a valid cards iframe or default iframe");
if (!(isset(self::$config['card_integration']))) throw new Exception("please set a valid card_integration");
$res = self::generatePaymentKeyWithOrderId(self::$config['card_integration'], $billing_data, $amount, $items, $delivery_needed, $additional_info, $lock_order_when_paid);
$res["url"] = "https://accept.paymobsolutions.com/api/acceptance/iframes/" . ( isset(self::$config['cards_iframe']) ? self::$config['cards_iframe'] : self::$config['default_iframe']) . "?payment_token=" . $res["payment_key"];
return $res;
if (self::$paymobClient == null) self::$paymobClient = new PaymobClient();
return self::$paymobClient;
}

/**
* @param PaymobClient $paymobClient
*/
public static function setPaymobClient(PaymobClient $paymobClient)
{
self::$paymobClient = $paymobClient;
}

/**
* @throws GuzzleException
Expand All @@ -109,28 +128,14 @@ public static function mobileWallet($wallet, $amount, $billing_data, $items = []
return $res;
}


/**
* @throws GuzzleException
*/
private static function generatePaymentKeyWithOrderId($integration_id, $billing_data, $amount, $items = [], $delivery_needed = false, $additional_info = [], $lock_order_when_paid = false)
{
$order = self::getPaymobClient()->registerOrder(self::getAuthToken(), array_merge([
"amount_cents" => $amount,
"items" => $items,
"delivery_needed" => $delivery_needed,

], $additional_info));
return ["payment_key" => self::getPaymobClient()->generatePaymentKey(self::getAuthToken(), $order->id, $integration_id, $billing_data, [
"amount" => $amount,
"expiration" => isset(self::$config["expiration"]) ?self::$config["expiration"] : 60 * 30,
"currency" => isset(self::$config['currency']) ? self::$config['currency'] : "EGP",
"lock_order_when_paid" => $lock_order_when_paid
]),
"order_id" => $order->id

];
}
//
// public static function validateTransactionCallback($transaction)
// {
//
// if (!isset(self::$config['HMAC'])) throw new Exception("please set a HMAC to validate transaction");
//
//
// }


}
1 change: 0 additions & 1 deletion src/PaymobClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function generatePaymentKey($auth_token, $order_id, $integration_id, $bil
"integration_id" => $integration_id,
"billing_data" => $billing_data,
"expiration" => 60 * 30,
"amount_cents" => 0,
"currency" => "EGP",
], $info)
])->token;
Expand Down

0 comments on commit babf9d4

Please sign in to comment.