mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge pull request #2511 from woocommerce/PCP-3317-implement-ap-ms-via-orders-api
Implement country based APMs via Orders API (3317)
This commit is contained in:
commit
ffc389ebda
39 changed files with 5347 additions and 0 deletions
|
@ -88,5 +88,12 @@ return function ( string $root_dir ): iterable {
|
||||||
$modules[] = ( require "$modules_dir/ppcp-axo/module.php" )();
|
$modules[] = ( require "$modules_dir/ppcp-axo/module.php" )();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( apply_filters(
|
||||||
|
'woocommerce.feature-flags.woocommerce_paypal_payments.local_apms_enabled',
|
||||||
|
getenv( 'PCP_LOCAL_APMS_ENABLED' ) === '1'
|
||||||
|
) ) {
|
||||||
|
$modules[] = ( require "$modules_dir/ppcp-local-alternative-payment-methods/module.php" )();
|
||||||
|
}
|
||||||
|
|
||||||
return $modules;
|
return $modules;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ClientCredentials;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ClientCredentials;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\UserIdToken;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\UserIdToken;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentMethodTokensEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentMethodTokensEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult;
|
||||||
|
@ -240,6 +241,13 @@ return array(
|
||||||
$bn_code
|
$bn_code
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'api.endpoint.orders' => static function ( ContainerInterface $container ): Orders {
|
||||||
|
return new Orders(
|
||||||
|
$container->get( 'api.host' ),
|
||||||
|
$container->get( 'api.bearer' ),
|
||||||
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
|
);
|
||||||
|
},
|
||||||
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {
|
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {
|
||||||
return new BillingAgreementsEndpoint(
|
return new BillingAgreementsEndpoint(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
|
|
108
modules/ppcp-api-client/src/Endpoint/Orders.php
Normal file
108
modules/ppcp-api-client/src/Endpoint/Orders.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orders API endpoints.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
||||||
|
* @link https://developer.paypal.com/docs/api/orders/v2/ Orders API documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Orders
|
||||||
|
*/
|
||||||
|
class Orders {
|
||||||
|
|
||||||
|
use RequestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The host.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bearer.
|
||||||
|
*
|
||||||
|
* @var Bearer
|
||||||
|
*/
|
||||||
|
private $bearer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*
|
||||||
|
* @var LoggerInterface
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders constructor.
|
||||||
|
*
|
||||||
|
* @param string $host The host.
|
||||||
|
* @param Bearer $bearer The bearer.
|
||||||
|
* @param LoggerInterface $logger The logger.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $host,
|
||||||
|
Bearer $bearer,
|
||||||
|
LoggerInterface $logger
|
||||||
|
) {
|
||||||
|
$this->host = $host;
|
||||||
|
$this->bearer = $bearer;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PayPal order.
|
||||||
|
*
|
||||||
|
* @param array $request_body The request body.
|
||||||
|
* @param array $headers The request headers.
|
||||||
|
* @return array
|
||||||
|
* @throws RuntimeException If something went wrong with the request.
|
||||||
|
* @throws PayPalApiException If something went wrong with the PayPal API request.
|
||||||
|
*/
|
||||||
|
public function create( array $request_body, array $headers = array() ): array {
|
||||||
|
$bearer = $this->bearer->bearer();
|
||||||
|
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
|
||||||
|
|
||||||
|
$default_headers = array(
|
||||||
|
'Authorization' => 'Bearer ' . $bearer->token(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'PayPal-Request-Id' => uniqid( 'ppcp-', true ),
|
||||||
|
);
|
||||||
|
$headers = array_merge(
|
||||||
|
$default_headers,
|
||||||
|
$headers
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'method' => 'POST',
|
||||||
|
'headers' => $headers,
|
||||||
|
'body' => wp_json_encode( $request_body ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->request( $url, $args );
|
||||||
|
if ( $response instanceof WP_Error ) {
|
||||||
|
throw new RuntimeException( $response->get_error_message() );
|
||||||
|
}
|
||||||
|
|
||||||
|
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||||
|
if ( $status_code !== 200 ) {
|
||||||
|
throw new PayPalApiException(
|
||||||
|
json_decode( $response['body'] ),
|
||||||
|
$status_code
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -92,6 +92,11 @@ class GooglePayGateway extends WC_Payment_Gateway {
|
||||||
) {
|
) {
|
||||||
$this->id = self::ID;
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
$this->method_title = __( 'Google Pay (via PayPal) ', 'woocommerce-paypal-payments' );
|
$this->method_title = __( 'Google Pay (via PayPal) ', 'woocommerce-paypal-payments' );
|
||||||
$this->method_description = __( 'The separate payment gateway with the Google Pay button. If disabled, the button is included in the PayPal gateway.', 'woocommerce-paypal-payments' );
|
$this->method_description = __( 'The separate payment gateway with the Google Pay button. If disabled, the button is included in the PayPal gateway.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
|
14
modules/ppcp-local-alternative-payment-methods/.babelrc
Normal file
14
modules/ppcp-local-alternative-payment-methods/.babelrc
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
[
|
||||||
|
"@babel/preset-env",
|
||||||
|
{
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"corejs": "3.25.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/preset-react"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
3
modules/ppcp-local-alternative-payment-methods/.gitignore
vendored
Normal file
3
modules/ppcp-local-alternative-payment-methods/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
assets/js
|
||||||
|
assets/css
|
17
modules/ppcp-local-alternative-payment-methods/composer.json
Normal file
17
modules/ppcp-local-alternative-payment-methods/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "woocommerce/ppcp-local-alternative-payment-methods",
|
||||||
|
"type": "dhii-mod",
|
||||||
|
"description": "Country based Alternative Payment Methods module",
|
||||||
|
"license": "GPL-2.0",
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 | ^8.0",
|
||||||
|
"dhii/module-interface": "^0.3.0-alpha1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"WooCommerce\\PayPalCommerce\\LocalAlternativePaymentMethods\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The local alternative payment methods module extensions.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
return array();
|
16
modules/ppcp-local-alternative-payment-methods/module.php
Normal file
16
modules/ppcp-local-alternative-payment-methods/module.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The local alternative payment methods module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
|
|
||||||
|
return static function (): ModuleInterface {
|
||||||
|
return new LocalAlternativePaymentMethodsModule();
|
||||||
|
};
|
33
modules/ppcp-local-alternative-payment-methods/package.json
Normal file
33
modules/ppcp-local-alternative-payment-methods/package.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"name": "ppcp-local-alternative-payment-methods",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"browserslist": [
|
||||||
|
"> 0.5%",
|
||||||
|
"Safari >= 8",
|
||||||
|
"Chrome >= 41",
|
||||||
|
"Firefox >= 43",
|
||||||
|
"Edge >= 14"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^3.25.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.19",
|
||||||
|
"@babel/preset-env": "^7.19",
|
||||||
|
"@babel/preset-react": "^7.18.6",
|
||||||
|
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
|
||||||
|
"babel-loader": "^8.2",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"file-loader": "^6.2.0",
|
||||||
|
"sass": "^1.42.1",
|
||||||
|
"sass-loader": "^12.1.0",
|
||||||
|
"webpack": "^5.76",
|
||||||
|
"webpack-cli": "^4.10"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||||
|
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||||
|
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
export function APM( { config, components } ) {
|
||||||
|
const { PaymentMethodIcons } = components;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<PaymentMethodIcons icons={ [ config.icon ] } align="right" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-bancontact_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-blik_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-eps_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-ideal_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-mybank_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-p24_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
import { APM } from './apm-block';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-trustly_data' );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <APM config={ config } />,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
170
modules/ppcp-local-alternative-payment-methods/services.php
Normal file
170
modules/ppcp-local-alternative-payment-methods/services.php
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The local alternative payment methods module services.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'ppcp-local-apms.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
/**
|
||||||
|
* The path cannot be false.
|
||||||
|
*
|
||||||
|
* @psalm-suppress PossiblyFalseArgument
|
||||||
|
*/
|
||||||
|
return plugins_url(
|
||||||
|
'/modules/ppcp-local-alternative-payment-methods/',
|
||||||
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.payment-methods' => static function( ContainerInterface $container ): array {
|
||||||
|
return array(
|
||||||
|
'bancontact' => array(
|
||||||
|
'id' => BancontactGateway::ID,
|
||||||
|
'countries' => array( 'BE' ),
|
||||||
|
'currencies' => array( 'EUR' ),
|
||||||
|
),
|
||||||
|
'blik' => array(
|
||||||
|
'id' => BlikGateway::ID,
|
||||||
|
'countries' => array( 'PL' ),
|
||||||
|
'currencies' => array( 'PLN' ),
|
||||||
|
),
|
||||||
|
'eps' => array(
|
||||||
|
'id' => EPSGateway::ID,
|
||||||
|
'countries' => array( 'AT' ),
|
||||||
|
'currencies' => array( 'EUR' ),
|
||||||
|
),
|
||||||
|
'ideal' => array(
|
||||||
|
'id' => IDealGateway::ID,
|
||||||
|
'countries' => array( 'NL' ),
|
||||||
|
'currencies' => array( 'EUR' ),
|
||||||
|
),
|
||||||
|
'mybank' => array(
|
||||||
|
'id' => MyBankGateway::ID,
|
||||||
|
'countries' => array( 'IT' ),
|
||||||
|
'currencies' => array( 'EUR' ),
|
||||||
|
),
|
||||||
|
'p24' => array(
|
||||||
|
'id' => P24Gateway::ID,
|
||||||
|
'countries' => array( 'PL' ),
|
||||||
|
'currencies' => array( 'EUR', 'PLN' ),
|
||||||
|
),
|
||||||
|
'trustly' => array(
|
||||||
|
'id' => TrustlyGateway::ID,
|
||||||
|
'countries' => array( 'AT', 'DE', 'DK', 'EE', 'ES', 'FI', 'GB', 'LT', 'LV', 'NL', 'NO', 'SE' ),
|
||||||
|
'currencies' => array( 'EUR', 'DKK', 'SEK', 'GBP', 'NOK' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.bancontact.wc-gateway' => static function ( ContainerInterface $container ): BancontactGateway {
|
||||||
|
return new BancontactGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.blik.wc-gateway' => static function ( ContainerInterface $container ): BlikGateway {
|
||||||
|
return new BlikGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.eps.wc-gateway' => static function ( ContainerInterface $container ): EPSGateway {
|
||||||
|
return new EPSGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.ideal.wc-gateway' => static function ( ContainerInterface $container ): IDealGateway {
|
||||||
|
return new IDealGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.mybank.wc-gateway' => static function ( ContainerInterface $container ): MyBankGateway {
|
||||||
|
return new MyBankGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.p24.wc-gateway' => static function ( ContainerInterface $container ): P24Gateway {
|
||||||
|
return new P24Gateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.trustly.wc-gateway' => static function ( ContainerInterface $container ): TrustlyGateway {
|
||||||
|
return new TrustlyGateway(
|
||||||
|
$container->get( 'api.endpoint.orders' ),
|
||||||
|
$container->get( 'api.factory.purchase-unit' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' ),
|
||||||
|
$container->get( 'wcgateway.transaction-url-provider' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.bancontact.payment-method' => static function( ContainerInterface $container ): BancontactPaymentMethod {
|
||||||
|
return new BancontactPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.bancontact.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.blik.payment-method' => static function( ContainerInterface $container ): BlikPaymentMethod {
|
||||||
|
return new BlikPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.blik.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.eps.payment-method' => static function( ContainerInterface $container ): EPSPaymentMethod {
|
||||||
|
return new EPSPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.eps.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.ideal.payment-method' => static function( ContainerInterface $container ): IDealPaymentMethod {
|
||||||
|
return new IDealPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.ideal.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.mybank.payment-method' => static function( ContainerInterface $container ): MyBankPaymentMethod {
|
||||||
|
return new MyBankPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.mybank.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.p24.payment-method' => static function( ContainerInterface $container ): P24PaymentMethod {
|
||||||
|
return new P24PaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.p24.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'ppcp-local-apms.trustly.payment-method' => static function( ContainerInterface $container ): TrustlyPaymentMethod {
|
||||||
|
return new TrustlyPaymentMethod(
|
||||||
|
$container->get( 'ppcp-local-apms.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'ppcp-local-apms.trustly.wc-gateway' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
|
@ -0,0 +1,226 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Bancontact payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BancontactGateway
|
||||||
|
*/
|
||||||
|
class BancontactGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-bancontact';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BancontactGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'Bancontact', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'A popular and trusted electronic payment method in Belgium, used by Belgian customers with Bancontact cards issued by local banks. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'Bancontact', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_bancontact_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable Bancontact payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting Bancontact to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'bancontact' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'en-BE',
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Bancontact payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BancontactPaymentMethod
|
||||||
|
*/
|
||||||
|
class BancontactPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bancontact WC gateway.
|
||||||
|
*
|
||||||
|
* @var BancontactGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BancontactPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param BancontactGateway $gateway Bancontact WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
BancontactGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = BancontactGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-bancontact-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/bancontact-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-bancontact-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_bancontact_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,227 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Blik payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BlikGateway
|
||||||
|
*/
|
||||||
|
class BlikGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-blik';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BlikGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'Blik', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'Blik', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_blik_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Blik', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable Blik payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting Blik to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'blik' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
'email' => $wc_order->get_billing_email(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'en-PL',
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Blik payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BlikPaymentMethod
|
||||||
|
*/
|
||||||
|
class BlikPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blik WC gateway.
|
||||||
|
*
|
||||||
|
* @var BlikGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BlikPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param BlikGateway $gateway Blik WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
BlikGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = BlikGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-blick-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/blik-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-blick-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_blik_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,226 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The EPS payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EPSGateway
|
||||||
|
*/
|
||||||
|
class EPSGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-eps';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EPSGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'EPS', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'EPS', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_eps_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'EPS', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable EPS payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting EPS to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'eps' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'en-AT',
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* EPS payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EPSPaymentMethod
|
||||||
|
*/
|
||||||
|
class EPSPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EPS WC gateway.
|
||||||
|
*
|
||||||
|
* @var EPSGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EPSPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param EPSGateway $gateway EPS WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
EPSGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = EPSGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-eps-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/eps-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-eps-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_eps_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,228 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The iDeal payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class IDealGateway
|
||||||
|
*/
|
||||||
|
class IDealGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-ideal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDealGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'iDeal', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'The most common payment method in the Netherlands, allowing Dutch buyers to pay directly through their preferred bank. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'iDeal', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_ideal_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'iDeal', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable iDeal payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting iDeal to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$payment_source = array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
);
|
||||||
|
// TODO get "bic" from gateway settings.
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'ideal' => $payment_source,
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* IDeal payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class IDealPaymentMethod
|
||||||
|
*/
|
||||||
|
class IDealPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDeal WC gateway.
|
||||||
|
*
|
||||||
|
* @var IDealGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IDealPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param IDealGateway $gateway IDeal WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
IDealGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = IDealGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-ideal-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/ideal-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-ideal-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_ideal_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,171 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The local alternative payment methods module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||||
|
use WC_Order;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LocalAlternativePaymentMethodsModule
|
||||||
|
*/
|
||||||
|
class LocalAlternativePaymentMethodsModule implements ModuleInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function setup(): ServiceProviderInterface {
|
||||||
|
return new ServiceProvider(
|
||||||
|
require __DIR__ . '/../services.php',
|
||||||
|
require __DIR__ . '/../extensions.php'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function run( ContainerInterface $c ): void {
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_payment_gateways',
|
||||||
|
/**
|
||||||
|
* Param types removed to avoid third-party issues.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
function ( $methods ) use ( $c ) {
|
||||||
|
if ( ! is_array( $methods ) ) {
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||||
|
foreach ( $payment_methods as $key => $value ) {
|
||||||
|
$methods[] = $c->get( 'ppcp-local-apms.' . $key . '.wc-gateway' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_available_payment_gateways',
|
||||||
|
/**
|
||||||
|
* Param types removed to avoid third-party issues.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
function ( $methods ) use ( $c ) {
|
||||||
|
if ( ! is_array( $methods ) ) {
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! is_admin() ) {
|
||||||
|
if ( ! isset( WC()->customer ) ) {
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country();
|
||||||
|
$site_currency = get_woocommerce_currency();
|
||||||
|
|
||||||
|
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||||
|
foreach ( $payment_methods as $payment_method ) {
|
||||||
|
if (
|
||||||
|
! in_array( $customer_country, $payment_method['countries'], true )
|
||||||
|
|| ! in_array( $site_currency, $payment_method['currencies'], true )
|
||||||
|
) {
|
||||||
|
unset( $methods[ $payment_method['id'] ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'woocommerce_blocks_payment_method_type_registration',
|
||||||
|
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
|
||||||
|
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||||
|
foreach ( $payment_methods as $key => $value ) {
|
||||||
|
$payment_method_registry->register( $c->get( 'ppcp-local-apms.' . $key . '.payment-method' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_paypal_payments_localized_script_data',
|
||||||
|
function ( array $data ) use ( $c ) {
|
||||||
|
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||||
|
|
||||||
|
$default_disable_funding = $data['url_params']['disable-funding'] ?? '';
|
||||||
|
$disable_funding = array_merge( array_keys( $payment_methods ), array_filter( explode( ',', $default_disable_funding ) ) );
|
||||||
|
$data['url_params']['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'woocommerce_before_thankyou',
|
||||||
|
/**
|
||||||
|
* Activate is_checkout() on woocommerce/classic-shortcode checkout blocks.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
function( $order_id ) use ( $c ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! $order instanceof WC_Order ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||||
|
$cancelled = wc_clean( wp_unslash( $_GET['cancelled'] ?? '' ) );
|
||||||
|
$order_key = wc_clean( wp_unslash( $_GET['key'] ?? '' ) );
|
||||||
|
// phpcs:enable
|
||||||
|
|
||||||
|
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
|
||||||
|
if (
|
||||||
|
! $this->is_local_apm( $order->get_payment_method(), $payment_methods )
|
||||||
|
|| ! $cancelled
|
||||||
|
|| $order->get_order_key() !== $order_key
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||||
|
$error_code = wc_clean( wp_unslash( $_GET['errorcode'] ?? '' ) );
|
||||||
|
if ( $error_code === 'processing_error' || $error_code === 'payment_error' ) {
|
||||||
|
$order->update_status( 'failed', __( "The payment can't be processed because of an error.", 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
add_filter( 'woocommerce_order_has_status', '__return_true' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if given payment method is a local APM.
|
||||||
|
*
|
||||||
|
* @param string $selected_payment_method Selected payment method.
|
||||||
|
* @param array $payment_methods Available local APMs.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function is_local_apm( string $selected_payment_method, array $payment_methods ): bool {
|
||||||
|
foreach ( $payment_methods as $payment_method ) {
|
||||||
|
if ( $payment_method['id'] === $selected_payment_method ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,226 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The MyBank payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class MyBankGateway
|
||||||
|
*/
|
||||||
|
class MyBankGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-mybank';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBankGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'MyBank', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'MyBank', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_mybank_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'MyBank', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable MyBank payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting MyBank to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'mybank' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'en-IT',
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* MyBank payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class MyBankPaymentMethod
|
||||||
|
*/
|
||||||
|
class MyBankPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBank WC gateway.
|
||||||
|
*
|
||||||
|
* @var MyBankGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBankPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param MyBankGateway $gateway MyBank WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
MyBankGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = MyBankGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-mybank-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/mybank-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-mybank-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_mybank_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,227 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The P24 payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class P24Gateway
|
||||||
|
*/
|
||||||
|
class P24Gateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-p24';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P24Gateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'Przelewy24', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'Przelewy24', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_przelewy24_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable Przelewy24 payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting Przelewy24 to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'p24' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
'email' => $wc_order->get_billing_email(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => 'en-PL',
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Przelewy24 payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class P24PaymentMethod
|
||||||
|
*/
|
||||||
|
class P24PaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P24Gateway WC gateway.
|
||||||
|
*
|
||||||
|
* @var P24Gateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P24PaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param P24Gateway $gateway Przelewy24 WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
P24Gateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = P24Gateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-p24-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/p24-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-p24-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_przelewy24_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,249 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Trustly payment gateway.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TrustlyGateway
|
||||||
|
*/
|
||||||
|
class TrustlyGateway extends WC_Payment_Gateway {
|
||||||
|
|
||||||
|
const ID = 'ppcp-trustly';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PayPal Orders endpoint.
|
||||||
|
*
|
||||||
|
* @var Orders
|
||||||
|
*/
|
||||||
|
private $orders_endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase unit factory.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnitFactory
|
||||||
|
*/
|
||||||
|
private $purchase_unit_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Refund Processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service able to provide transaction url for an order.
|
||||||
|
*
|
||||||
|
* @var TransactionUrlProvider
|
||||||
|
*/
|
||||||
|
protected $transaction_url_provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TrustlyGateway constructor.
|
||||||
|
*
|
||||||
|
* @param Orders $orders_endpoint PayPal Orders endpoint.
|
||||||
|
* @param PurchaseUnitFactory $purchase_unit_factory Purchase unit factory.
|
||||||
|
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||||
|
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
Orders $orders_endpoint,
|
||||||
|
PurchaseUnitFactory $purchase_unit_factory,
|
||||||
|
RefundProcessor $refund_processor,
|
||||||
|
TransactionUrlProvider $transaction_url_provider
|
||||||
|
) {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->supports = array(
|
||||||
|
'refunds',
|
||||||
|
'products',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->method_title = __( 'Trustly', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', __( 'Trustly', 'woocommerce-paypal-payments' ) );
|
||||||
|
$this->description = $this->get_option( 'description', '' );
|
||||||
|
|
||||||
|
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_trustly_color.svg' );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
|
||||||
|
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
|
||||||
|
|
||||||
|
$this->orders_endpoint = $orders_endpoint;
|
||||||
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Trustly', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable Trustly payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the order.
|
||||||
|
*
|
||||||
|
* @param int $order_id The WC order ID.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function process_payment( $order_id ) {
|
||||||
|
$wc_order = wc_get_order( $order_id );
|
||||||
|
$wc_order->update_status( 'on-hold', __( 'Awaiting Trustly to confirm the payment.', 'woocommerce-paypal-payments' ) );
|
||||||
|
|
||||||
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
|
$amount = $purchase_unit->amount()->to_array();
|
||||||
|
|
||||||
|
$request_body = array(
|
||||||
|
'intent' => 'CAPTURE',
|
||||||
|
'payment_source' => array(
|
||||||
|
'trustly' => array(
|
||||||
|
'country_code' => $wc_order->get_billing_country(),
|
||||||
|
'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'reference_id' => $purchase_unit->reference_id(),
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => $amount['currency_code'],
|
||||||
|
'value' => $amount['value'],
|
||||||
|
),
|
||||||
|
'custom_id' => $purchase_unit->custom_id(),
|
||||||
|
'invoice_id' => $purchase_unit->invoice_id(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'application_context' => array(
|
||||||
|
'locale' => $this->valid_bcp47_code(),
|
||||||
|
'return_url' => $this->get_return_url( $wc_order ),
|
||||||
|
'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->orders_endpoint->create( $request_body );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$exception->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'failure',
|
||||||
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$payer_action = '';
|
||||||
|
foreach ( $body->links as $link ) {
|
||||||
|
if ( $link->rel === 'payer-action' ) {
|
||||||
|
$payer_action = $link->href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'result' => 'success',
|
||||||
|
'redirect' => esc_url( $payer_action ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* If the gateway declares 'refunds' support, this will allow it to refund.
|
||||||
|
* a passed in amount.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return transaction url for this gateway and given order.
|
||||||
|
*
|
||||||
|
* @param \WC_Order $order WC order to get transaction url by.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_transaction_url( $order ): string {
|
||||||
|
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
|
||||||
|
|
||||||
|
return parent::get_transaction_url( $order );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a PayPal-supported BCP-47 code, for example de-DE-formal becomes de-DE.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function valid_bcp47_code() {
|
||||||
|
$locale = str_replace( '_', '-', get_user_locale() );
|
||||||
|
|
||||||
|
if ( preg_match( '/^[a-z]{2}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}))?$/', $locale ) ) {
|
||||||
|
return $locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = explode( '-', $locale );
|
||||||
|
if ( count( $parts ) === 3 ) {
|
||||||
|
$ret = substr( $locale, 0, strrpos( $locale, '-' ) );
|
||||||
|
if ( false !== $ret ) {
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'en';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Trustly payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TrustlyPaymentMethod
|
||||||
|
*/
|
||||||
|
class TrustlyPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TrustlyGateway WC gateway.
|
||||||
|
*
|
||||||
|
* @var TrustlyGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TrustlyPaymentMethod constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL of this module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
* @param TrustlyGateway $gateway Trustly WC gateway.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
TrustlyGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = TrustlyGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-trustly-payment-method',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/trustly-payment-method.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-trustly-payment-method' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_trustly_color.svg' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
const path = require( 'path' );
|
||||||
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||||
|
mode: isProduction ? 'production' : 'development',
|
||||||
|
target: 'web',
|
||||||
|
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||||
|
entry: {
|
||||||
|
'bancontact-payment-method': path.resolve(
|
||||||
|
'./resources/js/bancontact-payment-method.js'
|
||||||
|
),
|
||||||
|
'blik-payment-method': path.resolve(
|
||||||
|
'./resources/js/blik-payment-method.js'
|
||||||
|
),
|
||||||
|
'eps-payment-method': path.resolve(
|
||||||
|
'./resources/js/eps-payment-method.js'
|
||||||
|
),
|
||||||
|
'ideal-payment-method': path.resolve(
|
||||||
|
'./resources/js/ideal-payment-method.js'
|
||||||
|
),
|
||||||
|
'mybank-payment-method': path.resolve(
|
||||||
|
'./resources/js/mybank-payment-method.js'
|
||||||
|
),
|
||||||
|
'p24-payment-method': path.resolve(
|
||||||
|
'./resources/js/p24-payment-method.js'
|
||||||
|
),
|
||||||
|
'trustly-payment-method': path.resolve(
|
||||||
|
'./resources/js/trustly-payment-method.js'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.resolve( __dirname, 'assets/' ),
|
||||||
|
filename: 'js/[name].js',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.js?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel-loader',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.scss$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: 'file-loader',
|
||||||
|
options: {
|
||||||
|
name: 'css/[name].css',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ loader: 'sass-loader' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
2247
modules/ppcp-local-alternative-payment-methods/yarn.lock
Normal file
2247
modules/ppcp-local-alternative-payment-methods/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install",
|
"install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install",
|
||||||
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
||||||
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
||||||
|
"install:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn install",
|
||||||
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
||||||
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
||||||
"install:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn install",
|
"install:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn install",
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
"build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build",
|
"build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build",
|
||||||
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
||||||
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
||||||
|
"build:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn run build",
|
||||||
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
||||||
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
||||||
"build:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run build",
|
"build:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run build",
|
||||||
|
@ -49,6 +51,7 @@
|
||||||
"watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch",
|
"watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch",
|
||||||
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
||||||
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
||||||
|
"watch:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn run watch",
|
||||||
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
||||||
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
||||||
"watch:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run watch",
|
"watch:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run watch",
|
||||||
|
|
49
tests/e2e/PHPUnit/OrdersTest.php
Normal file
49
tests/e2e/PHPUnit/OrdersTest.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Tests\E2e;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||||
|
|
||||||
|
class OrdersTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_create()
|
||||||
|
{
|
||||||
|
$host = 'https://api-m.sandbox.paypal.com';
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$orders = new Orders(
|
||||||
|
$host,
|
||||||
|
$container->get('api.bearer'),
|
||||||
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
|
);
|
||||||
|
|
||||||
|
$requestBody = [
|
||||||
|
"intent" => "CAPTURE",
|
||||||
|
"payment_source" => [
|
||||||
|
"bancontact" => [
|
||||||
|
"country_code" => "BE",
|
||||||
|
"name" => "John Doe"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"processing_instruction" => "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",
|
||||||
|
"purchase_units" => [
|
||||||
|
[
|
||||||
|
"reference_id" => "d9f80740-38f0-11e8-b467-0ed5f89f718b",
|
||||||
|
"amount" => [
|
||||||
|
"currency_code" => "EUR",
|
||||||
|
"value" => "1.00"
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"application_context" => [
|
||||||
|
"locale" => "en-BE",
|
||||||
|
"return_url" => "https://example.com/returnUrl",
|
||||||
|
"cancel_url" => "https://example.com/cancelUrl"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $orders->create($requestBody);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $result['response']['code']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue