From 04ba4bb9e13c6bc073edd38f3a67351cded5ff1c Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 30 Jul 2024 16:17:24 +0300 Subject: [PATCH] implemented Bancontact PayIn method --- MangoPay/Libraries/ApiBase.php | 1 + MangoPay/PayIn.php | 1 + MangoPay/PayInPaymentDetailsBancontact.php | 28 +++++++++++++++++++ MangoPay/PayInPaymentType.php | 2 ++ tests/Cases/Base.php | 32 ++++++++++++++++++++++ tests/Cases/PayInsTest.php | 17 ++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 MangoPay/PayInPaymentDetailsBancontact.php diff --git a/MangoPay/Libraries/ApiBase.php b/MangoPay/Libraries/ApiBase.php index fe163378..fcf4f766 100644 --- a/MangoPay/Libraries/ApiBase.php +++ b/MangoPay/Libraries/ApiBase.php @@ -78,6 +78,7 @@ protected function getLogger() 'payins_klarna-web_create' => ['/payins/payment-methods/klarna', RequestType::POST], 'payins_ideal-web_create' => ['/payins/payment-methods/ideal', RequestType::POST], 'payins_giropay-web_create' => ['/payins/payment-methods/giropay', RequestType::POST], + 'payins_bancontact-web_create' => ['/payins/payment-methods/bancontact', RequestType::POST], 'add_tracking_info' => ['/payins/%s/trackings', RequestType::PUT], 'payment_method-metadata' => ['/payment-methods/metadata', RequestType::POST], diff --git a/MangoPay/PayIn.php b/MangoPay/PayIn.php index a484137f..24533530 100644 --- a/MangoPay/PayIn.php +++ b/MangoPay/PayIn.php @@ -69,6 +69,7 @@ public function GetDependsObjects() PayInPaymentType::Klarna => 'MangoPay\PayInPaymentDetailsKlarna', PayInPaymentType::Ideal => 'MangoPay\PayInPaymentDetailsIdeal', PayInPaymentType::Giropay => 'MangoPay\PayInPaymentDetailsGiropay', + PayInPaymentType::Bancontact => 'MangoPay\PayInPaymentDetailsBancontact', // ...and more in future... ], diff --git a/MangoPay/PayInPaymentDetailsBancontact.php b/MangoPay/PayInPaymentDetailsBancontact.php new file mode 100644 index 00000000..6e905941 --- /dev/null +++ b/MangoPay/PayInPaymentDetailsBancontact.php @@ -0,0 +1,28 @@ +_api->PayIns->Create($payIn); } + protected function getNewPayInBancontactWeb($userId = null) + { + $wallet = $this->getJohnsWalletWithMoney(); + if (is_null($userId)) { + $user = $this->getJohn(); + $userId = $user->Id; + } + + $payIn = new \MangoPay\PayIn(); + $payIn->AuthorId = $userId; + $payIn->CreditedWalletId = $wallet->Id; + $payIn->Fees = new \MangoPay\Money(); + $payIn->Fees->Amount = 10; + $payIn->Fees->Currency = 'EUR'; + $payIn->DebitedFunds = new \MangoPay\Money(); + $payIn->DebitedFunds->Amount = 1000; + $payIn->DebitedFunds->Currency = 'EUR'; + + $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsBancontact(); + $payIn->PaymentDetails->StatementDescriptor = 'test'; + $payIn->PaymentDetails->Recurring = true; + + // execution type as WEB + $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsWeb(); + $payIn->ExecutionDetails->ReturnURL = "http://www.my-site.com/returnURL?transactionId=wt_71a08458-b0cc-468d-98f7-1302591fc238"; + $payIn->ExecutionDetails->Culture = 'FR'; + + $payIn->Tag = "Bancontact tag"; + + return $this->_api->PayIns->Create($payIn); + } + /** * Creates Pay-In Card Direct object * @return \MangoPay\PayIn diff --git a/tests/Cases/PayInsTest.php b/tests/Cases/PayInsTest.php index 2373c2d1..a8c28a37 100644 --- a/tests/Cases/PayInsTest.php +++ b/tests/Cases/PayInsTest.php @@ -898,6 +898,23 @@ public function test_PayIns_Create_Giropay_Web() $this->assertEquals($payIn->Id, $fetchedPayIn->Id); } + public function test_PayIns_Create_Bancontact_Web() + { + $payIn = $this->getNewPayInBancontactWeb(); + + $this->assertNotNull($payIn->Id > 0); + $this->assertEquals(\MangoPay\PayInPaymentType::Bancontact, $payIn->PaymentType); + $this->assertInstanceOf('\MangoPay\PayInPaymentDetailsBancontact', $payIn->PaymentDetails); + $this->assertEquals(\MangoPay\PayInExecutionType::Web, $payIn->ExecutionType); + $this->assertInstanceOf('\MangoPay\PayInExecutionDetailsWeb', $payIn->ExecutionDetails); + $this->assertEquals(PayInStatus::Created, $payIn->Status); + $this->assertEquals('PAYIN', $payIn->Type); + $this->assertEquals('REGULAR', $payIn->Nature); + + $fetchedPayIn = $this->_api->PayIns->Get($payIn->Id); + $this->assertEquals($payIn->Id, $fetchedPayIn->Id); + } + public function test_CardDirect_getPaymentMethodMetadata() { $payin = $this->getNewPayInCardDirect();