vippsas / vipps-recurring-woocommerce

Vipps Recurring payments for WooCommerce
GNU Affero General Public License v3.0
6 stars 4 forks source link

Fails on manual renewals #8

Closed RashidJa closed 4 years ago

RashidJa commented 4 years ago

I get the following error when trying to pay a manual renewal order:

PHP Fatal error: Uncaught Error: Call to a member function get_billing_period() on null in xxxx/wp-content/plugins/vipps-recurring-payments-gateway-for-woocommerce/includes/class-wc-gateway-vipps-recurring.php:581 Stack trace:

0 xxxx/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(928): WC_Gateway_Vipps_Recurring->process_payment(5)

1 xxxx/wp-content/plugins/woocommerce/includes/class-wc-checkout.php(1131): WC_Checkout->process_order_payment(5, 'vipps_recurring')

2 xxxx/wp-content/plugins/woocommerce/includes/class-wc-ajax.php(462): WC_Checkout->process_checkout()

3 xxxx/wp-includes/class-wp-hook.php(288): WC_AJAX::checkout('')

4 xxxx/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array)

5 xxxx/wp-includes/plugin.php(478): WP_Hook->do_action(Array)

6 xxxx/wp-content/plugins/woocommerce/includes/class-wc-ajax. in xxxx/wp-content/plugins/vipps-recurring-payments-gateway-for-woocommerce/includes/class-wc-gateway-vipps-recurring.php on line 581

Process_payment should probably check if wcs_order_contains_renewal and then get wcs_get_subscriptions_for_renewal_order if it contains a renewal.

Marcuzz commented 4 years ago

Hi,

It was my understanding that you're not supposed to use a subscription payment gateway when using manual renewals?

If you read here: https://docs.woocommerce.com/document/subscriptions/store-manager-guide/#accept-manual-renewals it explains that you can't swap manual payments to automatic payments, only the other way around.

So what I'm trying to understand is why someone would use this payment gateway for manual renewals instead of using: https://github.com/vippsas/vipps-woocommerce

RashidJa commented 4 years ago

Hi,

Yes, it's an edge case. Some payment gateways sets the renewal order to manual if the automatic payment fails or if the subscriber by mistake removes the payment method. So if the customer logs in to pay the order, Vipps shows up as alternative, but throws an error. Maybe to problem is that the renewal order in other payment gateways should not be set to manual, but failed.

Marcuzz commented 4 years ago

Thanks for elaborating!

Do you know if orders in such cases get automatically renewed the following billing period as per usual?

I do need the payment period to determine what period to send to the Vipps API (even though Vipps doesn't strictly use this value "yet") but I can perhaps fetch that from the product itself as a back-up if the billing period is not set and effectively fix the problem that way.

RashidJa commented 4 years ago

I'm not sure, as we have not tested that far. But I think you might run into the same problem if a subscriber toggles on or off automatic renewals (if you have that setting enabled).

Marcuzz commented 4 years ago

Okay. I will fix it seeing as there are some edge cases where this might happen (and there seems to be no way to exclude a subscription gateway from being shown as a payment option for manual renewals)