Skip to content

Commit 1c6f2f6

Browse files
author
Iulian Masar
committed
handle deposit preauthorized payins
1 parent da96760 commit 1c6f2f6

File tree

7 files changed

+192
-53
lines changed

7 files changed

+192
-53
lines changed

MangoPay/ApiDeposits.php

Lines changed: 12 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
/**

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: 3 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,7 +245,7 @@ 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],
249251

MangoPay/PayInPaymentDetailsPreAuthorized.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ class PayInPaymentDetailsPreAuthorized extends Libraries\Dto implements PayInPay
1212
* @var string
1313
*/
1414
public $PreauthorizationId;
15+
16+
/**
17+
* The unique identifier of the deposit preauthorization. Used for Deposit Preauthorized PayIn.
18+
* @var string
19+
*/
20+
public $DepositId;
1521
}

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: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace MangoPay\Tests\Cases;
44

5+
use MangoPay\CancelDeposit;
6+
57
/**
68
* Tests basic methods for disputes
79
*/
@@ -85,23 +87,22 @@ public function test_Deposits_GetAllForCard()
8587
self::assertTrue(sizeof($fetched) > 0);
8688
}
8789

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-
// }
90+
/**
91+
* @throws \Exception
92+
*/
93+
public function test_Deposits_Cancel()
94+
{
95+
$user = $this->getJohn();
96+
$cardRegistration = $this->getUpdatedCardRegistration($user->Id);
97+
$deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id));
98+
99+
$dto = new CancelDeposit();
100+
$dto->PaymentStatus = "CANCELED";
101+
102+
$this->_api->Deposits->Cancel($deposit->Id, $dto);
103+
104+
$fetchedDeposit = $this->_api->Deposits->Get($deposit->Id);
105+
106+
$this->assertEquals("CANCELED", $fetchedDeposit->PaymentStatus);
107+
}
107108
}

tests/Cases/PayInsTest.php

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

11451213
public function test_PayIns_Create_PayByBank_Web()
11461214
{

0 commit comments

Comments
 (0)