Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Aug 5, 2021
2 parents 273b5a6 + 02365ce commit 94b44ea
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 277 deletions.
41 changes: 26 additions & 15 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run

coverage:
tests:
override:
- command: ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
coverage:
file: build/logs/clover.xml
format: clover

environment:
php: 7.3.0
variables:
WP_TESTS_DB_NAME: 'wp_phpunit_tests'
WP_TESTS_DB_USER: 'root'
WP_TESTS_DB_PASS: ''
WP_TESTS_DB_HOST: 'localhost'
project_setup:
before:
- mysql -e "CREATE DATABASE wp_phpunit_tests"
WP_TESTS_DB_HOST: '127.0.0.1'

services:
mysql: 5.7

dependencies:
override:
- composer install --ignore-platform-reqs --no-interaction
nodes:
coverage:
tests:
override:
- command: ./vendor/bin/phpunit
coverage:
file: build/logs/clover.xml
format: clover

project_setup:
before:
- mysql -e "CREATE DATABASE wp_phpunit_tests"

checks:
php:
Expand All @@ -28,6 +39,9 @@ checks:
code_rating: true
duplication: true

build_failure_conditions:
- 'issues.label("bug").exists'

coding_style:
php:
indentation:
Expand All @@ -50,6 +64,3 @@ coding_style:
switch: true
catch: true
type_cast: false

build_failure_conditions:
- 'issues.label("bug").exists'
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## [Unreleased][unreleased]
-

## [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`.
- Switched to `pronamic/wp-coding-standards`.

## [2.1.1] - 2021-04-26
- Happy 2021.

Expand Down Expand Up @@ -101,7 +106,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0 - 2014-12-12
- First release.

[unreleased]: https://github.com/wp-pay-gateways/sisow/compare/2.1.1...HEAD
[unreleased]: https://github.com/wp-pay-gateways/sisow/compare/3.0.0...HEAD
[3.0.0]: https://github.com/wp-pay-gateways/sisow/compare/3.0.0...3.0.0
[2.1.1]: https://github.com/wp-pay-gateways/sisow/compare/2.1.0...2.1.1
[2.1.0]: https://github.com/wp-pay-gateways/sisow/compare/2.0.4...2.1.0
[2.0.4]: https://github.com/wp-pay-gateways/sisow/compare/2.0.3...2.0.4
Expand Down
16 changes: 6 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,24 @@
"sort-packages": true
},
"require": {
"ext-simplexml": "*",
"php": ">=5.6.20",
"wp-pay/core": "^2.6"
"ext-simplexml": "*",
"wp-pay/core": "^3.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"overtrue/phplint": "^1.2",
"php-coveralls/php-coveralls": "^2.4",
"phpcompatibility/php-compatibility": "^9.2",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpmd/phpmd": "^2.7",
"phpunit/phpunit": "^5.7 || ^6.0",
"roots/wordpress": "^5.6",
"squizlabs/php_codesniffer": "^3.4",
"wp-coding-standards/wpcs": "^2.3",
"wp-phpunit/wp-phpunit": "^5.6"
"pronamic/wp-coding-standards": "^1.0",
"roots/wordpress": "^5.8",
"wp-phpunit/wp-phpunit": "^5.8"
},
"scripts": {
"coveralls": "vendor/bin/php-coveralls -v",
"phpcbf": "vendor/bin/phpcbf",
"phpcs": "vendor/bin/phpcs -s -v",
"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",
Expand Down
Binary file added documentation/rest540-en.pdf
Binary file not shown.
Binary file added documentation/rest540.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sisow",
"version": "2.1.1",
"version": "3.0.0",
"description": "Sisow driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
19 changes: 2 additions & 17 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
<?xml version="1.0"?>

<ruleset name="WordPress Pay Sisow rules">
<config name="minimum_supported_wp_version" value="4.7" />

<config name="testVersion" value="5.6-" />

<file>.</file>

<arg name="colors"/>
<arg name="extensions" value="php" />
<arg value="sp" />

<exclude-pattern>node_modules/*</exclude-pattern>
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
<exclude-pattern>tests/wp-config.php</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>wordpress/*</exclude-pattern>
<exclude-pattern type="relative">^wp-content/*</exclude-pattern>

<rule ref="PHPCompatibilityWP" />

<rule ref="WordPress">
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<rule ref="PronamicWP">
<exclude name="WordPressVIPMinimum.Security.PHPFilterFunctions.MissingThirdParameter" />
</rule>

<rule ref="WordPress.DB.SlowDBQuery.slow_db_query_meta_key">
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

<php>
<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/wp-config.php" />
</php>
Expand Down
66 changes: 42 additions & 24 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Pronamic\WordPress\Pay\Gateways\Sisow;

use Pronamic\WordPress\Money\Money;
use Pronamic\WordPress\Money\TaxedMoney;
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
use Pronamic\WordPress\Pay\Core\PaymentMethods;
use Pronamic\WordPress\Pay\Core\Util as Core_Util;
Expand Down Expand Up @@ -140,7 +142,7 @@ public function get_available_payment_methods() {
/**
* Get supported payment methods
*
* @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
* @see Core_Gateway::get_supported_payment_methods()
* @return array<int,string>
*/
public function get_supported_payment_methods() {
Expand Down Expand Up @@ -173,6 +175,16 @@ public function payment_method_is_required() {
return true;
}

/**
* Format amount.
*
* @param Money $amount Money.
* @return string
*/
private function format_amount( Money $amount ) {
return $amount->get_minor_units()->format( 0, '', '' );
}

/**
* Start
*
Expand Down Expand Up @@ -201,7 +213,7 @@ public function start( Payment $payment ) {
'payment' => Methods::transform( $payment->get_method(), $payment->get_method() ),
'purchaseid' => substr( $purchase_id, 0, 16 ),
'entrancecode' => $payment->get_entrance_code(),
'amount' => $payment->get_total_amount()->get_minor_units(),
'amount' => $this->format_amount( $payment->get_total_amount() ),
'description' => substr( (string) $payment->get_description(), 0, 32 ),
'testmode' => ( self::MODE_TEST === $this->config->mode ) ? 'true' : 'false',
'returnurl' => $payment->get_return_url(),
Expand Down Expand Up @@ -324,52 +336,58 @@ public function start( Payment $payment ) {
$x = 1;

foreach ( $lines as $line ) {
// Product ID.
$product_id = $line->get_id();
// Product type.
$product_type = 'physical';

switch ( $line->get_type() ) {
case PaymentLineType::SHIPPING:
$product_id = 'shipping';
$product_type = 'shipping_fee';

break;
case PaymentLineType::DISCOUNT:
$product_type = 'discount';

break;
case PaymentLineType::DIGITAL:
case PaymentLineType::FEE:
$product_id = 'paymentfee';
$product_id = 'digital';

break;
case PaymentLineType::PHYSICAL:
$product_id = 'physical';

break;
}

// Price.
$net_price = null;
$request->set_parameter( 'product_id_' . $x, $line->get_id() );
$request->set_parameter( 'product_description_' . $x, $line->get_name() );
$request->set_parameter( 'product_quantity_' . $x, $line->get_quantity() );
$request->set_parameter( 'product_type_' . $x, $product_type );

$unit_price = $line->get_unit_price();

if ( null !== $unit_price ) {
$net_price = $unit_price->get_excluding_tax()->get_minor_units();
$request->set_parameter( 'product_netprice_' . $x, $unit_price instanceof TaxedMoney ? $unit_price->get_excluding_tax() : $unit_price );
}

// Request parameters.
$request->merge_parameters(
array(
'product_id_' . $x => $product_id,
'product_description_' . $x => $line->get_name(),
'product_quantity_' . $x => $line->get_quantity(),
'product_netprice_' . $x => $net_price,
'product_total_' . $x => $line->get_total_amount()->get_including_tax()->get_minor_units(),
'product_nettotal_' . $x => $line->get_total_amount()->get_excluding_tax()->get_minor_units(),
)
);
$total_amount = $line->get_total_amount();

$request->set_parameter( 'product_total_' . $x, $total_amount instanceof TaxedMoney ? $total_amount->get_including_tax() : $total_amount );
$request->set_parameter( 'product_nettotal_' . $x, $total_amount instanceof TaxedMoney ? $total_amount->get_excluding_tax() : $total_amount );

// Tax request parameters.
$tax_amount = $line->get_tax_amount();

if ( null !== $tax_amount ) {
$request->set_parameter( 'product_tax_' . $x, $tax_amount->get_minor_units() );
$request->set_parameter( 'product_tax_' . $x, $this->format_amount( $tax_amount ) );
}

$tax_percentage = $line->get_total_amount()->get_tax_percentage();
if ( $total_amount instanceof TaxedMoney ) {
$tax_percentage = $total_amount->get_tax_percentage();

if ( null !== $tax_percentage ) {
$request->set_parameter( 'product_taxrate_' . $x, strval( $tax_percentage * 100 ) );
if ( null !== $tax_percentage ) {
$request->set_parameter( 'product_taxrate_' . $x, strval( $tax_percentage * 100 ) );
}
}

$x++;
Expand Down
Loading

0 comments on commit 94b44ea

Please sign in to comment.