Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mgamal92 committed Oct 3, 2022
2 parents a58933b + 1ddf4f4 commit 288f8c6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is an integration between Laravel framework and Paymob API to make it easie
You can install the package via composer:

```bash
composer require mgamal/laravel-paymob
composer require mgamal/paymob-laravel
```

Optionally, you can publish the config file with:
Expand Down
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 @@ -69,17 +121,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 @@ -237,8 +287,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 288f8c6

Please sign in to comment.