Skip to content

Commit

Permalink
added cumulative to Asanpardakht & Mellat
Browse files Browse the repository at this point in the history
  • Loading branch information
samuraee committed Dec 30, 2023
1 parent 2b81b46 commit 2bc2885
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions config/shaparak.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
'prefix' => 'SHAPARAK->',
],

'iban' => env('SETTLEMENT_IBAN'),

'providers' => [
/*
|--------------------------------------------------------------------------
Expand All @@ -34,6 +36,7 @@
'terminal_id' => env('AP_MERCHANT_ID'),
'key' => env('AP_KEY'),
'iv' => env('AP_IV'),
'cumulative' => env('AP_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -43,6 +46,7 @@
'saman' => [
'terminal_id' => env('SAMAN_TERMINAL_ID'),
'terminal_pass' => env('SAMAN_TERMINAL_PASS'),
'cumulative' => env('SAMAN_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -51,6 +55,7 @@
*/
'parsian' => [
'pin' => env('PARSIAN_PIN', ''),
'cumulative' => env('PARSIAN_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -61,6 +66,7 @@
'terminal_id' => env('PASARGAD_TERMINAL_ID'),
'merchant_id' => env('PASARGAD_MERCHANT_ID'),
'certificate_path' => env('PASARGAD_CERT_PATH', storage_path('shaparak/pasargad/certificate.xml')),
'cumulative' => env('PASARGAD_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -71,6 +77,7 @@
'username' => env('MELLAT_USERNAME'),
'password' => env('MELLAT_PASSWORD'),
'terminal_id' => env('MELLAT_TERMINAL_ID'),
'cumulative' => env('MELLAT_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -81,6 +88,7 @@
'merchant_id' => env('MELLI_MERCHANT_ID'),
'terminal_id' => env('MELLI_TERMINAL_ID'),
'transaction_key' => env('MELLI_TRANS_KEY'),
'cumulative' => env('MELLI_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -89,6 +97,7 @@
*/
'saderat' => [
'terminal_id' => env('SADERAT_MERCHANT_ID'),
'cumulative' => env('SADERAT_CUMULATIVE', false),
],
/*
|--------------------------------------------------------------------------
Expand All @@ -97,6 +106,7 @@
*/
'zarinpal' => [
'merchant_id' => env('ZARINPAL_MERCHANT_ID'),
'cumulative' => env('ZARINPAL_CUMULATIVE', false),
],
],

Expand Down
16 changes: 14 additions & 2 deletions src/Provider/AsanPardakhtProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,18 @@ public function requestTokenData(): array
'local_time',
]);

return [
$data = [
'serviceTypeId' => 1,
'merchantConfigurationId' => $this->getParameters('terminal_id'),
'localInvoiceId' => $this->getGatewayOrderId(), // get it from Transaction
'amountInRials' => $this->getAmount(),
'localDate' => $this->getParameters('local_date').' '.$this->getParameters('local_time'),
'callbackURL' => $this->getCallbackUrl(),
'paymentId' => 0,
'paymentId' => $this->getParameters('payment_id', 0),
'additionalData' => (string) $this->getParameters('additional_data', ''),
];

return array_merge($data, $this->cumulativeData());
}

public function sendParamToAp(array $params, string $url, string $method): mixed
Expand Down Expand Up @@ -392,4 +394,14 @@ protected function generateComplementaryOperation($method): bool

return false;
}

private function cumulativeData(): array
{
if ($this->getParameters('cumulative')) {
return [
'settlementPortions' => $this->getParameters('settlement_portions')
];
}
return [];
}
}
7 changes: 6 additions & 1 deletion src/Provider/MellatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ protected function requestToken(): string
'additionalData' => (string) $this->getParameters('additional_data'),
'callBackUrl' => $this->getCallbackUrl(),
'payerId' => (int) $this->getParameters('payer_id'),
'user_mobile' => '98' . substr($this->getParameters('user_mobile'), -10)
];

try {
$soapClient = $this->getSoapClient(self::URL_TOKEN);

$response = $soapClient->bpPayRequest($sendParams);
if ($this->getParameters('cumulative')) {
$response = $soapClient->bpCumulativeDynamicPayRequest($sendParams);
} else {
$response = $soapClient->bpPayRequest($sendParams);
}

if (isset($response->return)) {
$response = explode(',', $response->return);
Expand Down

0 comments on commit 2bc2885

Please sign in to comment.