Skip to content

Commit 2e1edf0

Browse files
iulian03Iulian Masar
andauthored
[release] 3.45.0 (#733)
* [improvement] updated type casting to work with arrays (#732) * updated type casting to work with arrays * updated parsing logic --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * updated PendingUserAction docs (#730) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * handle creation of bank wire direct payin for repudiation wallet (#731) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com>
1 parent b34a0c6 commit 2e1edf0

File tree

11 files changed

+94
-13
lines changed

11 files changed

+94
-13
lines changed

MangoPay/ApiClients.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,15 @@ public function CreatePayOut($payOut, $idempotencyKey = null)
183183
{
184184
return $this->CreateObject('client_create_payout', $payOut, '\MangoPay\PayOut', null, null, $idempotencyKey);
185185
}
186+
187+
/**
188+
* This endpoint allows the platform to make a Direct Bank Wire PayIn, instead of a Settlement Transfer
189+
* to their Repudiation Wallet in order to settle the negative balance due to a LOST dispute.
190+
* @param \MangoPay\PayIn $payIn \MangoPay\PayIn object
191+
* @return \MangoPay\PayIn Object returned from API
192+
*/
193+
public function CreateBankWireDirectPayIn($payIn, $idempotencyKey = null)
194+
{
195+
return $this->CreateObject('client_create_bank_wire_direct_payin', $payIn, '\MangoPay\PayIn', null, null, $idempotencyKey);
196+
}
186197
}

MangoPay/Libraries/ApiBase.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ protected function getLogger()
232232
'client_wallets_transactions_credit_currency' => ['/clients/wallets/credit/%s/transactions', RequestType::GET],
233233
'client_create_bank_account_iban' => ['/clients/bankaccounts/iban', RequestType::POST],
234234
'client_create_payout' => ['/clients/payouts', RequestType::POST],
235+
'client_create_bank_wire_direct_payin' => ['/clients/payins/bankwire/direct', RequestType::POST],
235236

236237
'banking_aliases_iban_create' => ['/wallets/%s/bankingaliases/iban', RequestType::POST],
237238
'banking_aliases_get' => ['/bankingaliases/%s', RequestType::GET],
@@ -703,12 +704,40 @@ protected function CastResponseToEntity($response, $entityClassName, $asDependen
703704

704705
// is sub object?
705706
if (isset($subObjects[$name])) {
706-
if (is_null($value)) {
707-
$object = null;
708-
} else {
709-
$object = $this->CastResponseToEntity($value, $subObjects[$name]);
707+
$object = null;
708+
if (!is_null($value)) {
709+
if (is_array($subObjects[$name])) {
710+
$type = $subObjects[$name][0];
711+
$class = $subObjects[$name][1];
712+
713+
if ($value instanceof \stdClass) {
714+
$value = (array)$value;
715+
}
716+
717+
// handle single array
718+
if ($type === 'array_single') {
719+
$object = [];
720+
foreach ($value as $k => $subValue) {
721+
$object[$k] = $this->CastResponseToEntity($subValue, $class);
722+
}
723+
} elseif ($type === 'array_nested') {
724+
// handle nested array
725+
$object = [];
726+
foreach ($value as $k => $subValue) {
727+
if ($subValue instanceof \stdClass) {
728+
$subValue = (array)$subValue;
729+
}
730+
$nestedArray = [];
731+
foreach ($subValue as $nk => $nestedObj) {
732+
$nestedArray[$nk] = $this->CastResponseToEntity($nestedObj, $class);
733+
}
734+
$object[$k] = $nestedArray;
735+
}
736+
}
737+
} else {
738+
$object = $this->CastResponseToEntity($value, $subObjects[$name]);
739+
}
710740
}
711-
712741
$entityProperty->setValue($entity, $object);
713742
} else {
714743
$entityProperty->setValue($entity, $value);
@@ -855,7 +884,7 @@ protected function GetObjectForIdempotencyUrl($url)
855884

856885
foreach ($map as $key => $className) {
857886
$sourceUrl = $this->GetRequestUrl($key);
858-
$sourceUrl = str_replace("%s", "[0-9a-zA-Z_]*", $sourceUrl);
887+
$sourceUrl = str_replace("%s", "[0-9a-zA-Z_-]*", $sourceUrl);
859888
$sourceUrl = str_replace("/", "\/", $sourceUrl);
860889
$pattern = '/' . $sourceUrl . '/';
861890
if (preg_match($pattern, $url) > 0) {

MangoPay/Recipient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Recipient extends Libraries\EntityBase
8989

9090
/**
9191
* Information about the action required from the user
92-
* @var PendingUserAction
92+
* @var PendingUserAction|null
9393
*/
9494
public $PendingUserAction;
9595

MangoPay/RecipientSchema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ public function GetSubObjects()
6565

6666
$subObjects['DisplayName'] = '\MangoPay\RecipientPropertySchema';
6767
$subObjects['Currency'] = '\MangoPay\RecipientPropertySchema';
68+
$subObjects['Country'] = '\MangoPay\RecipientPropertySchema';
6869
$subObjects['RecipientType'] = '\MangoPay\RecipientPropertySchema';
6970
$subObjects['PayoutMethodType'] = '\MangoPay\RecipientPropertySchema';
7071
$subObjects['RecipientScope'] = '\MangoPay\RecipientPropertySchema';
7172
$subObjects['Tag'] = '\MangoPay\RecipientPropertySchema';
7273
$subObjects['IndividualRecipient'] = '\MangoPay\IndividualRecipientPropertySchema';
7374
$subObjects['BusinessRecipient'] = '\MangoPay\BusinessRecipientPropertySchema';
75+
$subObjects['LocalBankTransfer'] = ['array_nested', '\MangoPay\RecipientPropertySchema'];
76+
$subObjects['InternationalBankTransfer'] = ['array_single', '\MangoPay\RecipientPropertySchema'];
7477

7578
return $subObjects;
7679
}

MangoPay/Transfer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Transfer extends Transaction
2525
public $ScaContext;
2626

2727
/**
28-
* @var PendingUserAction
28+
* @var PendingUserAction|null
2929
*/
3030
public $PendingUserAction;
3131

MangoPay/UserEnrollmentResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UserEnrollmentResult extends Dto
88
{
99
/**
1010
* Information about the action required from the user if UserStatus is PENDING_USER_ACTION (otherwise returned null).
11-
* @var PendingUserAction
11+
* @var PendingUserAction|null
1212
*/
1313
public $PendingUserAction;
1414

MangoPay/UserLegalSca.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class UserLegalSca extends User
5757

5858
/**
5959
* Information about the action required from the user if UserStatus is PENDING_USER_ACTION (otherwise returned null).
60-
* @var PendingUserAction
60+
* @var PendingUserAction|null
6161
*/
6262
public $PendingUserAction;
6363

MangoPay/UserNaturalSca.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class UserNaturalSca extends User
9999

100100
/**
101101
* Information about the action required from the user if UserStatus is PENDING_USER_ACTION (otherwise returned null).
102-
* @var PendingUserAction
102+
* @var PendingUserAction|null
103103
*/
104104
public $PendingUserAction;
105105

tests/Cases/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ protected function getNewPayInIntentAuthorization()
22562256

22572257
$externalData = new PayInIntentExternalData();
22582258
$externalData->ExternalProcessingDate = 1728133765;
2259-
$externalData->ExternalProviderReference = strval(rand(0, 10000));
2259+
$externalData->ExternalProviderReference = strval(round(microtime(true) * 1000));
22602260
$externalData->ExternalMerchantReference = "Order-xyz-35e8490e-2ec9-4c82-978e-c712a3f5ba16";
22612261
$externalData->ExternalProviderName = "Stripe";
22622262
$externalData->ExternalProviderPaymentMethod = "PAYPAL";

tests/Cases/ClientTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
use MangoPay\BusinessType;
66
use MangoPay\Money;
7+
use MangoPay\PayIn;
8+
use MangoPay\PayInExecutionDetailsDirect;
9+
use MangoPay\PayInPaymentDetailsBankWire;
10+
use MangoPay\PayInStatus;
711
use MangoPay\PayOut;
812
use MangoPay\PayOutPaymentDetailsBankWire;
913
use MangoPay\Sector;
@@ -279,4 +283,26 @@ public function test_CreatePayOut()
279283
$this->assertNotNull($createdPayOut);
280284
$this->assertNotNull($createdPayOut->Id);
281285
}
286+
287+
public function test_CreateBankWireDirectPayIn()
288+
{
289+
$payIn = new PayIn();
290+
$payIn->CreditedWalletId = "CREDIT_EUR";
291+
$payIn->PaymentDetails = new PayInPaymentDetailsBankWire();
292+
$payIn->PaymentDetails->DeclaredDebitedFunds = new Money();
293+
$payIn->PaymentDetails->DeclaredDebitedFunds->Amount = 100;
294+
$payIn->PaymentDetails->DeclaredDebitedFunds->Currency = 'EUR';
295+
$payIn->ExecutionDetails = new PayInExecutionDetailsDirect();
296+
297+
$createPayIn = $this->_api->Clients->CreateBankWireDirectPayIn($payIn);
298+
299+
$this->assertNotNull($createPayIn->Id);
300+
$this->assertEquals(\MangoPay\PayInPaymentType::BankWire, $createPayIn->PaymentType);
301+
$this->assertInstanceOf('\MangoPay\PayInPaymentDetailsBankWire', $createPayIn->PaymentDetails);
302+
$this->assertInstanceOf('\MangoPay\Money', $createPayIn->PaymentDetails->DeclaredDebitedFunds);
303+
$this->assertEquals(\MangoPay\PayInExecutionType::Direct, $createPayIn->ExecutionType);
304+
$this->assertInstanceOf('\MangoPay\PayInExecutionDetailsDirect', $createPayIn->ExecutionDetails);
305+
$this->assertEquals(PayInStatus::Created, $createPayIn->Status);
306+
$this->assertEquals('PAYIN', $createPayIn->Type);
307+
}
282308
}

0 commit comments

Comments
 (0)