Skip to content

Commit

Permalink
Merge pull request #11 from MostafaEzzelden/master
Browse files Browse the repository at this point in the history
dynamically switched between payment channels on runtime
  • Loading branch information
mgamal92 authored Sep 27, 2022
2 parents dddec94 + e2287a6 commit 627d678
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions src/Paymob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,59 @@
class Paymob
{
const URL = 'https://accept.paymob.com/api';

/**
* The Integration ID
*
* @var String
*/
protected $integrationId;

/**
* The Iframe ID
*
* @var String
*/
protected $iframeId;

/**
* Constructor
*
* @param string|null $integrationId
* @param string|null $iframeId
*/
public function __construct(string $integrationId = null, string $iframeId = null)
{
$this->integrationId = $integrationId ?: config('paymob.auth.integration_id');
$this->iframeId = $iframeId ?: config('paymob.auth.iframe_id');
}

/**
* Set The Integration ID
*
* @param string $integrationId
* @return self
*/
public function setIntegrationId(string $integrationId): self
{
$this->integrationId = $integrationId;

return $this;
}

/**
* Set The Iframe ID
*
* @param string $iframeId
* @return self
*/
public function setIframeId(string $iframeId): self
{
$this->iframeId = $iframeId;

return $this;
}

/**
* Paymob Authentication
*
Expand Down Expand Up @@ -68,17 +120,15 @@ public function makeOrder(string $token, bool $deliveryNeeded, int $amountCents,
* @return array
*/
public function getPaymentKey(string $token, int $amountCents, int $expiration, int $orderId, array $billingData, string $currency): array
{
$integrationId = config('paymob.auth.integration_id');

{
$json = [
'auth_token' => $token,
'amount_cents' => $amountCents,
'expiration' => $expiration,
'order_id' => $orderId,
'billing_data' => $billingData,
'currency' => $currency,
'integration_id' => $integrationId
'integration_id' => $this->integrationId
];

$response = Http::post(
Expand Down Expand Up @@ -235,8 +285,7 @@ private function createPaymentToken(string $authToken, string $orderId, array $d
*/
private function buildIframeUrl(string $paymentToken): string
{
$iframeId = config('paymob.auth.iframe_id');
$iframeUrl = 'https://accept.paymobsolutions.com/api/acceptance/iframes/'. $iframeId .'?payment_token='.$paymentToken;
$iframeUrl = 'https://accept.paymobsolutions.com/api/acceptance/iframes/'. $this->iframeId .'?payment_token='.$paymentToken;
return $iframeUrl;
}
}

0 comments on commit 627d678

Please sign in to comment.