Skip to content

Commit

Permalink
fix: several issues with initial charge description being empty or wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcuzz committed Dec 22, 2021
1 parent 4fca2cc commit b97d5ed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ Alternatively you could look into using WooCommerce "Early renewals": [https://d

==== End Log ====

= 1.12.3 =
* Fixed: Initial charge description no longer contains " + " when no extra products are purchased.
* Fixed: Filling in 0 in the trial field tricking us into adding a campaign to the product, also resulting in an empty `initialCharge.description` and being unable to check out.

= 1.12.2 =
* Fixed: Fixed an issue where `initialCharge.description` was empty. It cannot be empty under any circumstances.

Expand Down
12 changes: 8 additions & 4 deletions includes/wc-gateway-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -1471,16 +1471,20 @@ public function process_payment( $order_id, bool $retry = true, bool $previous_e
$is_zero_amount = (int) $order->get_total() === 0 || $is_gateway_change;
$capture_immediately = $is_virtual || $direct_capture;
$has_synced_product = WC_Subscriptions_Synchroniser::subscription_contains_synced_product( $subscription );
$has_trial = WC_Subscriptions_Product::get_trial_length( $product ) !== null;
$has_trial = (bool) WC_Subscriptions_Product::get_trial_length( $product );

$sign_up_fee = WC_Subscriptions_Order::get_sign_up_fee( $order );
$has_campaign = $has_trial || $has_synced_product || $is_zero_amount || $order->get_total_discount() !== 0.00 || $is_subscription_switch || $sign_up_fee;
$has_free_campaign = $is_subscription_switch || $sign_up_fee || $has_synced_product || $has_trial;

if ( ! $is_zero_amount ) {
$initial_charge_description = WC_Vipps_Recurring_Helper::get_product_description( $parent_product ) . ' + ' . $extra_initial_charge_description;
if ( $has_campaign && ! empty( $extra_initial_charge_description ) ) {
$initial_charge_description = $extra_initial_charge_description;
$initial_charge_description = WC_Vipps_Recurring_Helper::get_product_description( $parent_product );
if ( ! empty( $extra_initial_charge_description ) ) {
$initial_charge_description .= ' + ' . $extra_initial_charge_description;

if ( $has_campaign ) {
$initial_charge_description = $extra_initial_charge_description;
}
}

$agreement_body = array_merge( $agreement_body, [
Expand Down
3 changes: 2 additions & 1 deletion includes/wc-vipps-recurring-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ private function process_agreement_body( $body ): array {
}
}

if ( isset( $body['initialCharge']['description'] ) ) {
if ( isset( $body['initialCharge'] ) ) {
$charge_description = ! empty( $body['initialCharge']['description'] )
? $body['initialCharge']['description']
: 'Mangler produktbeskrivelse';

$body['initialCharge']['description'] = $charge_description;
if ( strlen( $charge_description ) > 45 ) {
$body['initialCharge']['description'] = mb_substr( $charge_description, 0, 42 ) . '...';
}
Expand Down
4 changes: 2 additions & 2 deletions woo-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Offer recurring payments with Vipps for WooCommerce Subscriptions
* Author: Everyday AS
* Author URI: https://everyday.no
* Version: 1.12.2
* Version: 1.12.3
* Requires at least: 4.4
* Tested up to: 5.8
* WC tested up to: 6.0
Expand All @@ -17,7 +17,7 @@

// phpcs:disable WordPress.Files.FileName

define( 'WC_VIPPS_RECURRING_VERSION', '1.12.2' );
define( 'WC_VIPPS_RECURRING_VERSION', '1.12.3' );

add_action( 'plugins_loaded', 'woocommerce_gateway_vipps_recurring_init' );

Expand Down

0 comments on commit b97d5ed

Please sign in to comment.