Skip to content

Commit

Permalink
Merge pull request #51 from saucal/hotfix/admin-ux
Browse files Browse the repository at this point in the history
alpha5 release
  • Loading branch information
lauramelos authored Jan 25, 2021
2 parents 596fe5b + d71c2cf commit 1cd37fc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
73 changes: 54 additions & 19 deletions assets/js/amazon-wc-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
simple_path_form_id: 'simple_path',
payment_region_input: $( '#woocommerce_amazon_payments_advanced_payment_region' ),
button_language_input: $( '#woocommerce_amazon_payments_advanced_button_language' ),
button_languages: {},
authorization_mode: $( '#woocommerce_amazon_payments_advanced_authorization_mode' ),
payment_capture: $( '#woocommerce_amazon_payments_advanced_payment_capture' ),
action_url: '#',
spId: '',
register_now_link: $( 'a.register_now' ),
Expand All @@ -23,10 +24,44 @@
poll_timer: false,
poll_interval: 3000,
main_setting_form: $( '#mainform' ),
init_settings: function() {
wc_simple_path_form.button_language_input.children( 'option' ).each( function() {
init_dynamic_options: function( select, parent, combos ) {
var allOptions = select.data( 'wc-apa-all-options' );
if ( typeof allOptions !== 'undefined' ) {
return allOptions;
}
allOptions = {};
select.data( 'wc-apa-all-options', allOptions );

select.children( 'option' ).each( function() {
var key = $( this ).prop( 'value' ).replace( '-', '_' );
wc_simple_path_form.button_languages[ key ] = $( this ).text();
allOptions[ key ] = $( this ).text();
} );

var watch = function() {
var val = parent.val();
wc_simple_path_form.select_rebuild( select, combos, val );
};

watch();

parent.on( 'change', watch );

return allOptions;
},
init_settings: function() {
$.each( amazon_admin_params.language_combinations, function( i, langs ) {
langs.unshift( '' );
langs = $.map( langs, function( item ) {
return item.replace( '-', '_' );
} );
amazon_admin_params.language_combinations[ i ] = langs;
} );

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 );
wc_simple_path_form.init_dynamic_options( wc_simple_path_form.authorization_mode, wc_simple_path_form.payment_capture, {
'': [ 'sync' ],
authorize: true,
manual: true,
} );

// Init values if region is already selected
Expand All @@ -38,19 +73,20 @@
wc_simple_path_form.delete_settings_link.on( 'click', this.delete_settings_on_click );
$( document ).on( 'click', 'a.wcapa-toggle-section', this.toggle_visibility );
},
payment_button_language_rebuild: function() {
var langs = amazon_admin_params.language_combinations[ wc_simple_path_form.get_region_selected() ].slice();
langs.unshift( '' );
langs = $.map( langs, function( item ) {
return item.replace( '-', '_' );
} );
var selected = wc_simple_path_form.button_language_input.children( 'option:selected' );
var selected_key = selected.prop( 'value' ).replace( '-', '_' );
select_rebuild: function( select, combos, val ) {
var allOptions = select.data( 'wc-apa-all-options' );
var langs = combos[ val ];
if ( typeof combos[ val ] === 'boolean' ) {
langs = combos[ val ] = Object.keys( allOptions );
}
langs = langs.slice();
var selected = select.children( 'option:selected' );
var selected_key = selected.prop( 'value' );
if ( langs.indexOf( selected_key ) === -1 ) {
wc_simple_path_form.button_language_input.children( 'option' ).remove();
select.children( 'option' ).remove();
selected_key = false;
} else {
wc_simple_path_form.button_language_input.children( 'option' ).not( ':selected' ).remove();
select.children( 'option' ).not( ':selected' ).remove();
}
var found = false;
$.each( langs, function( i, key ) {
Expand All @@ -62,22 +98,21 @@
var newOpt = $(
'<option/>',
{
value: key.replace( '_', '-' ),
value: key,
}
).html( wc_simple_path_form.button_languages[ key ] );
).html( allOptions[ key ] );

if ( selected_key && ! found ) {
selected.before( newOpt );
} else {
wc_simple_path_form.button_language_input.append( newOpt );
select.append( newOpt );
}
} );
if ( ! selected_key ) {
wc_simple_path_form.button_language_input.children().first().prop( 'selected', true );
select.children().first().prop( 'selected', true );
}
},
payment_region_on_change: function() {
wc_simple_path_form.payment_button_language_rebuild();
if ( 'jp' === wc_simple_path_form.get_region_selected() ) {
// JP does not have Simple Path Registration, we open a new url for it.
wc_simple_path_form.register_now_link.attr( 'href', wc_simple_path_form.get_simple_path_url() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function get_form_fields() {
'type' => 'title',
'description' => sprintf(
/* translators: Merchant URL to copy and paste */
__( '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' ),
__( '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' ),
wc_apa()->ipn_handler->get_notify_url()
),
),
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-gateway-amazon-payments-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: WooCommerce Amazon Pay
* Plugin URI: https://woocommerce.com/products/pay-with-amazon/
* 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.
* Version: 2.0.0-alpha4
* Version: 2.0.0-alpha5
* Author: WooCommerce
* Author URI: https://woocommerce.com
*
Expand Down

0 comments on commit 1cd37fc

Please sign in to comment.