Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Aug 17, 2021
2 parents cc60d92 + 7f9cd2a commit 87de8f1
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 87 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased][unreleased]
-

## [2.0.1] - 2021-08-17
- No longer require PHP `intl` extensie.
- Simplified exception handling.

## [2.0.0] - 2021-08-05
- Updated to `pronamic/wp-pay-core` version `3.0.0`.
Expand Down Expand Up @@ -82,7 +87,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 1.0.0 - 2019-03-28
- First release.

[unreleased]: https://github.com/wp-pay-gateways/adyen/compare/2.0.0...HEAD
[unreleased]: https://github.com/wp-pay-gateways/adyen/compare/2.0.1...HEAD
[2.0.1]: https://github.com/wp-pay-gateways/adyen/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/wp-pay-gateways/adyen/compare/1.3.2...2.0.0
[1.3.2]: https://github.com/wp-pay-gateways/adyen/compare/1.3.1...1.3.2
[1.3.1]: https://github.com/wp-pay-gateways/adyen/compare/1.3.0...1.3.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"phpcs": "XDEBUG_MODE=off vendor/bin/phpcs -s -v",
"phplint": "vendor/bin/phplint",
"phpmd": "vendor/bin/phpmd src,tests text phpmd.ruleset.xml --suffixes php",
"phpstan": "vendor/bin/phpstan analyse",
"phpstan": "vendor/bin/phpstan analyse --memory-limit=-1",
"phpunit": "vendor/bin/phpunit",
"post-install-cmd": "echo 'Optionally run: composer bin all install'",
"post-update-cmd": "echo 'Optionally run: composer bin all update'",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adyen",
"version": "2.0.0",
"version": "2.0.1",
"description": "Adyen driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ parameters:
- tests/phpstan/bootstrap.php
paths:
- src/
ignoreErrors:
# Uses func_get_args()
- '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
2 changes: 1 addition & 1 deletion pronamic-pay-adyen.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://www.pronamic.eu/plugins/pronamic-pay-adyen/
* Description: Extend the Pronamic Pay plugin with the Adyen gateway to receive payments with Adyen through a variety of WordPress plugins.
*
* Version: 2.0.0
* Version: 2.0.1
* Requires at least: 4.7
*
* Author: Pronamic
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Tags: pronamic, pay, adyen, add-on
Requires at least: 4.7
Tested up to: 5.1
Requires PHP: 5.3
Stable tag: 2.0.0
Stable tag: 2.0.1

Extend the Pronamic Pay plugin with the Adyen gateway to receive payments with Adyen through a variety of WordPress plugins.
17 changes: 13 additions & 4 deletions src/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
* @link https://github.com/adyenpayments/php/blob/master/generatepaymentform.php
*
* @author Remco Tolsma
* @version 1.0.5
* @version 2.0.1
* @since 1.0.0
*/
abstract class AbstractGateway extends Core_Gateway {
/**
* Config.
*
* @var Config
*/
protected $adyen_config;

/**
* Client.
*
Expand All @@ -37,6 +44,8 @@ abstract class AbstractGateway extends Core_Gateway {
public function __construct( Config $config ) {
parent::__construct( $config );

$this->adyen_config = $config;

$this->set_method( self::METHOD_HTTP_REDIRECT );

// Supported features.
Expand All @@ -56,7 +65,7 @@ public function get_available_payment_methods() {
$core_payment_methods = array();

try {
$payment_methods_response = $this->client->get_payment_methods( new PaymentMethodsRequest( $this->config->get_merchant_account() ) );
$payment_methods_response = $this->client->get_payment_methods( new PaymentMethodsRequest( $this->adyen_config->get_merchant_account() ) );
} catch ( \Exception $e ) {
$this->error = new \WP_Error( 'adyen_error', $e->getMessage() );

Expand Down Expand Up @@ -84,14 +93,14 @@ public function get_available_payment_methods() {
/**
* Get issuers.
*
* @return array<int, array<string, array<string, string>>>
* @return array<string, string>|array<int, array<string, array<string, string>>>
* @see Core_Gateway::get_issuers()
*/
public function get_issuers() {
$issuers = array();

try {
$payment_methods_response = $this->client->get_payment_methods( new PaymentMethodsRequest( $this->config->get_merchant_account() ) );
$payment_methods_response = $this->client->get_payment_methods( new PaymentMethodsRequest( $this->adyen_config->get_merchant_account() ) );
} catch ( \Exception $e ) {
$this->error = new \WP_Error( 'adyen_error', $e->getMessage() );

Expand Down
47 changes: 10 additions & 37 deletions src/DropInGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function payment_redirect( Payment $payment ) {
/**
* Payment methods.
*/
$request = new PaymentMethodsRequest( $this->config->get_merchant_account() );
$request = new PaymentMethodsRequest( $this->adyen_config->get_merchant_account() );

if ( null !== $payment->get_method() ) {
// Payment method type.
Expand All @@ -170,28 +170,15 @@ public function payment_redirect( Payment $payment ) {
}

// Prevent Apple Pay if no merchant identifier has been configured.
$apple_pay_merchant_id = $this->config->get_apple_pay_merchant_id();
$apple_pay_merchant_id = $this->adyen_config->get_apple_pay_merchant_id();

if ( empty( $apple_pay_merchant_id ) ) {
$request->set_blocked_payment_methods( array( PaymentMethodType::APPLE_PAY ) );
}

// Set country code.
$locale = Util::get_payment_locale( $payment );
$request->set_country_code( Util::get_country_code( $payment ) );

$country_code = \Locale::getRegion( $locale );

$billing_address = $payment->get_billing_address();

if ( null !== $billing_address ) {
$country = $billing_address->get_country_code();

if ( null !== $country ) {
$country_code = $country;
}
}

$request->set_country_code( $country_code );
$request->set_amount( AmountTransformer::transform( $payment->get_total_amount() ) );

try {
Expand Down Expand Up @@ -266,7 +253,7 @@ public function payment_redirect( Payment $payment ) {
$configuration = (object) array(
'locale' => Util::get_payment_locale( $payment ),
'environment' => ( self::MODE_TEST === $payment->get_mode() ? 'test' : 'live' ),
'originKey' => $this->config->origin_key,
'originKey' => $this->adyen_config->origin_key,
'paymentMethodsResponse' => $payment_methods->get_original_object(),
'amount' => AmountTransformer::transform( $payment->get_total_amount() )->get_json(),
);
Expand Down Expand Up @@ -430,7 +417,7 @@ public function create_payment( Payment $payment, PaymentMethod $payment_method,
// Payment request.
$payment_request = new PaymentRequest(
$amount,
$this->config->get_merchant_account(),
$this->adyen_config->get_merchant_account(),
(string) $payment->get_id(),
$payment->get_return_url(),
$payment_method
Expand All @@ -448,7 +435,7 @@ public function create_payment( Payment $payment, PaymentMethod $payment_method,
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object.

// Merchant order reference.
$payment_request->set_merchant_order_reference( $payment->format_string( $this->config->get_merchant_order_reference() ) );
$payment_request->set_merchant_order_reference( $payment->format_string( $this->adyen_config->get_merchant_order_reference() ) );

/**
* Application info.
Expand All @@ -472,21 +459,7 @@ public function create_payment( Payment $payment, PaymentMethod $payment_method,
$payment_request->set_application_info( $application_info );

// Set country code.
$locale = Util::get_payment_locale( $payment );

$country_code = \Locale::getRegion( $locale );

$billing_address = $payment->get_billing_address();

if ( null !== $billing_address ) {
$country = $billing_address->get_country_code();

if ( null !== $country ) {
$country_code = $country;
}
}

$payment_request->set_country_code( $country_code );
$payment_request->set_country_code( Util::get_country_code( $payment ) );

// Complement payment request.
PaymentRequestHelper::complement( $payment, $payment_request );
Expand Down Expand Up @@ -543,7 +516,7 @@ public function get_checkout_payment_methods_configuration( $payment_method_type
'currencyCode' => $payment->get_total_amount()->get_currency()->get_alphabetic_code(),
'configuration' => array(
'merchantName' => \get_bloginfo( 'name' ),
'merchantIdentifier' => $this->config->get_apple_pay_merchant_id(),
'merchantIdentifier' => $this->adyen_config->get_apple_pay_merchant_id(),
),
);

Expand Down Expand Up @@ -592,12 +565,12 @@ public function get_checkout_payment_methods_configuration( $payment_method_type
'value' => $payment->get_total_amount()->get_minor_units()->to_int(),
),
'configuration' => array(
'gatewayMerchantId' => $this->config->merchant_account,
'gatewayMerchantId' => $this->adyen_config->merchant_account,
),
);

if ( self::MODE_LIVE === $this->config->mode ) {
$configuration['paywithgoogle']['configuration']['merchantIdentifier'] = $this->config->get_google_pay_merchant_identifier();
$configuration['paywithgoogle']['configuration']['merchantIdentifier'] = $this->adyen_config->get_google_pay_merchant_identifier();
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Integration
*
* @author Remco Tolsma
* @version 1.1.2
* @version 2.0.1
* @since 1.0.0
*/
class Integration extends AbstractGatewayIntegration {
Expand Down Expand Up @@ -56,11 +56,6 @@ public function __construct( $args = array() ) {
);

parent::__construct( $args );

// Dependencies.
$dependencies = $this->get_dependencies();

$dependencies->add( new PhpExtensionDependency( 'intl' ) );
}

/**
Expand Down
32 changes: 31 additions & 1 deletion src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Util
*
* @author Remco Tolsma
* @version 1.0.5
* @version 2.0.1
* @since 1.0.0
*/
class Util {
Expand Down Expand Up @@ -57,4 +57,34 @@ public static function get_payment_locale( Payment $payment ) {

return (string) $locale;
}

/**
* Get country code.
*
* @since 2.0.1
* @param Payment $payment Payment.
* @return string|null
*/
public static function get_country_code( Payment $payment ) {
$country_code = null;

// Billing Address.
$billing_address = $payment->get_billing_address();

if ( null !== $billing_address ) {
$country = $billing_address->get_country_code();

if ( null !== $country ) {
$country_code = $country;
}
}

if ( null === $country_code && \method_exists( '\Locale', 'getRegion' ) ) {
$locale = self::get_payment_locale( $payment );

$country_code = \Locale::getRegion( $locale );
}

return $country_code;
}
}
47 changes: 16 additions & 31 deletions src/WebSdkGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @link https://github.com/adyenpayments/php/blob/master/generatepaymentform.php
*
* @author Remco Tolsma
* @version 1.0.5
* @version 2.0.1
* @since 1.0.0
*/
class WebSdkGateway extends AbstractGateway {
Expand Down Expand Up @@ -78,35 +78,17 @@ public function get_supported_payment_methods() {
*
* @param Payment $payment Payment.
* @return void
* @throws \Exception Throws an exception when the shopper country cannot be determined.
*/
public function start( Payment $payment ) {
// Amount.
try {
$amount = AmountTransformer::transform( $payment->get_total_amount() );
} catch ( InvalidArgumentException $e ) {
$this->error = new WP_Error( 'adyen_error', $e->getMessage() );

return;
}
$amount = AmountTransformer::transform( $payment->get_total_amount() );

// Payment method type.
$payment_method_type = PaymentMethodType::transform( $payment->get_method() );

// Country.
$locale = Util::get_payment_locale( $payment );

$country_code = Locale::getRegion( $locale );

// Set country from billing address.
$billing_address = $payment->get_billing_address();

if ( null !== $billing_address ) {
$country = $billing_address->get_country_code();

if ( ! empty( $country ) ) {
$country_code = $country;
}
}
$country_code = Util::get_country_code( $payment );

/*
* API Integration
Expand All @@ -130,7 +112,7 @@ public function start( Payment $payment ) {
// API integration.
$payment_request = new PaymentRequest(
$amount,
$this->config->get_merchant_account(),
$this->adyen_config->get_merchant_account(),
(string) $payment->get_id(),
$payment->get_return_url(),
new PaymentMethod( (object) $payment_method )
Expand All @@ -140,13 +122,7 @@ public function start( Payment $payment ) {

PaymentRequestHelper::complement( $payment, $payment_request );

try {
$payment_response = $this->client->create_payment( $payment_request );
} catch ( Exception $e ) {
$this->error = new WP_Error( 'adyen_error', $e->getMessage() );

return;
}
$payment_response = $this->client->create_payment( $payment_request );

$payment->set_transaction_id( $payment_response->get_psp_reference() );

Expand All @@ -160,14 +136,23 @@ public function start( Payment $payment ) {
return;
}

/**
* The shopper country is required.
*
* @link https://docs.adyen.com/api-explorer/#/CheckoutService/v67/post/paymentSession__reqParam_countryCode
*/
if ( null === $country_code ) {
throw new \Exception( 'Unable to determine shopper country.' );
}

/**
* SDK Integration
*
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/paymentSession
*/
$payment_session_request = new PaymentSessionRequest(
$amount,
$this->config->get_merchant_account(),
$this->adyen_config->get_merchant_account(),
(string) $payment->get_id(),
$payment->get_return_url(),
$country_code
Expand Down
Loading

0 comments on commit 87de8f1

Please sign in to comment.