Skip to content

Commit

Permalink
Merge branch 'release/4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Apr 11, 2022
2 parents 7c13740 + 2612f69 commit 4967b4c
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 70 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [4.1.0] - 2022-04-11
- No longer catch exception, should be handled downstream.
- No longer use core gateway mode.

## [4.0.0] - 2022-01-11
### Changed
- Updated to https://github.com/pronamic/wp-pay-core/releases/tag/4.0.0.
Expand Down Expand Up @@ -111,7 +115,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [1.0.0] - 2015-01-19
- First release.

[unreleased]: https://github.com/wp-pay-gateways/buckaroo/compare/4.0.0...HEAD
[unreleased]: https://github.com/wp-pay-gateways/buckaroo/compare/4.1.0...HEAD
[4.1.0]: https://github.com/wp-pay-gateways/buckaroo/compare/4.0.0...4.1.0
[4.0.0]: https://github.com/wp-pay-gateways/buckaroo/compare/3.0.2...4.0.0
[3.0.2]: https://github.com/wp-pay-gateways/buckaroo/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/wp-pay-gateways/buckaroo/compare/3.0.0...3.0.1
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": "buckaroo",
"version": "4.0.0",
"version": "4.1.0",
"description": "Buckaroo driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function wp_cli_transaction_status( $args, $assoc_args ) {
foreach ( $args as $transaction_key ) {
$result = $gateway->request( 'GET', 'Transaction/Status/' . $transaction_key );

\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
\WP_CLI::line( (string) \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
}
}

Expand All @@ -96,7 +96,7 @@ public function wp_cli_transaction_refund_info( $args, $assoc_args ) {
foreach ( $args as $transaction_key ) {
$result = $gateway->request( 'GET', 'Transaction/RefundInfo/' . $transaction_key );

\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
\WP_CLI::line( (string) \wp_json_encode( $result, \JSON_PRETTY_PRINT ) );
}
}
}
32 changes: 32 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
* @since 1.0.0
*/
class Config extends GatewayConfig {
/**
* Host.
*
* @var string
*/
private $host;

/**
* Website key.
*
Expand Down Expand Up @@ -43,6 +50,31 @@ class Config extends GatewayConfig {
*/
public $invoice_number;

/**
* Construct config.
*/
public function __construct() {
$this->host = 'checkout.buckaroo.nl';
}

/**
* Get host.
*
* @return string
*/
public function get_host() {
return $this->host;
}

/**
* Set host.
*
* @param string $host Host.
*/
public function set_host( $host ) {
$this->host = $host;
}

/**
* Get website key.
*
Expand Down
153 changes: 90 additions & 63 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
*/
class Gateway extends Core_Gateway {
/**
* Constructs and initializes an Buckaroo gateway
* Config
*
* @var Config
*/
protected $config;

/**
* Constructs and initializes a Buckaroo gateway
*
* @param Config $config Config.
*/
public function __construct( Config $config ) {
parent::__construct( $config );

$this->config = $config;

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

// Supported features.
Expand All @@ -46,6 +55,7 @@ public function __construct( Config $config ) {
*
* @since 1.2.4
* @see Core_Gateway::get_issuers()
* @return array<int|string, array<string, array<string>>>
*/
public function get_issuers() {
$groups = array();
Expand All @@ -56,13 +66,7 @@ public function get_issuers() {
}

// Get iDEAL issuers.
try {
$object = $this->request( 'GET', 'Transaction/Specification/ideal?serviceVersion=2' );
} catch ( \Exception $e ) {
$this->set_error( new WP_Error( 'buckaroo_error', $e->getMessage() ) );

return $groups;
}
$object = $this->request( 'GET', 'Transaction/Specification/ideal?serviceVersion=2' );

if ( \property_exists( $object, 'Actions' ) ) {
foreach ( $object->Actions as $action ) {
Expand Down Expand Up @@ -100,6 +104,7 @@ public function get_issuers() {
* Get supported payment methods
*
* @see Core_Gateway::get_supported_payment_methods()
* @return string[]
*/
public function get_supported_payment_methods() {
return array(
Expand Down Expand Up @@ -502,7 +507,11 @@ public function start( Payment $payment ) {
/**
* Required Action.
*/
if ( null !== $object->RequiredAction ) {
if (
\property_exists( $object, 'RequiredAction' )
&&
null !== $object->RequiredAction
) {
if ( 'Redirect' !== $object->RequiredAction->Name ) {
throw new \Exception(
\sprintf(
Expand Down Expand Up @@ -544,11 +553,7 @@ public function start( Payment $payment ) {
* @return object
*/
public function request( $method, $endpoint, $data = null ) {
$host = 'checkout.buckaroo.nl';

if ( self::MODE_TEST === $this->config->mode ) {
$host = 'testcheckout.buckaroo.nl';
}
$host = $this->config->get_host();

/**
* Authentication.
Expand Down Expand Up @@ -578,7 +583,7 @@ public function request( $method, $endpoint, $data = null ) {
)
);

$hash = \hash_hmac( 'sha256', $values, $this->config->secret_key, true );
$hash = \hash_hmac( 'sha256', $values, (string) $this->config->secret_key, true );

// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$hmac = \base64_encode( $hash );
Expand Down Expand Up @@ -639,7 +644,15 @@ public function update_status( Payment $payment ) {

$result = $this->request( 'GET', 'Transaction/Status/' . $transaction_key );

$payment->set_status( Statuses::transform( \strval( $result->Status->Code->Code ) ) );
if (
\property_exists( $result, 'Status' )
&&
\property_exists( $result->Status, 'Code' )
&&
\property_exists( $result->Status->Code, 'Code' )
) {
$payment->set_status( Statuses::transform( \strval( $result->Status->Code->Code ) ) );
}

/**
* Consumer bank details.
Expand All @@ -655,52 +668,54 @@ public function update_status( Payment $payment ) {
/**
* Services.
*/
foreach ( $result->Services as $service ) {
foreach ( $service->Parameters as $parameter ) {
if ( 'consumerName' === $parameter->Name ) {
$consumer_bank_details->set_name( $parameter->Value );
}
if ( \property_exists( $result, 'Services' ) ) {
foreach ( $result->Services as $service ) {
foreach ( $service->Parameters as $parameter ) {
if ( 'consumerName' === $parameter->Name ) {
$consumer_bank_details->set_name( $parameter->Value );
}

if ( \in_array(
$parameter->Name,
array(
/**
* Payment method iDEAL.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/ideal
*/
'consumerIBAN',
/**
* Payment method Sofort.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/sofort
*/
'CustomerIBAN',
),
true
) ) {
$consumer_bank_details->set_iban( $parameter->Value );
}
if ( \in_array(
$parameter->Name,
array(
/**
* Payment method iDEAL.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/ideal
*/
'consumerIBAN',
/**
* Payment method Sofort.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/sofort
*/
'CustomerIBAN',
),
true
) ) {
$consumer_bank_details->set_iban( $parameter->Value );
}

if ( \in_array(
$parameter->Name,
array(
/**
* Payment method iDEAL.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/ideal
*/
'consumerName',
/**
* Payment method Sofort.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/sofort
*/
'CustomerBIC',
),
true
) ) {
$consumer_bank_details->set_bic( $parameter->Value );
if ( \in_array(
$parameter->Name,
array(
/**
* Payment method iDEAL.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/ideal
*/
'consumerName',
/**
* Payment method Sofort.
*
* @link https://dev.buckaroo.nl/PaymentMethods/Description/sofort
*/
'CustomerBIC',
),
true
) ) {
$consumer_bank_details->set_bic( $parameter->Value );
}
}
}
}
Expand All @@ -712,7 +727,13 @@ public function update_status( Payment $payment ) {
*/
$result = $this->request( 'GET', 'Transaction/RefundInfo/' . $transaction_key );

if ( \property_exists( $result, 'RefundedAmount' ) && ! empty( $result->RefundedAmount ) ) {
if (
\property_exists( $result, 'RefundedAmount' )
&&
\property_exists( $result, 'RefundCurrency' )
&&
! empty( $result->RefundedAmount )
) {
$refunded_amount = new Money( $result->RefundedAmount, $result->RefundCurrency );

$payment->set_refunded_amount( $refunded_amount );
Expand Down Expand Up @@ -775,7 +796,7 @@ public function create_refund( $transaction_id, Money $amount, $description = nu
*
* @link https://dev.buckaroo.nl/Apis
*/
'AmountCredit' => $amount->format( null, '.', '' ),
'AmountCredit' => $amount->number_format( null, '.', '' ),
'Invoice' => $invoice,
'OriginalTransactionKey' => $transaction_id,
'Services' => array(
Expand Down Expand Up @@ -816,7 +837,13 @@ public function create_refund( $transaction_id, Money $amount, $description = nu
if ( null !== $payment ) {
$result = $this->request( 'GET', 'Transaction/RefundInfo/' . $transaction_id );

if ( \property_exists( $result, 'RefundedAmount' ) && ! empty( $result->RefundedAmount ) ) {
if (
\property_exists( $result, 'RefundedAmount' )
&&
\property_exists( $result, 'RefundCurrency' )
&&
! empty( $result->RefundedAmount )
) {
$refunded_amount = new Money( $result->RefundedAmount, $result->RefundCurrency );

$payment->set_refunded_amount( $refunded_amount );
Expand Down
21 changes: 18 additions & 3 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ class Integration extends AbstractGatewayIntegration {
*/
const REST_ROUTE_NAMESPACE = 'pronamic-pay/buckaroo/v1';

/**
* Host.
*
* @var string
*/
private $host;

/**
* Construct Buckaroo integration.
*
* @param array $args Arguments.
* @param array<string, array<string>> $args Arguments.
*/
public function __construct( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'id' => 'buckaroo',
'name' => 'Buckaroo',
'host' => 'checkout.buckaroo.nl',
'url' => 'https://plaza.buckaroo.nl/',
'product_url' => \__( 'http://www.buckaroo-payments.com', 'pronamic_ideal' ),
'dashboard_url' => 'https://plaza.buckaroo.nl/',
Expand All @@ -50,6 +58,8 @@ public function __construct( $args = array() ) {

parent::__construct( $args );

$this->host = $args['host'];

/**
* CLI.
*
Expand Down Expand Up @@ -181,11 +191,12 @@ public function get_settings_fields() {
public function get_config( $post_id ) {
$config = new Config();

$config->set_host( $this->host );

$config->website_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true );
$config->secret_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true );
$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true );
$config->invoice_number = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true );
$config->mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true );

return $config;
}
Expand All @@ -197,6 +208,10 @@ public function get_config( $post_id ) {
* @return Gateway
*/
public function get_gateway( $post_id ) {
return new Gateway( $this->get_config( $post_id ) );
$gateway = new Gateway( $this->get_config( $post_id ) );

$gateway->set_mode( $this->get_mode() );

return $gateway;
}
}

0 comments on commit 4967b4c

Please sign in to comment.