Skip to content

Commit

Permalink
Fix Melat Payment (#62)
Browse files Browse the repository at this point in the history
* Debug Melat Paymen And True Payment
  • Loading branch information
alimousavi71 committed May 5, 2020
1 parent 210fee8 commit c77fd39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion config/payment.php
Expand Up @@ -35,10 +35,12 @@
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],

'behpardakht' => [
'apiPurchaseUrl' => 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl',
'apiPaymentUrl' => 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat',
'apiVerificationUrl' => 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl',
'apiNamespaceUrl' => 'http://interfaces.core.sw.bps.com/',
'terminalId' => '',
'username' => '',
'password' => '',
Expand Down Expand Up @@ -84,7 +86,7 @@
'apiPurchaseUrl' => 'https://pay.ir/pg/send/',
'apiPaymentUrl' => 'https://pay.ir/pg/',
'apiVerificationUrl' => 'https://pay.ir/pg/verify/',
'merchantId' => '', // set it to `test` for test environments
'merchantId' => 'test', // set it to `test` for test environments
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
Expand Down
10 changes: 6 additions & 4 deletions src/Drivers/Behpardakht/Behpardakht.php
Expand Up @@ -46,8 +46,9 @@ public function __construct(Invoice $invoice, $settings)
* @throws PurchaseFailedException
* @throws \SoapFault
*/

public function purchase()
{
{
$soap = new \SoapClient($this->settings->apiPurchaseUrl);
$response = $soap->bpPayRequest($this->preparePurchaseData());

Expand All @@ -56,7 +57,8 @@ public function purchase()
throw new PurchaseFailedException('پذیرنده معتبر نیست.');
}

$data = explode(',', $response);

$data = explode(',', $response->return);

// purchase was not successful
if ($data[0] != "0") {
Expand Down Expand Up @@ -107,15 +109,15 @@ public function verify() : ReceiptInterface
$soap = new \SoapClient($this->settings->apiVerificationUrl);

// step1: verify request
$verifyResponse = $soap->bpVerifyRequest($data, $this->settings->apiNamespaceUrl);
$verifyResponse = (int)$soap->bpVerifyRequest($data, $this->settings->apiNamespaceUrl)->return;
if ($verifyResponse != 0) {
// rollback money and throw exception
$soap->bpReversalRequest($data, $this->settings->apiNamespaceUrl);
throw new InvalidPaymentException($verifyResponse ?? "خطا در عملیات وریفای تراکنش");
}

// step2: settle request
$settleResponse = $soap->bpSettleRequest($data, $this->settings->apiNamespaceUrl);
$settleResponse = $soap->bpSettleRequest($data, $this->settings->apiNamespaceUrl)->return;
if ($settleResponse != 0) {
// rollback money and throw exception
$soap->bpReversalRequest($data, $this->settings->apiNamespaceUrl);
Expand Down

0 comments on commit c77fd39

Please sign in to comment.