@@ -186,6 +186,8 @@ public function __construct() {
186
186
add_action ( 'wp_ajax_amazon_get_order_reference ' , array ( $ this , 'ajax_get_order_reference ' ) );
187
187
add_action ( 'wp_ajax_nopriv_amazon_get_order_reference ' , array ( $ this , 'ajax_get_order_reference ' ) );
188
188
189
+ // WC Subscription Hook
190
+ add_filter ( 'woocommerce_subscriptions_process_payment_for_change_method_via_pay_shortcode ' , array ( $ this , 'filter_payment_method_changed_result ' ), 10 , 2 );
189
191
}
190
192
191
193
/**
@@ -501,6 +503,7 @@ public function checkout_init( $checkout ) {
501
503
// Don't try to render the Amazon widgets if we don't have the prerequisites
502
504
// for each mode.
503
505
if ( ( ! $ enable_login_app && empty ( $ this ->reference_id ) ) || ( $ enable_login_app && empty ( $ this ->access_token ) ) ) {
506
+ add_filter ( 'woocommerce_available_payment_gateways ' , array ( $ this , 'remove_amazon_gateway ' ) );
504
507
return ;
505
508
}
506
509
@@ -1104,6 +1107,24 @@ public function update_amazon_widgets_fragment( $fragments ) {
1104
1107
1105
1108
}
1106
1109
1110
+ /**
1111
+ * Remove amazon gateway.
1112
+ *
1113
+ * @param $gateways
1114
+ *
1115
+ * @return array
1116
+ */
1117
+ public function remove_amazon_gateway ( $ gateways ) {
1118
+
1119
+ foreach ( $ gateways as $ gateway_key => $ gateway ) {
1120
+ if ( 'amazon_payments_advanced ' === $ gateway_key ) {
1121
+ unset( $ gateways [ $ gateway_key ] );
1122
+ }
1123
+ }
1124
+
1125
+ return $ gateways ;
1126
+ }
1127
+
1107
1128
/**
1108
1129
* Remove all gateways except amazon
1109
1130
*
@@ -1639,6 +1660,21 @@ protected function amazon_keys_already_set() {
1639
1660
private function get_settings_url () {
1640
1661
return admin_url ( 'admin.php?page=wc-settings&tab=checkout§ion=amazon_payments_advanced ' );
1641
1662
}
1663
+
1664
+ /**
1665
+ * Set redirect URL if the result redirect URL is empty
1666
+ *
1667
+ * @param mixed $result
1668
+ * @param WC_Subscription $subscription
1669
+ *
1670
+ * @return mixed
1671
+ */
1672
+ public function filter_payment_method_changed_result ( $ result , $ subscription ) {
1673
+ if ( empty ( $ result ['redirect ' ] ) && ! empty ( $ subscription ) && method_exists ( $ subscription , 'get_view_order_url ' ) ) {
1674
+ $ result ['redirect ' ] = $ subscription ->get_view_order_url ();
1675
+ }
1676
+ return $ result ;
1677
+ }
1642
1678
}
1643
1679
1644
1680
/**
0 commit comments