Skip to content

Commit 1cd37fc

Browse files
authored
Merge pull request #51 from saucal/hotfix/admin-ux
alpha5 release
2 parents 596fe5b + d71c2cf commit 1cd37fc

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

assets/js/amazon-wc-admin.js

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
simple_path_form_id: 'simple_path',
55
payment_region_input: $( '#woocommerce_amazon_payments_advanced_payment_region' ),
66
button_language_input: $( '#woocommerce_amazon_payments_advanced_button_language' ),
7-
button_languages: {},
7+
authorization_mode: $( '#woocommerce_amazon_payments_advanced_authorization_mode' ),
8+
payment_capture: $( '#woocommerce_amazon_payments_advanced_payment_capture' ),
89
action_url: '#',
910
spId: '',
1011
register_now_link: $( 'a.register_now' ),
@@ -23,10 +24,44 @@
2324
poll_timer: false,
2425
poll_interval: 3000,
2526
main_setting_form: $( '#mainform' ),
26-
init_settings: function() {
27-
wc_simple_path_form.button_language_input.children( 'option' ).each( function() {
27+
init_dynamic_options: function( select, parent, combos ) {
28+
var allOptions = select.data( 'wc-apa-all-options' );
29+
if ( typeof allOptions !== 'undefined' ) {
30+
return allOptions;
31+
}
32+
allOptions = {};
33+
select.data( 'wc-apa-all-options', allOptions );
34+
35+
select.children( 'option' ).each( function() {
2836
var key = $( this ).prop( 'value' ).replace( '-', '_' );
29-
wc_simple_path_form.button_languages[ key ] = $( this ).text();
37+
allOptions[ key ] = $( this ).text();
38+
} );
39+
40+
var watch = function() {
41+
var val = parent.val();
42+
wc_simple_path_form.select_rebuild( select, combos, val );
43+
};
44+
45+
watch();
46+
47+
parent.on( 'change', watch );
48+
49+
return allOptions;
50+
},
51+
init_settings: function() {
52+
$.each( amazon_admin_params.language_combinations, function( i, langs ) {
53+
langs.unshift( '' );
54+
langs = $.map( langs, function( item ) {
55+
return item.replace( '-', '_' );
56+
} );
57+
amazon_admin_params.language_combinations[ i ] = langs;
58+
} );
59+
60+
wc_simple_path_form.init_dynamic_options( wc_simple_path_form.button_language_input, wc_simple_path_form.payment_region_input, amazon_admin_params.language_combinations );
61+
wc_simple_path_form.init_dynamic_options( wc_simple_path_form.authorization_mode, wc_simple_path_form.payment_capture, {
62+
'': [ 'sync' ],
63+
authorize: true,
64+
manual: true,
3065
} );
3166

3267
// Init values if region is already selected
@@ -38,19 +73,20 @@
3873
wc_simple_path_form.delete_settings_link.on( 'click', this.delete_settings_on_click );
3974
$( document ).on( 'click', 'a.wcapa-toggle-section', this.toggle_visibility );
4075
},
41-
payment_button_language_rebuild: function() {
42-
var langs = amazon_admin_params.language_combinations[ wc_simple_path_form.get_region_selected() ].slice();
43-
langs.unshift( '' );
44-
langs = $.map( langs, function( item ) {
45-
return item.replace( '-', '_' );
46-
} );
47-
var selected = wc_simple_path_form.button_language_input.children( 'option:selected' );
48-
var selected_key = selected.prop( 'value' ).replace( '-', '_' );
76+
select_rebuild: function( select, combos, val ) {
77+
var allOptions = select.data( 'wc-apa-all-options' );
78+
var langs = combos[ val ];
79+
if ( typeof combos[ val ] === 'boolean' ) {
80+
langs = combos[ val ] = Object.keys( allOptions );
81+
}
82+
langs = langs.slice();
83+
var selected = select.children( 'option:selected' );
84+
var selected_key = selected.prop( 'value' );
4985
if ( langs.indexOf( selected_key ) === -1 ) {
50-
wc_simple_path_form.button_language_input.children( 'option' ).remove();
86+
select.children( 'option' ).remove();
5187
selected_key = false;
5288
} else {
53-
wc_simple_path_form.button_language_input.children( 'option' ).not( ':selected' ).remove();
89+
select.children( 'option' ).not( ':selected' ).remove();
5490
}
5591
var found = false;
5692
$.each( langs, function( i, key ) {
@@ -62,22 +98,21 @@
6298
var newOpt = $(
6399
'<option/>',
64100
{
65-
value: key.replace( '_', '-' ),
101+
value: key,
66102
}
67-
).html( wc_simple_path_form.button_languages[ key ] );
103+
).html( allOptions[ key ] );
68104

69105
if ( selected_key && ! found ) {
70106
selected.before( newOpt );
71107
} else {
72-
wc_simple_path_form.button_language_input.append( newOpt );
108+
select.append( newOpt );
73109
}
74110
} );
75111
if ( ! selected_key ) {
76-
wc_simple_path_form.button_language_input.children().first().prop( 'selected', true );
112+
select.children().first().prop( 'selected', true );
77113
}
78114
},
79115
payment_region_on_change: function() {
80-
wc_simple_path_form.payment_button_language_rebuild();
81116
if ( 'jp' === wc_simple_path_form.get_region_selected() ) {
82117
// JP does not have Simple Path Registration, we open a new url for it.
83118
wc_simple_path_form.register_now_link.attr( 'href', wc_simple_path_form.get_simple_path_url() );

includes/class-wc-gateway-amazon-payments-advanced-abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function get_form_fields() {
280280
'type' => 'title',
281281
'description' => sprintf(
282282
/* translators: Merchant URL to copy and paste */
283-
__( 'To process payment the Optimal way complete your Seller Central configuration on plugin setup. From your seller Central home page, go to “Settings – Integration Settings”. In this page, please paste the URL below to the “Merchant URL” input field. <br /><code>%1$s</code>', 'woocommerce-gateway-amazon-payments-advanced' ),
283+
__( 'In order to get the quickest updates while working with Async mode, complete your Seller Central configuration on plugin setup. From your seller Central home page, go to “Settings – Integration Settings”. In this page, please paste the URL below to the “Merchant URL” input field. <br /><code>%1$s</code>', 'woocommerce-gateway-amazon-payments-advanced' ),
284284
wc_apa()->ipn_handler->get_notify_url()
285285
),
286286
),

woocommerce-gateway-amazon-payments-advanced.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin Name: WooCommerce Amazon Pay
1010
* Plugin URI: https://woocommerce.com/products/pay-with-amazon/
1111
* Description: Amazon Pay is embedded directly into your existing web site, and all the buyer interactions with Amazon Pay and Login with Amazon take place in embedded widgets so that the buyer never leaves your site. Buyers can log in using their Amazon account, select a shipping address and payment method, and then confirm their order. Requires an Amazon Pay seller account and supports USA, UK, Germany, France, Italy, Spain, Luxembourg, the Netherlands, Sweden, Portugal, Hungary, Denmark, and Japan.
12-
* Version: 2.0.0-alpha4
12+
* Version: 2.0.0-alpha5
1313
* Author: WooCommerce
1414
* Author URI: https://woocommerce.com
1515
*

0 commit comments

Comments
 (0)