Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Sep 26, 2022
2 parents 08e0f9c + 4d3c775 commit 6518342
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 99 deletions.
14 changes: 14 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"core": null,
"plugins": [
".",
"../../../",
"pronamic/wp-pronamic-pay-test-helper",
"https://downloads.wordpress.org/plugin/pronamic-client.zip",
"https://downloads.wordpress.org/plugin/query-monitor.zip",
"https://downloads.wordpress.org/plugin/one-time-login.zip"
],
"config": {
"PRONAMIC_PAY_DEBUG": true
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased][unreleased]

## [2.2.0] - 2022-09-26
- Updated payment methods registration.

## [2.1.0] - 2022-04-11
- No longer use global core mode.

Expand All @@ -22,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.0.0] - 2021-08-05
- First release.

[unreleased]: https://github.com/wp-pay-gateways/paypal/compare/2.1.0...HEAD
[unreleased]: https://github.com/wp-pay-gateways/paypal/compare/2.2.0...HEAD
[2.2.0]: https://github.com/pronamic/wp-pronamic-pay-paypal/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/wp-pay-gateways/paypal/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/wp-pay-gateways/paypal/compare/1.0.2...2.0.0
[1.0.2]: https://github.com/wp-pay-gateways/paypal/compare/1.0.1...1.0.2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@psalm"
],
"coveralls": "vendor/bin/php-coveralls -v",
"phpcbf": "vendor/bin/phpcbf",
"phpcbf": "XDEBUG_MODE=off vendor/bin/phpcbf",
"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",
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paypal",
"version": "2.1.0",
"version": "2.2.0",
"description": "PayPal driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,10 +36,18 @@
"eslint": "eslint . --ext .json --ext .js"
},
"devDependencies": {
"@wordpress/env": "^5.2.0",
"@babel/cli": "^7.12.8",
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"eslint": "^7.14.0",
"eslint-plugin-json": "^2.1.2"
"eslint-plugin-json": "^2.1.2",
"npm-run-all": "^4.1.5"
},
"scripts": {
"start": "wp-env start && npm run setup && npm run login",
"setup": "npm-run-all setup-*",
"setup-mollie": "wp-env run cli wp config set PRONAMIC_PAY_PAYPAL_EMAIL $PRONAMIC_PAY_PAYPAL_EMAIL",
"login": "wp-env run cli wp user one-time-login admin"
}
}
7 changes: 6 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
<exclude-pattern>tests/wp-config.php</exclude-pattern>

<rule ref="PronamicWP" />
<rule ref="PronamicWP">
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
</rule>

<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
<exclude name="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace.SpaceAfterArrayOpen" />
<exclude name="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace.SpaceBeforeArrayClose" />

<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes" />

<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility.MissingConstantVisibility" />
Expand Down
8 changes: 4 additions & 4 deletions pronamic-pay-paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@
'pronamic_pay_gateways',
function( $gateways ) {
$gateways[] = new \Pronamic\WordPress\Pay\Gateways\PayPal\Integration(
array(
[
'id' => 'paypal',
'name' => 'PayPal',
'mode' => 'live',
'webscr_url' => 'https://www.paypal.com/cgi-bin/webscr',
'ipn_pb_url' => 'https://ipnpb.paypal.com/cgi-bin/webscr',
)
]
);

$gateways[] = new \Pronamic\WordPress\Pay\Gateways\PayPal\Integration(
array(
[
'id' => 'paypal-sandbox',
'name' => 'PayPal - Sandbox',
'mode' => 'test',
'webscr_url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
'ipn_pb_url' => 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr',
)
]
);

return $gateways;
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function get_email() {
* @return object
*/
public function jsonSerialize() {
return (object) array(
return (object) [
'email' => $this->email,
);
];
}
}
66 changes: 38 additions & 28 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Pronamic\WordPress\Money\Money;
use Pronamic\WordPress\Money\TaxedMoney;
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
use Pronamic\WordPress\Pay\Core\PaymentMethod;
use Pronamic\WordPress\Pay\Core\PaymentMethods;
use Pronamic\WordPress\Pay\Payments\Payment;

Expand All @@ -29,7 +30,7 @@ class Gateway extends Core_Gateway {
*
* @var Config
*/
protected $paypal_config;
protected $config;

/**
* Client.
Expand All @@ -44,41 +45,25 @@ class Gateway extends Core_Gateway {
* @param Config $config Config.
*/
public function __construct( Config $config ) {
parent::__construct( $config );
parent::__construct();

$this->paypal_config = $config;
$this->config = $config;

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

// Supported features.
$this->supports = array(
$this->supports = [
'payment_status_request',
);
];

// Client.
$this->client = new Client( $config );
}

/**
* Get supported payment methods
*
* @see Core_Gateway::get_supported_payment_methods()
* @return array<string>
*/
public function get_supported_payment_methods() {
return array(
PaymentMethods::PAYPAL,
);
}
// Methods.
$payment_method_paypal = new PaymentMethod( PaymentMethods::PAYPAL );
$payment_method_paypal->set_status( 'active' );

/**
* Is payment method required to start transaction?
*
* @see Core_Gateway::payment_method_is_required()
* @return true
*/
public function payment_method_is_required() {
return true;
$this->register_payment_method( $payment_method_paypal );
}

/**
Expand All @@ -87,20 +72,45 @@ public function payment_method_is_required() {
* @param Payment $payment Payment.
* @return void
* @throws \InvalidArgumentException Throws exception if payment ID or currency is empty.
* @throws \Exception Throws exception Throws exception on unsupported payment method.
* @see Plugin::start()
*/
public function start( Payment $payment ) {
/**
* If the payment method of the payment is unknown (`null`), we will turn it into
* an PayPal payment.
*/
$payment_method = $payment->get_payment_method();

if ( null === $payment_method ) {
$payment->set_payment_method( PaymentMethods::PAYPAL );
}

/**
* This gateway can only process payments for the payment method PayPal.
*/
$payment_method = $payment->get_payment_method();

if ( PaymentMethods::PAYPAL !== $payment_method ) {
throw new \Exception(
\sprintf(
'The PayPal cannot process `%s` payments, only PayPal payments.',
$payment_method
)
);
}

/**
* HTML Variables for PayPal Payments Standard
*
* @link https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/Appx-websitestandard-htmlvariables/
* @link https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.9.26/includes/gateways/paypal-standard.php
*/
$url = $this->paypal_config->get_webscr_url();
$url = $this->config->get_webscr_url();

$variables = new Variables();

$variables->set_business( $this->paypal_config->get_email() );
$variables->set_business( $this->config->get_email() );
$variables->set_cmd( '_cart' );
$variables->set_upload( true );

Expand Down Expand Up @@ -272,7 +282,7 @@ private function format_amount( Money $amount ) {
* @return array<string, string>
*/
private function get_shopping_cart_variables( Payment $payment ) {
$variables = array();
$variables = [];

$lines = $payment->get_lines();

Expand Down
20 changes: 10 additions & 10 deletions src/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class Integration extends AbstractGatewayIntegration {
*
* @param array<string, array<string>> $args Arguments.
*/
public function __construct( $args = array() ) {
public function __construct( $args = [] ) {
$args = \wp_parse_args(
$args,
array(
[
'id' => 'paypal',
'name' => 'PayPal',
'mode' => 'live',
Expand All @@ -64,8 +64,8 @@ public function __construct( $args = array() ) {
'https://www.pronamic.eu/manuals/using-paypal-pronamic-pay/',
'pronamic_ideal'
),
'supports' => array(),
)
'supports' => [],
]
);

parent::__construct( $args );
Expand All @@ -80,12 +80,12 @@ public function __construct( $args = array() ) {
public function setup() {
\add_filter(
'pronamic_gateway_configuration_display_value_' . $this->get_id(),
array( $this, 'gateway_configuration_display_value' ),
[ $this, 'gateway_configuration_display_value' ],
10,
2
);

\add_filter( 'pronamic_payment_provider_url_paypal', array( $this, 'payment_provider_url' ), 10, 2 );
\add_filter( 'pronamic_payment_provider_url_paypal', [ $this, 'payment_provider_url' ], 10, 2 );

// Notifications controller.
$notifications_controller = new NotificationsController( $this );
Expand Down Expand Up @@ -129,18 +129,18 @@ public function payment_provider_url( $url, Payment $payment ) {
* @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
*/
public function get_settings_fields() {
$fields = array();
$fields = [];

// Business Id.
$fields[] = array(
$fields[] = [
'section' => 'general',
'filter' => \FILTER_SANITIZE_STRING,
'meta_key' => '_pronamic_gateway_paypal_email',
'title' => \_x( 'Email', 'paypal', 'pronamic_ideal' ),
'type' => 'text',
'classes' => array( 'regular-text', 'code' ),
'classes' => [ 'regular-text', 'code' ],
'tooltip' => \__( 'Enter your PayPal account\'s email.', 'pronamic_ideal' ),
);
];

// Return fields.
return $fields;
Expand Down
Loading

0 comments on commit 6518342

Please sign in to comment.