Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New SEPA Direct Debit integration (3698) #2855

Draft
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions modules.php
Original file line number Diff line number Diff line change
@@ -97,5 +97,12 @@
$modules[] = ( require "$modules_dir/ppcp-settings/module.php" )();
}

if ( apply_filters(
'woocommerce.feature-flags.woocommerce_paypal_payments.sepa_enabled',
getenv( 'PCP_SEPA_ENABLED' ) === '1'
) ) {
$modules[] = ( require "$modules_dir/ppcp-sepa/module.php" )();
}

return $modules;
};
54 changes: 35 additions & 19 deletions modules/ppcp-blocks/resources/js/Components/card-fields.js
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ import { useEffect, useState } from '@wordpress/element';
import {
PayPalScriptProvider,
PayPalCardFieldsProvider,
PayPalNameField,
PayPalNumberField,
PayPalExpiryField,
PayPalCVVField,
PayPalNameField,
PayPalNumberField,
PayPalExpiryField,
PayPalCVVField,
} from '@paypal/react-paypal-js';

import { CheckoutHandler } from './checkout-handler';
@@ -19,11 +19,7 @@ import {
import { cartHasSubscriptionProducts } from '../Helper/Subscription';
import { __ } from '@wordpress/i18n';

export function CardFields( {
config,
eventRegistration,
emitResponse,
} ) {
export function CardFields( { config, eventRegistration, emitResponse } ) {
const { onPaymentSetup } = eventRegistration;
const { responseTypes } = emitResponse;

@@ -96,16 +92,36 @@ export function CardFields( {
console.error( err );
} }
>
<PayPalNameField placeholder={ __( 'Cardholder Name (optional)', 'woocommerce-paypal-payments' ) }/>
<PayPalNumberField placeholder={ __( 'Card number', 'woocommerce-paypal-payments' ) }/>
<div style={ { display: "flex", width: "100%" } }>
<div style={ { width: "100%" } }>
<PayPalExpiryField placeholder={ __( 'MM / YY', 'woocommerce-paypal-payments' ) }/>
</div>
<div style={ { width: "100%" } }>
<PayPalCVVField placeholder={ __( 'CVV', 'woocommerce-paypal-payments' ) }/>
</div>
</div>
<PayPalNameField
placeholder={ __(
'Cardholder Name (optional)',
'woocommerce-paypal-payments'
) }
/>
<PayPalNumberField
placeholder={ __(
'Card number',
'woocommerce-paypal-payments'
) }
/>
<div style={ { display: 'flex', width: '100%' } }>
<div style={ { width: '100%' } }>
<PayPalExpiryField
placeholder={ __(
'MM / YY',
'woocommerce-paypal-payments'
) }
/>
</div>
<div style={ { width: '100%' } }>
<PayPalCVVField
placeholder={ __(
'CVV',
'woocommerce-paypal-payments'
) }
/>
</div>
</div>
<CheckoutHandler
getCardFieldsForm={ getCardFieldsForm }
getSavePayment={ getSavePayment }
17 changes: 17 additions & 0 deletions modules/ppcp-sepa/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "woocommerce/ppcp-sepa",
"type": "dhii-mod",
"description": "SEPA direct debit payment",
"license": "GPL-2.0",
"require": {
"php": "^7.4 | ^8.0",
"dhii/module-interface": "^0.3.0-alpha1"
},
"autoload": {
"psr-4": {
"WooCommerce\\PayPalCommerce\\SEPA\\": "src"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
12 changes: 12 additions & 0 deletions modules/ppcp-sepa/extensions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* The SEPA module extensions.
*
* @package WooCommerce\PayPalCommerce\SEPA
*/

declare(strict_types=1);

namespace WooCommerce\PayPalCommerce\SEPA;

return array();
14 changes: 14 additions & 0 deletions modules/ppcp-sepa/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* The SEPA module.
*
* @package WooCommerce\PayPalCommerce\SEPA
*/

declare(strict_types=1);

namespace WooCommerce\PayPalCommerce\SEPA;

return static function (): SEPAModule {
return new SEPAModule();
};
12 changes: 12 additions & 0 deletions modules/ppcp-sepa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ppcp-sepa",
"version": "1.0.0",
"license": "GPL-3.0-or-later",
"scripts": {
"watch": "wp-scripts start --webpack-src-dir=resources/js --output-path=assets",
"build": "wp-scripts build --webpack-src-dir=resources/js --output-path=assets"
},
"devDependencies": {
"@wordpress/scripts": "^30.3.0"
}
}
35 changes: 35 additions & 0 deletions modules/ppcp-sepa/resources/js/SEPA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect, useState } from '@wordpress/element';

export function SEPA( { eventRegistration, emitResponse } ) {
const { onPaymentSetup } = eventRegistration;
const { responseTypes } = emitResponse;

const [ iban, setIban ] = useState( '' );

useEffect(
() =>
onPaymentSetup( () => {
async function handlePaymentProcessing() {
return {
type: responseTypes.SUCCESS,
meta: {
paymentMethodData: {
ppcp_sepa_iban: iban,
},
},
};
}

return handlePaymentProcessing();
} ),
[ onPaymentSetup, iban ]
);

return (
<input
name="ppcp_sepa_iban"
value={ iban }
onChange={ ( e ) => setIban( e.target.value ) }
/>
);
}
18 changes: 18 additions & 0 deletions modules/ppcp-sepa/resources/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SEPA } from './SEPA';

const { registerPaymentMethod } = window.wc.wcBlocksRegistry;
const config = wc.wcSettings.getSetting( 'ppcp-sepa_data' );

registerPaymentMethod( {
name: config.id,
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
content: <SEPA />,
edit: <div></div>,
ariaLabel: config.title,
canMakePayment: () => {
return true;
},
supports: {
features: config.supports,
},
} );
47 changes: 47 additions & 0 deletions modules/ppcp-sepa/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* The SEPA module services.
*
* @package WooCommerce\PayPalCommerce\SEPA
*/

declare(strict_types=1);

namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;

use WooCommerce\PayPalCommerce\SEPA\SEPAGateway;
use WooCommerce\PayPalCommerce\SEPA\SEPAPaymentMethod;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;

return array(
'sepa.url' => static function ( ContainerInterface $container ): string {
/**
* The path cannot be false.
*
* @psalm-suppress PossiblyFalseArgument
*/
return plugins_url(
'/modules/ppcp-sepa/',
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
'sepa.wc-gateway' => static function ( ContainerInterface $container ): SEPAGateway {
return new SEPAGateway(
$container->get( 'api.endpoint.orders' ),
$container->get( 'api.factory.purchase-unit' ),
$container->get( 'wcgateway.order-processor' ),
$container->get( 'api.factory.paypal-checkout-url' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'session.handler' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'sepa.payment-method' => static function( ContainerInterface $container ): SEPAPaymentMethod {
return new SEPAPaymentMethod(
$container->get( 'sepa.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'sepa.wc-gateway' )
);
},
);
Loading