Skip to content

Commit

Permalink
Merge branch 'release/2.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed May 11, 2021
2 parents 33f7a22 + 193dc57 commit 8887d0c
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 184 deletions.
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]
-

## [2.3.1] - 2021-05-11
- Use default gateway configuration setting.
- Reduced magic in MemberPress payment address transformation function.
- Improved tax calculation of payment from MemberPress subscription in trial (coupon code).

## [2.3.0] - 2021-04-26
- Added support for single-page checkout.

Expand Down Expand Up @@ -119,7 +124,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
## 1.0.0 - 2016-02-01
- First release.

[unreleased]: https://github.com/wp-pay-extensions/memberpress/compare/2.3.0...HEAD
[unreleased]: https://github.com/wp-pay-extensions/memberpress/compare/2.3.1...HEAD
[2.3.1]: https://github.com/wp-pay-extensions/memberpress/compare/2.3.0...2.3.1
[2.3.0]: https://github.com/wp-pay-extensions/memberpress/compare/2.2.3...2.3.0
[2.2.3]: https://github.com/wp-pay-extensions/memberpress/compare/2.2.2...2.2.3
[2.2.2]: https://github.com/wp-pay-extensions/memberpress/compare/2.2.1...2.2.2
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": "memberpress",
"version": "2.3.0",
"version": "2.3.1",
"description": "MemberPress driver for the WordPress payment processing library.",
"repository": {
"type": "git",
Expand Down
87 changes: 64 additions & 23 deletions src/Gateways/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* WordPress pay MemberPress gateway
*
* @author Remco Tolsma
* @version 2.2.3
* @version 2.3.1
* @since 1.0.0
*/
class Gateway extends MeprBaseRealGateway {
Expand Down Expand Up @@ -676,21 +676,21 @@ public function process_signup_form( $txn ) {
* @since 1.0.2
*/
public function payment_redirect( $txn ) {
$txn = new MeprTransaction( $txn->id );

// Gateway.
$config_id = $this->settings->config_id;
$config_id = $this->get_config_id();

$gateway = Plugin::get_gateway( $config_id );

if ( ! $gateway ) {
if ( null === $gateway ) {
return;
}

// Create Pronamic payment.
$txn = new MeprTransaction( $txn->id );

$payment = Pronamic::get_payment( $txn );

$payment->config_id = $this->settings->config_id;
$payment->config_id = $config_id;
$payment->method = $this->payment_method;

$error = null;
Expand Down Expand Up @@ -742,15 +742,15 @@ public function payment_redirect( $txn ) {
*/
public function display_payment_page( $txn ) {
// Gateway.
$config_id = $this->settings->config_id;
$config_id = $this->get_config_id();

$gateway = Plugin::get_gateway( $config_id );

// Check gateway.
if ( null === $gateway ) {
return;
}

// Redirect payment on empty input HTML.
$gateway->set_payment_method( $this->payment_method );

$html = $gateway->get_input_html();
Expand All @@ -774,13 +774,16 @@ public function display_payment_page( $txn ) {
*/
public function process_payment_form( $txn ) {
// Gateway.
$config_id = $this->settings->config_id;
$config_id = $this->get_config_id();

$gateway = Plugin::get_gateway( $config_id );

if ( $gateway ) {
$this->payment_redirect( $txn );
if ( null === $gateway ) {
return;
}

// Redirect.
$this->payment_redirect( $txn );
}

/**
Expand Down Expand Up @@ -808,6 +811,29 @@ public function enqueue_payment_form_scripts() {
* @param int $txn_id Transaction ID.
*/
public function display_payment_form( $amount, $user, $product_id, $txn_id ) {
// Gateway.
$config_id = $this->get_config_id();

$gateway = Plugin::get_gateway( $config_id );

if ( null === $gateway ) {

$admin_message = null;

if ( \current_user_can( 'manage_options' ) ) {
$admin_message = __( 'For admins only: check payment method settings in MemberPress.', 'pronamic_ideal' );
}

printf(
'<div class="mp_wrapper mp_payment_form_wrapper"><ul><li>%s</li>%s</ul></div>',
\esc_html( Plugin::get_default_error_message() ),
null === $admin_message ? '' : sprintf( '<li><em>%s</em></li>', \esc_html( $admin_message ) )
);

return;
}

// Invoice.
$product = new MeprProduct( $product_id );

$coupon = false;
Expand Down Expand Up @@ -836,17 +862,10 @@ public function display_payment_form( $amount, $user, $product_id, $txn_id ) {

<?php

// Gateway.
$config_id = $this->settings->config_id;

$gateway = Plugin::get_gateway( $config_id );

if ( null !== $gateway ) {
$gateway->set_payment_method( $this->payment_method );
$gateway->set_payment_method( $this->payment_method );

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $gateway->get_input_html();
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $gateway->get_input_html();

?>

Expand All @@ -873,15 +892,15 @@ public function display_payment_form( $amount, $user, $product_id, $txn_id ) {
*/
public function spc_payment_fields() {
// Gateway.
$config_id = $this->settings->config_id;
$config_id = $this->get_config_id();

$gateway = Plugin::get_gateway( $config_id );

// Check gateway.
if ( null === $gateway ) {
return '';
}

// Input HTML.
$gateway->set_payment_method( $this->payment_method );

$html = $gateway->get_input_html();
Expand Down Expand Up @@ -1038,4 +1057,26 @@ public function is_test_mode() {
public function force_ssl() {
return false;
}

/**
* Get config ID.
*
* @return string|int|null
*/
protected function get_config_id() {
// Get config ID setting.
$config_id = $this->settings->config_id;

// Check empty config ID.
if ( empty( $config_id ) ) {
$config_id = \get_option( 'pronamic_pay_config_id' );
}

// Check empty config ID.
if ( empty( $config_id ) ) {
$config_id = null;
}

return $config_id;
}
}
42 changes: 18 additions & 24 deletions src/Pronamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use MeprTransaction;
use Pronamic\WordPress\Money\TaxedMoney;
use Pronamic\WordPress\Pay\Address;
use Pronamic\WordPress\Pay\AddressHelper;
use Pronamic\WordPress\Pay\Customer;
use Pronamic\WordPress\Pay\ContactName;
use Pronamic\WordPress\Pay\Core\Util as Core_Util;
Expand All @@ -26,7 +27,7 @@
* Pronamic
*
* @author Remco Tolsma
* @version 2.2.3
* @version 2.3.1
* @since 2.0.5
*/
class Pronamic {
Expand Down Expand Up @@ -76,31 +77,24 @@ public static function get_payment( MeprTransaction $memberpress_transaction ) {

$payment->set_customer( $customer );

/*
/**
* Address.
*
* @link https://github.com/wp-premium/memberpress-business/blob/1.3.36/app/models/MeprUser.php#L1191-L1216
*/
$address = new Address();

$address->set_name( $contact_name );

$address_fields = array(
'one' => 'set_line_1',
'two' => 'set_line_2',
'city' => 'set_city',
'state' => 'set_region',
'zip' => 'set_postal_code',
'country' => 'set_country_code',
$address = AddressHelper::from_array(
array(
'line_1' => $memberpress_user->address( 'one', false ),
'line_2' => $memberpress_user->address( 'two', false ),
'postal_code' => $memberpress_user->address( 'zip', false ),
'city' => $memberpress_user->address( 'city', false ),
'region' => $memberpress_user->address( 'state', false ),
'country_code' => $memberpress_user->address( 'country', false ),
)
);

foreach ( $address_fields as $field => $function ) {
$value = $memberpress_user->address( $field, false );

if ( empty( $value ) ) {
continue;
}

call_user_func( array( $address, $function ), $value );
if ( null !== $address ) {
$address->set_name( $contact_name );
}

$payment->set_billing_address( $address );
Expand Down Expand Up @@ -138,10 +132,10 @@ public static function get_payment( MeprTransaction $memberpress_transaction ) {
if ( $memberpress_subscription->in_trial() ) {
$payment->set_total_amount(
new TaxedMoney(
$memberpress_subscription->trial_amount,
$memberpress_subscription->trial_total,
MemberPress::get_currency(),
null, // Calculate tax value based on tax percentage.
$memberpress_transaction->tax_rate
$memberpress_subscription->trial_tax_amount,
$memberpress_subscription->tax_rate
)
);
}
Expand Down
Loading

0 comments on commit 8887d0c

Please sign in to comment.