Skip to content

Commit

Permalink
Add SEPA Direct Debit Core Support (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Apr 22, 2024
1 parent ee391de commit c944daa
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/Checkout/Common/InstrumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class InstrumentType

public static $card = "card";

public static $sepa = "sepa";

public static $card_token = "card_token";
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function __construct()
*/
public $bank_details;

/**
* @var BankDetails
*/
public $bank;

/**
* @var CreateCustomerInstrumentRequest
*/
Expand Down
26 changes: 26 additions & 0 deletions lib/Checkout/Instruments/Create/CreateSepaInstrumentRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Checkout\Instruments\Create;

use Checkout\Common\AccountHolder;
use Checkout\Common\InstrumentType;

class CreateSepaInstrumentRequest extends CreateInstrumentRequest
{

public function __construct()
{
parent::__construct(InstrumentType::$sepa);
}

/**
* @var InstrumentData
*/
public $instrument_data;

/**
* @var AccountHolder
*/
public $account_holder;

}
36 changes: 36 additions & 0 deletions lib/Checkout/Instruments/Create/InstrumentData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Checkout\Instruments\Create;

class InstrumentData
{
/**
* @var string
*/
public $account_number;

/**
* @var string values of Country
*/
public $country;

/**
* @var string values of Currency
*/
public $currency;

/**
* @var string values of PaymentType
*/
public $payment_type;

/**
* @var string
*/
public $mandate_id;

/**
* @var DateTime
*/
public $date_of_signature;
}
5 changes: 5 additions & 0 deletions lib/Checkout/Payments/Request/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,9 @@ class PaymentRequest
* @var PaymentRetryRequest
*/
public $retry;

/**
* @var PaymentInstruction
*/
public $instruction;
}
36 changes: 36 additions & 0 deletions test/Checkout/Tests/Instruments/InstrumentsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
use Checkout\CheckoutAuthorizationException;
use Checkout\CheckoutException;
use Checkout\Common\AccountHolder;
use Checkout\Common\Country;
use Checkout\Common\Currency;
use Checkout\Customers\CustomerRequest;
use Checkout\Instruments\Create\CreateCustomerInstrumentRequest;
use Checkout\Instruments\Create\CreateSepaInstrumentRequest;
use Checkout\Instruments\Create\CreateTokenInstrumentRequest;
use Checkout\Instruments\Create\InstrumentData;
use Checkout\Instruments\Update\UpdateCardInstrumentRequest;
use Checkout\Instruments\Update\UpdateCustomerRequest;
use Checkout\Instruments\Update\UpdateTokenInstrumentRequest;
use Checkout\Payments\PaymentType;
use Checkout\PlatformType;
use Checkout\Tests\Payments\AbstractPaymentsIntegrationTest;

Expand All @@ -30,6 +35,37 @@ public function before()
$this->init(PlatformType::$default);
}

/**
* @test
* @throws CheckoutApiException
*/
public function shouldCreateSepaInstrument()
{
$instrumentData = new InstrumentData();
$instrumentData->account_number = "FR7630006000011234567890189";
$instrumentData->country = Country::$FR;
$instrumentData->currency = Currency::$EUR;
$instrumentData->payment_type = PaymentType::$recurring;

$accountHolder = new AccountHolder();
$accountHolder->first_name = "John";
$accountHolder->last_name = "Smith";
$accountHolder->phone = $this->getPhone();
$accountHolder->billing_address = $this->getAddress();

$sepaInstrument = new CreateSepaInstrumentRequest();
$sepaInstrument->instrument_data = $instrumentData;
$sepaInstrument->account_holder = $accountHolder;

$response = $this->checkoutApi->getInstrumentsClient()->create($sepaInstrument);
$this->assertResponse(
$response,
"id",
"type",
"fingerprint"
);
}

/**
* @test
* @throws CheckoutApiException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use Checkout\Common\Currency;
use Checkout\Common\CustomerRequest;
use Checkout\Common\Phone;
use Checkout\Common\Product;
use Checkout\Environment;
use Checkout\Payments\BillingPlan;
use Checkout\Payments\BillingPlanType;
use Checkout\Payments\PaymentCustomerRequest;
use Checkout\Payments\ProcessingSettings;
use Checkout\Payments\Product;
use Checkout\Payments\Request\PaymentRequest;
use Checkout\Payments\Request\Source\Apm\FawryProduct;
use Checkout\Payments\Request\Source\Apm\RequestAfterPaySource;
Expand Down Expand Up @@ -744,7 +744,6 @@ public function shouldMakeCvConnectPayment()
*/
public function shouldMakeSepaPayment()
{
$this->markTestSkipped("unavailable");
$requestSource = new RequestSepaSource();
$requestSource->country = Country::$ES;
$requestSource->currency = Currency::$EUR;
Expand Down

0 comments on commit c944daa

Please sign in to comment.