Skip to content

Commit fd973ef

Browse files
committed
added fixed sharing functionality
1 parent d8a1351 commit fd973ef

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

src/Adapter/Parsian.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
declare(strict_types=1);
3+
declare(strict_types = 1);
44

55
namespace Tartan\Larapay\Adapter;
66

7+
use a\Sharing;
78
use SoapFault;
89
use Tartan\Larapay\Adapter\Parsian\Exception;
910
use Tartan\Log\Facades\XLog;
@@ -14,19 +15,19 @@
1415
*/
1516
class Parsian extends AdapterAbstract implements AdapterInterface
1617
{
17-
protected $WSDLSale = 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?WSDL';
18-
protected $WSDLConfirm = 'https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL';
19-
protected $WSDLReversal = 'https://pec.shaparak.ir/NewIPGServices/Reverse/ReversalService.asmx';
18+
protected $WSDLSale = 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?WSDL';
19+
protected $WSDLConfirm = 'https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL';
20+
protected $WSDLReversal = 'https://pec.shaparak.ir/NewIPGServices/Reverse/ReversalService.asmx';
2021
protected $WSDLMultiplex = 'https://pec.shaparak.ir/NewIPGServices/MultiplexedSale/OnlineMultiplexedSalePaymentService.asmx?wsdl';
2122

22-
protected $endPoint = 'https://pec.shaparak.ir/NewIPG/';
23+
protected $endPoint = 'https://pec.shaparak.ir/NewIPG/';
2324

24-
protected $testWSDLSale = 'http://banktest.ir/gateway/parsian-sale/ws?wsdl';
25-
protected $testWSDLConfirm = 'http://banktest.ir/gateway/parsian-confirm/ws?wsdl';
26-
protected $testWSDLReversal = 'http://banktest.ir/gateway/parsian-reverse/ws?wsdl';
25+
protected $testWSDLSale = 'http://banktest.ir/gateway/parsian-sale/ws?wsdl';
26+
protected $testWSDLConfirm = 'http://banktest.ir/gateway/parsian-confirm/ws?wsdl';
27+
protected $testWSDLReversal = 'http://banktest.ir/gateway/parsian-reverse/ws?wsdl';
2728
protected $testWSDLMultiplex = 'http://banktest.ir/parsian/NewIPGServices/MultiplexedSale/OnlineMultiplexedSalePaymentService.asmx?wsdl';
2829

29-
protected $testEndPoint = 'http://banktest.ir/gateway/parsian/gate';
30+
protected $testEndPoint = 'http://banktest.ir/gateway/parsian/gate';
3031

3132
protected $reverseSupport = true;
3233

@@ -123,20 +124,25 @@ private function requestTokenWithoutSharing($sendParams)
123124
*/
124125
private function requestTokenWithSharing($sendParams)
125126
{
126-
foreach ($this->sharing as $item) {
127-
if (isset($item->IBAN)) {
128-
// dynamic sharing
129-
$method = 'MultiplexedSaleWithIBANPaymentRequest';
130-
$respo = 'MultiplexedSaleWithIBANPaymentResult';
127+
if (!isset($this->sharing['type']) || !isset($this->sharing['data'])) {
128+
throw new Exception('larapay::larapay.invalid_sharing_data');
129+
}
130+
if ($this->sharing['type'] == Sharing::DYNAMIC) {
131+
// dynamic sharing
132+
$method = 'MultiplexedSaleWithIBANPaymentRequest';
133+
$respo = 'MultiplexedSaleWithIBANPaymentResult';
134+
foreach ($this->sharing['data'] as $item) {
131135
$sendParams['MultiplexedAccounts']['Account'][] = [
132136
'Amount' => $item->share,
133137
'PayId' => $item->pay_id ?? '',
134-
'IBAN' => $item->iban
138+
'IBAN' => $item->iban,
135139
];
136-
} else {
137-
// fix sharing
138-
$method = 'MultiplexedSalePaymentRequest';
139-
$respo = 'MultiplexedSalePaymentResult';
140+
}
141+
} else {
142+
// fix sharing
143+
$method = 'MultiplexedSalePaymentRequest';
144+
$respo = 'MultiplexedSalePaymentResult';
145+
foreach ($this->sharing['data'] as $item) {
140146
$sendParams['MultiplexedAccounts']['Account'][] = [
141147
'Amount' => $item->share,
142148
'PayId' => $item->pay_id ?? '',
@@ -169,6 +175,7 @@ private function requestTokenWithSharing($sendParams)
169175
throw new Exception('SoapFault: ' . $e->getMessage() . ' #' . $e->getCode(), $e->getCode());
170176
}
171177
}
178+
172179
/**
173180
* @return mixed
174181
* @throws Exception
@@ -195,9 +202,9 @@ public function formParams(): array
195202
{
196203
$authority = $this->requestToken();
197204

198-
return [
199-
'endPoint' => $this->getEndPoint(),
200-
'refId' => $authority,
205+
return [
206+
'endPoint' => $this->getEndPoint(),
207+
'refId' => $authority,
201208
];
202209
}
203210

src/Models/Enum/Sharing.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
4+
namespace a;
5+
6+
7+
class Sharing
8+
{
9+
const DYNAMIC = 'DYNAMIC';
10+
const FIXEd = 'FIXED';
11+
}

translations/en/larapay.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
'reversed_failed' => 'بازگشت تراکنش با موفقیت انجام نشد!',
1717
'verification_failed' => 'تایید تراکنش با موفقیت انجام نشد!',
1818
'after_verification_failed' => 'تایید بعد از تراکنش با موفقیت انجام نشد!',
19+
'invalid_sharing_data' => 'اطلاعات تسهیم معتبر نیست',
20+
'transaction_not_found' => 'تراکنش پیدا نشد',
1921

2022
'mellat' => [
2123
'errors' => [
@@ -132,4 +134,4 @@
132134
'error__54 '=> 'درخواست مورد نظر آرشیو شده است',
133135
]
134136
]
135-
];
137+
];

translations/fa/larapay.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
'reversed_failed' => 'بازگشت تراکنش با موفقیت انجام نشد!',
1717
'verification_failed' => 'تایید تراکنش با موفقیت انجام نشد!',
1818
'after_verification_failed' => 'تایید بعد از تراکنش با موفقیت انجام نشد!',
19+
'invalid_sharing_data' => 'اطلاعات تسهیم معتبر نیست',
20+
'transaction_not_found' => 'تراکنش پیدا نشد',
1921

2022
'mellat' => [
2123
'errors' => [
@@ -132,4 +134,4 @@
132134
'error__54 '=> 'درخواست مورد نظر آرشیو شده است',
133135
]
134136
]
135-
];
137+
];

0 commit comments

Comments
 (0)