Skip to content
Draft
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
7 changes: 7 additions & 0 deletions modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,12 @@
$modules[] = ( require "$modules_dir/ppcp-axo-block/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;
};
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
Loading