Skip to content

Commit

Permalink
[fix] check if not set fallback url set callback url , and convert it…
Browse files Browse the repository at this point in the history
…ems to rial (shetabit#162)
  • Loading branch information
alissn authored Sep 3, 2022
1 parent db02227 commit efe50c0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Drivers/Azki/Azki.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function __construct(Invoice $invoice, $settings)
$this->invoice($invoice);
$this->settings = (object)$settings;
$this->client = new Client();
$this->convertAmountItems();
}

public function purchase()
Expand All @@ -82,7 +83,10 @@ public function purchase()

$merchant_id = $this->settings->merchantId;
$callback = $this->settings->callbackUrl;
$fallback = $this->settings->fallbackUrl;
$fallback =
$this->settings->fallbackUrl != 'http://yoursite.com/path/to' && $this->settings->fallbackUrl == ''
? $this->settings->fallbackUrl
: $callback;
$sub_url = self::subUrls['purchase'];
$url = $this->settings->apiPaymentUrl . $sub_url;

Expand Down Expand Up @@ -153,7 +157,7 @@ private function makeSignature($sub_url, $request_method = 'POST')
return bin2hex($digest);
}

private function getItems()
private function convertAmountItems()
{
/**
* example data
Expand All @@ -175,7 +179,16 @@ private function getItems()
*
*/

return $this->invoice->getDetails()['items'];
$new_items = array_map(
function ($item) {
$item['amount'] *= 10; // convert toman to rial
return $item;
},
$this->invoice->getDetails()['items'] ?? []
);

$this->invoice->detail('items', $new_items);
return $new_items;
}

/**
Expand Down

0 comments on commit efe50c0

Please sign in to comment.