Skip to content

Commit d7d4dfc

Browse files
iulian03Iulian Masar
andauthored
[feature] handle deposit preauthorized payins (#701)
* handle deposit preauthorized payins * run lint * handle fetching of deposit transactions * moved DepositId from PayInPaymentDetailsPreAuthorized to Transaction --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com>
1 parent b58be54 commit d7d4dfc

File tree

7 files changed

+246
-53
lines changed

7 files changed

+246
-53
lines changed

MangoPay/ApiDeposits.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ public function Get($depositId)
3535
*/
3636
public function Cancel($depositId, CancelDeposit $dto)
3737
{
38-
return $this->SaveObject('deposits_cancel', $dto, '\MangoPay\Deposit', $depositId);
38+
return $this->SaveObject('deposits_update', $dto, '\MangoPay\Deposit', $depositId);
39+
}
40+
41+
/**
42+
* Update Deposit
43+
* @param string $depositId Deposit identifier
44+
* @param UpdateDeposit $dto Update deposit body
45+
* @return Deposit Deposit object returned from API
46+
*/
47+
public function Update($depositId, UpdateDeposit $dto)
48+
{
49+
return $this->SaveObject('deposits_update', $dto, '\MangoPay\Deposit', $depositId);
3950
}
4051

4152
/**
@@ -63,4 +74,17 @@ public function GetAllForCard($cardId, $pagination = null, $filter = null, $sort
6374
{
6475
return $this->GetList('deposits_get_all_for_card', $pagination, '\MangoPay\Deposit', $cardId, $filter, $sorting);
6576
}
77+
78+
/**
79+
* Get all transactions for a deposit
80+
* @param string $depositId Deposit identifier
81+
* @param Pagination $pagination Pagination object
82+
* @param FilterTransactions $filter Filtering object
83+
* @param Sorting $sorting Sorting object
84+
* @return Transaction[] Transaction list returned from API
85+
*/
86+
public function GetTransactions($depositId, $pagination = null, $filter = null, $sorting = null)
87+
{
88+
return $this->GetList('deposits_get_transactions', $pagination, '\MangoPay\Transaction', $depositId, $filter, $sorting);
89+
}
6690
}

MangoPay/ApiPayIns.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,36 @@ public function CreateCardPreAuthorizedDepositPayIn(CreateCardPreAuthorizedDepos
164164
return $this->CreateObject('payins_create_card_pre_authorized_deposit', $payIn, '\MangoPay\PayIn');
165165
}
166166

167+
/**
168+
* Create a Deposit Preauthorized PayIn without complement
169+
* @param CreateCardPreAuthorizedDepositPayIn $payIn PayIn object to create
170+
* @return PayIn Deposit object returned from API
171+
*/
172+
public function CreateDepositPreauthorizedPayInWithoutComplement(CreateCardPreAuthorizedDepositPayIn $payIn)
173+
{
174+
return $this->CreateObject('payins_create_card_pre_authorized_deposit', $payIn, '\MangoPay\PayIn');
175+
}
176+
177+
/**
178+
* Create a Deposit Preauthorized PayIn prior to complement
179+
* @param CreateCardPreAuthorizedDepositPayIn $payIn PayIn object to create
180+
* @return PayIn Deposit object returned from API
181+
*/
182+
public function CreateDepositPreauthorizedPayInPriorToComplement(CreateCardPreAuthorizedDepositPayIn $payIn)
183+
{
184+
return $this->CreateObject('payins_deposit_preauthorized_prior_to_complement', $payIn, '\MangoPay\PayIn');
185+
}
186+
187+
/**
188+
* Create a Deposit Preauthorized PayIn complement
189+
* @param CreateCardPreAuthorizedDepositPayIn $payIn PayIn object to create
190+
* @return PayIn Deposit object returned from API
191+
*/
192+
public function CreateDepositPreauthorizedPayInComplement(CreateCardPreAuthorizedDepositPayIn $payIn)
193+
{
194+
return $this->CreateObject('payins_deposit_preauthorized_complement', $payIn, '\MangoPay\PayIn');
195+
}
196+
167197
/**
168198
* Create new PayPal Web pay-in object
169199
* @param \MangoPay\PayIn $payIn \MangoPay\PayIn object

MangoPay/Libraries/ApiBase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ protected function getLogger()
9393
'payins_recurring_card_direct' => ['/payins/recurring/card/direct', RequestType::POST],
9494
'payins_recurring_paypal' => ['/payins/payment-methods/paypal/recurring', RequestType::POST],
9595
'payins_create_card_pre_authorized_deposit' => ['/payins/deposit-preauthorized/direct/full-capture', RequestType::POST],
96+
'payins_deposit_preauthorized_prior_to_complement' => ['/payins/deposit-preauthorized/direct/capture-with-complement', RequestType::POST],
97+
'payins_deposit_preauthorized_complement' => ['/payins/deposit-preauthorized/direct/complement', RequestType::POST],
9698

9799
'repudiation_get' => ['/repudiations/%s', RequestType::GET],
98100

@@ -243,9 +245,10 @@ protected function getLogger()
243245

244246
'deposits_create' => ['/deposit-preauthorizations/card/direct', RequestType::POST],
245247
'deposits_get' => ['/deposit-preauthorizations/%s', RequestType::GET],
246-
'deposits_cancel' => ['/deposit-preauthorizations/%s', RequestType::PUT],
248+
'deposits_update' => ['/deposit-preauthorizations/%s', RequestType::PUT],
247249
'deposits_get_all_for_user' => ['/users/%s/deposit-preauthorizations', RequestType::GET],
248250
'deposits_get_all_for_card' => ['/cards/%s/deposit-preauthorizations', RequestType::GET],
251+
'deposits_get_transactions' => ['/deposit-preauthorizations/%s/transactions', RequestType::GET],
249252

250253
'get_conversion_rate' => ['/conversions/rate/%s/%s', RequestType::GET],
251254
'create_client_wallets_instant_conversion' => ['/clients/conversions/instant-conversion', RequestType::POST],

MangoPay/Transaction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class Transaction extends Libraries\EntityBase
8686
*/
8787
public $CreditedWalletId;
8888

89+
/**
90+
* Deposit Id
91+
* @var string
92+
*/
93+
public $DepositId;
94+
8995
/**
9096
* Get array with mapping which property is object and what type of object
9197
* @return array

MangoPay/UpdateDeposit.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace MangoPay;
4+
5+
class UpdateDeposit extends Libraries\Dto
6+
{
7+
/**
8+
* @var string
9+
* @see CardPreAuthorizationPaymentStatus
10+
*/
11+
public $PaymentStatus;
12+
13+
/**
14+
* Get array with mapping which property is object and what type of object
15+
* @return array
16+
*/
17+
public function GetSubObjects()
18+
{
19+
return parent::GetSubObjects();
20+
}
21+
}

tests/Cases/DepositTest.php

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace MangoPay\Tests\Cases;
44

5+
use MangoPay\CancelDeposit;
6+
use MangoPay\CreateCardPreAuthorizedDepositPayIn;
7+
use MangoPay\Money;
8+
59
/**
610
* Tests basic methods for disputes
711
*/
@@ -85,23 +89,57 @@ public function test_Deposits_GetAllForCard()
8589
self::assertTrue(sizeof($fetched) > 0);
8690
}
8791

88-
// /**
89-
// * @throws \Exception
90-
// */
91-
// public function test_Deposits_Cancel()
92-
// {
93-
// $cardRegistration = $this->getCardRegistrationForDeposit();
94-
// $user = $this->getJohn();
95-
//
96-
// $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
97-
//
98-
// $dto = new CancelDeposit();
99-
// $dto->PaymentStatus = "CANCELED";
100-
//
101-
// $this->_api->Deposits->Cancel($deposit->Id, $dto);
102-
//
103-
// $fetchedDeposit = $this->_api->Deposits->Get($deposit->Id);
104-
//
105-
// $this->assertEquals("CANCELED", $fetchedDeposit->PaymentStatus);
106-
// }
92+
/**
93+
* @throws \Exception
94+
*/
95+
public function test_Deposits_Cancel()
96+
{
97+
$user = $this->getJohn();
98+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
99+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
100+
101+
$dto = new CancelDeposit();
102+
$dto->PaymentStatus = "CANCELED";
103+
104+
$this->_api->Deposits->Cancel($deposit->Id, $dto);
105+
106+
$fetchedDeposit = $this->_api->Deposits->Get($deposit->Id);
107+
108+
$this->assertEquals("CANCELED", $fetchedDeposit->PaymentStatus);
109+
}
110+
111+
/**
112+
* @throws \Exception
113+
*/
114+
public function test_Deposits_GetTransactions()
115+
{
116+
$user = $this->getJohn();
117+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
118+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
119+
$wallet = $this->getJohnsWallet();
120+
121+
$dto = new CreateCardPreAuthorizedDepositPayIn();
122+
$dto->DepositId = $deposit->Id;
123+
$dto->AuthorId = $user->Id;
124+
$dto->CreditedWalletId = $wallet->Id;
125+
126+
$debitedFunds = new Money();
127+
$debitedFunds->Amount = 1000;
128+
$debitedFunds->Currency = "EUR";
129+
130+
$fees = new Money();
131+
$fees->Amount = 0;
132+
$fees->Currency = "EUR";
133+
134+
$dto->DebitedFunds = $debitedFunds;
135+
$dto->Fees = $fees;
136+
137+
$this->_api->PayIns->CreateDepositPreauthorizedPayInWithoutComplement($dto);
138+
sleep(1);
139+
$transactions = $this->_api->Deposits->GetTransactions($deposit->Id);
140+
141+
self::assertNotNull($transactions);
142+
self::assertTrue(is_array($transactions));
143+
self::assertTrue(sizeof($transactions) > 0);
144+
}
107145
}

tests/Cases/PayInsTest.php

Lines changed: 103 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MangoPay\Tests\Cases;
44

5+
use MangoPay\CreateCardPreAuthorizedDepositPayIn;
56
use MangoPay\Libraries\Exception;
67
use MangoPay\LineItem;
78
use MangoPay\Money;
@@ -14,6 +15,7 @@
1415
use MangoPay\RecurringPayPalPayInCIT;
1516
use MangoPay\RecurringPayPalPayInMIT;
1617
use MangoPay\TransactionStatus;
18+
use MangoPay\UpdateDeposit;
1719

1820
/**
1921
* Tests methods for pay-ins
@@ -1109,38 +1111,107 @@ public function test_CardDirect_getPaymentMethodMetadata()
11091111
$this->assertNotNull($result_metadata->BinData[0]->CardType);
11101112
}
11111113

1112-
// /**
1113-
// * @throws \Exception
1114-
// */
1115-
// public function test_CreateCardPreAuthorizedDepositPayIn() {
1116-
// $cardRegistration = $this->getCardRegistrationForDeposit();
1117-
// $user = $this->getJohn();
1118-
// $wallet = $this->getJohnsWallet();
1119-
//
1120-
// $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
1121-
//
1122-
// $dto = new CreateCardPreAuthorizedDepositPayIn();
1123-
// $dto->DepositId = $deposit->Id;
1124-
// $dto->AuthorId = $user->Id;
1125-
// $dto->CreditedWalletId = $wallet->Id;
1126-
//
1127-
// $debitedFunds = new Money();
1128-
// $debitedFunds->Amount = 500;
1129-
// $debitedFunds->Currency = "EUR";
1130-
//
1131-
// $fees = new Money();
1132-
// $fees->Amount = 0;
1133-
// $fees->Currency = "EUR";
1134-
//
1135-
// $dto->DebitedFunds = $debitedFunds;
1136-
// $dto->Fees = $fees;
1137-
//
1138-
// $payIn = $this->_api->PayIns->CreateCardPreAuthorizedDepositPayIn($dto);
1139-
// print_r($payIn);
1140-
//
1141-
// $this->assertNotNull($payIn);
1142-
// $this->assertEquals("SUCCEEDED", $payIn->Status);
1143-
// }
1114+
/**
1115+
* @throws \Exception
1116+
*/
1117+
public function test_createDepositPreauthorizedPayInWithoutComplement()
1118+
{
1119+
$user = $this->getJohn();
1120+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
1121+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
1122+
$wallet = $this->getJohnsWallet();
1123+
1124+
$dto = new CreateCardPreAuthorizedDepositPayIn();
1125+
$dto->DepositId = $deposit->Id;
1126+
$dto->AuthorId = $user->Id;
1127+
$dto->CreditedWalletId = $wallet->Id;
1128+
1129+
$debitedFunds = new Money();
1130+
$debitedFunds->Amount = 1000;
1131+
$debitedFunds->Currency = "EUR";
1132+
1133+
$fees = new Money();
1134+
$fees->Amount = 0;
1135+
$fees->Currency = "EUR";
1136+
1137+
$dto->DebitedFunds = $debitedFunds;
1138+
$dto->Fees = $fees;
1139+
1140+
$payIn = $this->_api->PayIns->CreateDepositPreauthorizedPayInWithoutComplement($dto);
1141+
1142+
$this->assertNotNull($payIn);
1143+
$this->assertEquals("SUCCEEDED", $payIn->Status);
1144+
$this->assertNotNull($payIn->DepositId);
1145+
}
1146+
1147+
/**
1148+
* @throws \Exception
1149+
*/
1150+
public function test_createDepositPreauthorizedPayInPriorToComplement()
1151+
{
1152+
$user = $this->getJohn();
1153+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
1154+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
1155+
$wallet = $this->getJohnsWallet();
1156+
1157+
$dto = new CreateCardPreAuthorizedDepositPayIn();
1158+
$dto->DepositId = $deposit->Id;
1159+
$dto->AuthorId = $user->Id;
1160+
$dto->CreditedWalletId = $wallet->Id;
1161+
1162+
$debitedFunds = new Money();
1163+
$debitedFunds->Amount = 1000;
1164+
$debitedFunds->Currency = "EUR";
1165+
1166+
$fees = new Money();
1167+
$fees->Amount = 0;
1168+
$fees->Currency = "EUR";
1169+
1170+
$dto->DebitedFunds = $debitedFunds;
1171+
$dto->Fees = $fees;
1172+
1173+
$payIn = $this->_api->PayIns->CreateDepositPreauthorizedPayInPriorToComplement($dto);
1174+
1175+
$this->assertNotNull($payIn);
1176+
$this->assertEquals("SUCCEEDED", $payIn->Status);
1177+
$this->assertNotNull($payIn->DepositId);
1178+
}
1179+
1180+
/**
1181+
* @throws \Exception
1182+
*/
1183+
public function test_createDepositPreauthorizedPayInComplement()
1184+
{
1185+
$user = $this->getJohn();
1186+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
1187+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
1188+
$updateDepositDto = new UpdateDeposit();
1189+
$updateDepositDto->PaymentStatus = "NO_SHOW_REQUESTED";
1190+
$this->_api->Deposits->Update($deposit->Id, $updateDepositDto);
1191+
$wallet = $this->getJohnsWallet();
1192+
1193+
$dto = new CreateCardPreAuthorizedDepositPayIn();
1194+
$dto->DepositId = $deposit->Id;
1195+
$dto->AuthorId = $user->Id;
1196+
$dto->CreditedWalletId = $wallet->Id;
1197+
1198+
$debitedFunds = new Money();
1199+
$debitedFunds->Amount = 1000;
1200+
$debitedFunds->Currency = "EUR";
1201+
1202+
$fees = new Money();
1203+
$fees->Amount = 0;
1204+
$fees->Currency = "EUR";
1205+
1206+
$dto->DebitedFunds = $debitedFunds;
1207+
$dto->Fees = $fees;
1208+
1209+
$payIn = $this->_api->PayIns->CreateDepositPreauthorizedPayInComplement($dto);
1210+
1211+
$this->assertNotNull($payIn);
1212+
$this->assertEquals("SUCCEEDED", $payIn->Status);
1213+
$this->assertNotNull($payIn->DepositId);
1214+
}
11441215

11451216
public function test_PayIns_Create_PayByBank_Web()
11461217
{

0 commit comments

Comments
 (0)