From 2bc28854ba27e563863c93df18ac3b2d873e6326 Mon Sep 17 00:00:00 2001 From: Aboozar Ghaffari Date: Sat, 30 Dec 2023 17:12:24 +0330 Subject: [PATCH] added cumulative to Asanpardakht & Mellat --- config/shaparak.php | 10 ++++++++++ src/Provider/AsanPardakhtProvider.php | 16 ++++++++++++++-- src/Provider/MellatProvider.php | 7 ++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/config/shaparak.php b/config/shaparak.php index 6295a44..8b27868 100644 --- a/config/shaparak.php +++ b/config/shaparak.php @@ -22,6 +22,8 @@ 'prefix' => 'SHAPARAK->', ], + 'iban' => env('SETTLEMENT_IBAN'), + 'providers' => [ /* |-------------------------------------------------------------------------- @@ -34,6 +36,7 @@ 'terminal_id' => env('AP_MERCHANT_ID'), 'key' => env('AP_KEY'), 'iv' => env('AP_IV'), + 'cumulative' => env('AP_CUMULATIVE', false), ], /* |-------------------------------------------------------------------------- @@ -43,6 +46,7 @@ 'saman' => [ 'terminal_id' => env('SAMAN_TERMINAL_ID'), 'terminal_pass' => env('SAMAN_TERMINAL_PASS'), + 'cumulative' => env('SAMAN_CUMULATIVE', false), ], /* |-------------------------------------------------------------------------- @@ -51,6 +55,7 @@ */ 'parsian' => [ 'pin' => env('PARSIAN_PIN', ''), + 'cumulative' => env('PARSIAN_CUMULATIVE', false), ], /* |-------------------------------------------------------------------------- @@ -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), ], /* |-------------------------------------------------------------------------- @@ -71,6 +77,7 @@ 'username' => env('MELLAT_USERNAME'), 'password' => env('MELLAT_PASSWORD'), 'terminal_id' => env('MELLAT_TERMINAL_ID'), + 'cumulative' => env('MELLAT_CUMULATIVE', false), ], /* |-------------------------------------------------------------------------- @@ -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), ], /* |-------------------------------------------------------------------------- @@ -89,6 +97,7 @@ */ 'saderat' => [ 'terminal_id' => env('SADERAT_MERCHANT_ID'), + 'cumulative' => env('SADERAT_CUMULATIVE', false), ], /* |-------------------------------------------------------------------------- @@ -97,6 +106,7 @@ */ 'zarinpal' => [ 'merchant_id' => env('ZARINPAL_MERCHANT_ID'), + 'cumulative' => env('ZARINPAL_CUMULATIVE', false), ], ], diff --git a/src/Provider/AsanPardakhtProvider.php b/src/Provider/AsanPardakhtProvider.php index 6d9326d..b1fc601 100755 --- a/src/Provider/AsanPardakhtProvider.php +++ b/src/Provider/AsanPardakhtProvider.php @@ -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 @@ -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 []; + } } diff --git a/src/Provider/MellatProvider.php b/src/Provider/MellatProvider.php index 41cbe07..f22d103 100644 --- a/src/Provider/MellatProvider.php +++ b/src/Provider/MellatProvider.php @@ -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);