Skip to content

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Aug 24, 2021
2 parents a0c04ac + 9417bb8 commit 4f3f770
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 89 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [3.0.1] - 2021-08-24
- Fixed "Fatal error: Uncaught Error: Call to undefined method Pronamic\WordPress\Money\Money::get_including_tax()".

## [3.0.0] - 2021-08-05
- Updated to `pronamic/wp-pay-core` version `3.0.0`.
- Updated to `pronamic/wp-money` version `2.0.0`.
Expand Down Expand Up @@ -90,7 +93,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0 - 2014-12-15
- First release.

[unreleased]: https://github.com/wp-pay-gateways/pay-nl/compare/3.0.0...HEAD
[unreleased]: https://github.com/wp-pay-gateways/pay-nl/compare/3.0.1...HEAD
[3.0.1]: https://github.com/wp-pay-gateways/pay-nl/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/wp-pay-gateways/pay-nl/compare/2.1.2...3.0.0
[2.1.2]: https://github.com/wp-pay-gateways/pay-nl/compare/2.1.1...2.1.2
[2.1.1]: https://github.com/wp-pay-gateways/pay-nl/compare/2.1.0...2.1.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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": "pay-nl",
"version": "3.0.0",
"version": "3.0.1",
"description": "Pay.nl driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
163 changes: 90 additions & 73 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Company: Pronamic
*
* @author Remco Tolsma
* @version 2.0.4
* @version 3.0.1
* @since 1.0.0
*/
class Gateway extends Core_Gateway {
Expand Down Expand Up @@ -101,79 +101,130 @@ public function get_supported_payment_methods() {
public function start( Payment $payment ) {
$payment_method = $payment->get_method();

/*
* New transaction request.
* @link https://www.pay.nl/docs/developers.php#transactions
$customer = $payment->get_customer();

/**
* End user.
*/
$customer = $payment->get_customer();
$billing_address = $payment->get_billing_address();
$shipping_address = $payment->get_shipping_address();
$end_user = array();

// Payment lines.
$order_data = array();
if ( null !== $customer ) {
$end_user['gender'] = $customer->get_gender();
$end_user['phoneNumber'] = $customer->get_phone();
$end_user['emailAddress'] = $customer->get_email();
$end_user['language'] = $customer->get_language();

if ( null !== $payment->get_lines() ) {
foreach ( $payment->get_lines() as $line ) {
$price = null;
/**
* Name.
*/
$name = $customer->get_name();

if ( null !== $line->get_unit_price() ) {
$price = $line->get_unit_price()->get_including_tax()->get_minor_units()->to_int();
}
if ( null !== $name ) {
$end_user['initials'] = \substr( (string) $name->get_first_name(), 0, 32 );
$end_user['lastName'] = \substr( (string) $name->get_last_name(), 0, 32 );
}

$order_data[] = array(
'productId' => $line->get_id(),
'productType' => ProductTypes::transform( $line->get_type() ),
'description' => $line->get_name(),
'price' => $price,
'quantity' => $line->get_quantity(),
);
/**
* Date of Birth.
*/
$birth_date = $customer->get_birth_date();

if ( $birth_date instanceof \DateTimeInterface ) {
$end_user['dob'] = $birth_date->format( 'dmY' );
}
}

// End user.
$end_user = array();
/**
* End user - Address.
*/
$shipping_address = $payment->get_shipping_address();

// End user - Address.
if ( null !== $shipping_address ) {
$end_user['address'] = array(
$address = array(
'streetName' => $shipping_address->get_street_name(),
'streetNumber' => $shipping_address->get_house_number_base(),
'streetNumberExtension' => $shipping_address->get_house_number_addition(),
'zipCode' => $shipping_address->get_postal_code(),
'city' => $shipping_address->get_city(),
'countryCode' => $shipping_address->get_country_code(),
);

$end_user['address'] = $address;
}

// End user - Invoice address.
/**
* End user - Invoice address.
*/
$billing_address = $payment->get_billing_address();

if ( null !== $billing_address ) {
$end_user['invoiceAddress'] = array(
$address = array(
'streetName' => $billing_address->get_street_name(),
'streetNumber' => $billing_address->get_house_number_base(),
'streetNumberExtension' => $billing_address->get_house_number_addition(),
'zipCode' => $billing_address->get_postal_code(),
'city' => $billing_address->get_city(),
'countryCode' => $billing_address->get_country_code(),
);

if ( \array_key_exists( 'gender', $end_user ) ) {
$address['gender'] = $end_user['gender'];
}

if ( \array_key_exists( 'initials', $end_user ) ) {
$address['initials'] = $end_user['initials'];
}

if ( \array_key_exists( 'lastName', $end_user ) ) {
$address['lastName'] = $end_user['lastName'];
}

$end_user['invoiceAddress'] = $address;
}

/**
* Sale data.
*/
$sale_data = array(
'invoiceDate' => $payment->get_date()->format( 'd-m-Y' ),
'deliveryDate' => $payment->get_date()->format( 'd-m-Y' ),
);

$payment_lines = $payment->get_lines();

if ( null !== $payment_lines ) {
$sale_data['order_data'] = array();

foreach ( $payment_lines as $line ) {
$order_data_item = array(
'productId' => $line->get_id(),
'productType' => ProductTypes::transform( $line->get_type() ),
'description' => $line->get_name(),
'quantity' => $line->get_quantity(),
);

$unit_price = $line->get_unit_price();

if ( null !== $unit_price ) {
$order_data_item['price'] = $unit_price->get_minor_units()->to_int();
}

$sale_data['order_data'][] = $order_data_item;
}
}

// Request.
/**
* Request.
*
* @link https://docs.pay.nl/developers?language=nl#transaction-process
*/
$request = array(
// Transaction.
'transaction' => array(
'currency' => $payment->get_total_amount()->get_currency()->get_alphabetic_code(),
'description' => $payment->get_description(),
),

// End user.
'enduser' => $end_user,

// Sale data.
'saleData' => array(
'invoiceDate' => $payment->get_date()->format( 'd-m-Y' ),
'deliveryDate' => $payment->get_date()->format( 'd-m-Y' ),
'orderData' => $order_data,
),
'saleData' => $sale_data,
);

// Payment method.
Expand All @@ -183,40 +234,6 @@ public function start( Payment $payment ) {
$request['paymentOptionId'] = $method;
}

if ( null !== $payment->get_customer() ) {
$enduser = array(
'gender' => $customer->get_gender(),
'phoneNumber' => $customer->get_phone(),
'emailAddress' => $customer->get_email(),
'language' => $customer->get_language(),
);

$invoice_address = array(
'gender' => $customer->get_gender(),
);

// Set name from customer.
if ( null !== $customer->get_name() ) {
$first_name = \substr( (string) $customer->get_name()->get_first_name(), 0, 32 );
$last_name = \substr( (string) $customer->get_name()->get_last_name(), 0, 32 );

$enduser['initials'] = $first_name;
$enduser['lastName'] = $last_name;

$invoice_address['initials'] = $first_name;
$invoice_address['lastName'] = $last_name;
}

// Set date of birth.
if ( $customer->get_birth_date() instanceof \DateTime ) {
$enduser['dob'] = $customer->get_birth_date()->format( 'dmY' );
}

$request['enduser'] = array_merge( $request['enduser'], $enduser );

$request['enduser']['invoiceAddress'] = array_merge( $request['enduser']['invoiceAddress'], $invoice_address );
}

// Check payment method.
if ( null === $request['paymentOptionId'] && ! empty( $payment_method ) ) {
// Leap of faith if the WordPress payment method could not transform to a Pay.nl method?
Expand Down
12 changes: 6 additions & 6 deletions vendor-bin/phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions vendor-bin/psalm/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f3f770

Please sign in to comment.