Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions assets/js/blocks/gateways/buckaroo_zakelijkoprekening.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { __ } from '@wordpress/i18n';
import useFormData from '../hooks/useFormData';
import CoCField from '../partials/buckaroo_coc_field';

function ZakelijkOpRekening({ onStateChange, methodName, billing }) {
const initialState = {
[`${methodName}-company`]: billing?.company || '',
[`${methodName}-company-coc-registration`]: '',
};

const { handleChange } = useFormData(initialState, onStateChange);

const hasCompany = (billing?.company || '') !== '';

return (
<div id="buckaroo_zakelijkoprekening_b2b">
<p className="buckaroo-zakelijkoprekening-subtext">{__('Betaal later', 'wc-buckaroo-bpe-gateway')}</p>
<p className="buckaroo-zakelijkoprekening-tooltip">
{__('Voor iedereen, powered by ABN AMRO.', 'wc-buckaroo-bpe-gateway')}{' '}
<a
href="https://www.abnamro.nl/nl/zakelijk/betalen/zakelijk-op-rekening.html"
target="_blank"
rel="noopener noreferrer"
>
{__('lees meer', 'wc-buckaroo-bpe-gateway')}
</a>
</p>

{!hasCompany && (
<p className="form-row form-row-wide validate-required">
<label htmlFor={`${methodName}-company`}>
{__('Company name:', 'wc-buckaroo-bpe-gateway')}
<span className="required">*</span>
</label>
<input
id={`${methodName}-company`}
name={`${methodName}-company`}
className="input-text"
type="text"
maxLength="250"
autoComplete="organization"
onChange={handleChange}
/>
</p>
)}

<CoCField methodName={methodName} handleChange={handleChange} />
</div>
);
}

export default ZakelijkOpRekening;
2 changes: 2 additions & 0 deletions assets/js/blocks/gateways/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import buckaroo_klarnapay from './buckaroo_klarnapay';
import buckaroo_paybybank from './buckaroo_paybybank';
import buckaroo_payperemail from './buckaroo_payperemail';
import buckaroo_sepadirectdebit from './buckaroo_sepadirectdebit';
import buckaroo_zakelijkoprekening from './buckaroo_zakelijkoprekening';

export const paymentGatewaysTemplates = {
buckaroo_afterpay,
Expand All @@ -20,6 +21,7 @@ export const paymentGatewaysTemplates = {
buckaroo_paybybank,
buckaroo_payperemail,
buckaroo_sepadirectdebit,
buckaroo_zakelijkoprekening,
};

export const separateCreditCards = [
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dist/blocks.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-i18n'), 'version' => 'f999bf7f48eb669e606c');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-i18n'), 'version' => 'c9a34ee9cfd341761790');
2 changes: 1 addition & 1 deletion assets/js/dist/blocks.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Core/PaymentGatewayRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Buckaroo\Woocommerce\Gateways\WeChatPay\WeChatPayGateway;
use Buckaroo\Woocommerce\Gateways\Swish\SwishGateway;
use Buckaroo\Woocommerce\Gateways\Wero\WeroGateway;
use Buckaroo\Woocommerce\Gateways\ZakelijkOpRekening\ZakelijkOpRekeningGateway;
use Buckaroo\Woocommerce\Order\OrderCapture;

class PaymentGatewayRegistry
Expand Down Expand Up @@ -76,6 +77,7 @@ class PaymentGatewayRegistry
'alipay' => ['gateway_class' => AlipayGateway::class],
'wechatpay' => ['gateway_class' => WeChatPayGateway::class],
'wero' => ['gateway_class' => WeroGateway::class],
'zakelijkoprekening' => ['gateway_class' => ZakelijkOpRekeningGateway::class],
];

/**
Expand Down
27 changes: 27 additions & 0 deletions src/Gateways/ZakelijkOpRekening/Sdk/Company.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Buckaroo\Woocommerce\Gateways\ZakelijkOpRekening\Sdk;

use BuckarooDeps\Buckaroo\PaymentMethods\In3\Models\Company as In3Company;

/**
* B2B recipient model for the "Zakelijk op rekening" (In3 / AbnB2b) method.
*
* The bundled In3 SDK Company model only declares `customerNumber`, so the
* `CompanyName` and `CocNumber` service parameters required for a B2B order
* are silently dropped. We extend it here (instead of editing the vendored
* SDK) and declare the missing properties. The In3 RecipientAdapter already
* maps `companyName` -> CompanyName and `chamberOfCommerce` -> CocNumber.
*/
class Company extends In3Company
{
/**
* @var string|null
*/
protected ?string $companyName;

/**
* @var string|null
*/
protected ?string $chamberOfCommerce;
}
42 changes: 42 additions & 0 deletions src/Gateways/ZakelijkOpRekening/Sdk/Pay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Buckaroo\Woocommerce\Gateways\ZakelijkOpRekening\Sdk;

use BuckarooDeps\Buckaroo\PaymentMethods\In3\Models\Pay as In3Pay;

/**
* Pay/Authorize service model for the "Zakelijk op rekening" method.
*
* Identical to the In3 SDK Pay model, except the billing and shipping
* recipients are built from our Recipient subclass so the B2B company details
* (CompanyName / CocNumber) survive serialization. The `route` property
* (inherited from the In3 Pay model) is serialized as the "Route" parameter
* and is set to "AbnB2b" by the processor.
*/
class Pay extends In3Pay
{
/**
* {@inheritDoc}
*/
public function billing($billing = null)
{
if (is_array($billing)) {
$this->billingRecipient = new Recipient('Billing', $billing);
$this->shippingRecipient = new Recipient('Shipping', $billing);
}

return $this->billingRecipient;
}

/**
* {@inheritDoc}
*/
public function shipping($shipping = null)
{
if (is_array($shipping)) {
$this->shippingRecipient = new Recipient('Shipping', $shipping);
}

return $this->shippingRecipient;
}
}
35 changes: 35 additions & 0 deletions src/Gateways/ZakelijkOpRekening/Sdk/Recipient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Buckaroo\Woocommerce\Gateways\ZakelijkOpRekening\Sdk;

use BuckarooDeps\Buckaroo\PaymentMethods\In3\Models\Person as In3Person;
use BuckarooDeps\Buckaroo\PaymentMethods\In3\Models\Recipient as In3Recipient;
use BuckarooDeps\Buckaroo\PaymentMethods\In3\Service\ParameterKeys\RecipientAdapter;

/**
* Recipient for the "Zakelijk op rekening" method.
*
* The bundled In3 SDK Recipient resolves a B2B recipient to the SDK's own
* Company model (which cannot hold the company name / CoC number). We override
* recipient() so a B2B recipient is built from our extended Company model,
* keeping the CompanyName and CocNumber parameters in the request. B2C falls
* back to the standard In3 Person model.
*/
class Recipient extends In3Recipient
{
/**
* {@inheritDoc}
*/
public function recipient($recipient = null)
{
if (is_array($recipient)) {
if (isset($recipient['category']) && $recipient['category'] === 'B2B') {
$this->recipient = new RecipientAdapter(new Company($recipient));
} else {
$this->recipient = new RecipientAdapter(new In3Person($recipient));
}
}

return $this->recipient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Buckaroo\Woocommerce\Gateways\ZakelijkOpRekening\Sdk;

use BuckarooDeps\Buckaroo\Models\Model;
use BuckarooDeps\Buckaroo\PaymentMethods\In3\In3;
use BuckarooDeps\Buckaroo\Transaction\Response\TransactionResponse;

/**
* "Zakelijk op rekening" payment method (powered by ABN AMRO).
*
* Reuses the In3 service (paymentName "In3") but exposes the separate
* Authorize and Capture actions that the bundled In3 SDK does not provide,
* mirroring how the SDK's Afterpay method implements them. Defined here in the
* plugin namespace so the vendored SDK stays untouched.
*/
class ZakelijkOpRekeningPaymentMethod extends In3
{
/**
* Reserve the funds (separate Authorize flow). Returns a RedirectURL,
* exactly like the regular In3 Pay action.
*/
public function authorize(?Model $model = null): TransactionResponse
{
$pay = $model ?? new Pay($this->payload);

$this->setPayPayload();

$this->setServiceList('Authorize', $pay);

return $this->postRequest();
}

/**
* Capture (part of) a previously authorized transaction.
*
* When the capture amount equals the authorized amount, Buckaroo reuses the
* articles from the Authorize call, so no InvoiceLine parameters are sent
* (model is null). The amount and OriginalTransactionKey are carried on the
* top-level payload.
*/
public function capture(?Model $model = null): TransactionResponse
{
$this->setPayPayload();

$this->setServiceList('Capture', $model);

return $this->postRequest();
}
}
Loading
Loading