|
1
|
|
|
jQuery( function( $ ) { |
|
2
|
|
|
'use strict'; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Object to handle Stripe admin functions. |
|
6
|
|
|
*/ |
|
7
|
|
|
var wc_stripe_admin = { |
|
8
|
|
|
isTestMode: function() { |
|
9
|
|
|
return $( '#woocommerce_stripe_testmode' ).is( ':checked' ); |
|
10
|
|
|
}, |
|
11
|
|
|
|
|
12
|
|
|
getSecretKey: function() { |
|
13
|
|
|
if ( wc_stripe_admin.isTestMode() ) { |
|
14
|
|
|
return $( '#woocommerce_stripe_test_secret_key' ).val(); |
|
15
|
|
|
} else { |
|
16
|
|
|
return $( '#woocommerce_stripe_secret_key' ).val(); |
|
17
|
|
|
} |
|
18
|
|
|
}, |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Initialize. |
|
22
|
|
|
*/ |
|
23
|
|
|
init: function() { |
|
24
|
|
|
$( document.body ).on( 'change', '#woocommerce_stripe_testmode', function() { |
|
25
|
|
|
var test_secret_key = $( '#woocommerce_stripe_test_secret_key' ).parents( 'tr' ).eq( 0 ), |
|
26
|
|
|
test_publishable_key = $( '#woocommerce_stripe_test_publishable_key' ).parents( 'tr' ).eq( 0 ), |
|
27
|
|
|
live_secret_key = $( '#woocommerce_stripe_secret_key' ).parents( 'tr' ).eq( 0 ), |
|
28
|
|
|
live_publishable_key = $( '#woocommerce_stripe_publishable_key' ).parents( 'tr' ).eq( 0 ); |
|
29
|
|
|
|
|
30
|
|
|
if ( $( this ).is( ':checked' ) ) { |
|
31
|
|
|
test_secret_key.show(); |
|
32
|
|
|
test_publishable_key.show(); |
|
33
|
|
|
live_secret_key.hide(); |
|
34
|
|
|
live_publishable_key.hide(); |
|
35
|
|
|
} else { |
|
36
|
|
|
test_secret_key.hide(); |
|
37
|
|
|
test_publishable_key.hide(); |
|
38
|
|
|
live_secret_key.show(); |
|
39
|
|
|
live_publishable_key.show(); |
|
40
|
|
|
} |
|
41
|
|
|
} ); |
|
42
|
|
|
|
|
43
|
|
|
$( '#woocommerce_stripe_testmode' ).change(); |
|
44
|
|
|
|
|
45
|
|
|
// Toggle Stripe Checkout settings. |
|
46
|
|
|
$( '#woocommerce_stripe_stripe_checkout' ).change( function() { |
|
47
|
|
|
if ( $( this ).is( ':checked' ) ) { |
|
48
|
|
|
$( '#woocommerce_stripe_stripe_checkout_locale, #woocommerce_stripe_stripe_bitcoin, #woocommerce_stripe_stripe_checkout_image' ).closest( 'tr' ).show(); |
|
49
|
|
|
$( '#woocommerce_stripe_request_payment_api' ).closest( 'tr' ).hide(); |
|
50
|
|
|
} else { |
|
51
|
|
|
$( '#woocommerce_stripe_stripe_checkout_locale, #woocommerce_stripe_stripe_bitcoin, #woocommerce_stripe_stripe_checkout_image' ).closest( 'tr' ).hide(); |
|
52
|
|
|
$( '#woocommerce_stripe_request_payment_api' ).closest( 'tr' ).show(); |
|
53
|
|
|
} |
|
54
|
|
|
}).change(); |
|
55
|
|
|
|
|
56
|
|
|
// Toggle Apple Pay settings. |
|
57
|
|
|
$( '#woocommerce_stripe_apple_pay' ).change( function() { |
|
58
|
|
|
if ( $( this ).is( ':checked' ) ) { |
|
59
|
|
|
$( '#woocommerce_stripe_apple_pay_button, #woocommerce_stripe_apple_pay_button_lang' ).closest( 'tr' ).show(); |
|
60
|
|
|
} else { |
|
61
|
|
|
$( '#woocommerce_stripe_apple_pay_button, #woocommerce_stripe_apple_pay_button_lang' ).closest( 'tr' ).hide(); |
|
62
|
|
|
} |
|
63
|
|
|
}).change(); |
|
64
|
|
|
|
|
65
|
|
|
// Validate the keys to make sure it is matching test with test field. |
|
66
|
|
|
$( '#woocommerce_stripe_secret_key, #woocommerce_stripe_publishable_key' ).on( 'input', function() { |
|
67
|
|
|
var value = $( this ).val(); |
|
68
|
|
|
|
|
69
|
|
|
if ( value.indexOf( '_test_' ) >= 0 ) { |
|
70
|
|
|
$( this ).css( 'border-color', 'red' ).after( '<span class="description stripe-error-description" style="color:red; display:block;">' + wc_stripe_admin_params.localized_messages.not_valid_live_key_msg + '</span>' ); |
|
|
|
|
|
|
71
|
|
|
} else { |
|
72
|
|
|
$( this ).css( 'border-color', '' ); |
|
73
|
|
|
$( '.stripe-error-description', $( this ).parent() ).remove(); |
|
74
|
|
|
} |
|
75
|
|
|
}).trigger( 'input' ); |
|
76
|
|
|
|
|
77
|
|
|
// Validate the keys to make sure it is matching live with live field. |
|
78
|
|
|
$( '#woocommerce_stripe_test_secret_key, #woocommerce_stripe_test_publishable_key' ).on( 'input', function() { |
|
79
|
|
|
var value = $( this ).val(); |
|
80
|
|
|
|
|
81
|
|
|
if ( value.indexOf( '_live_' ) >= 0 ) { |
|
82
|
|
|
$( this ).css( 'border-color', 'red' ).after( '<span class="description stripe-error-description" style="color:red; display:block;">' + wc_stripe_admin_params.localized_messages.not_valid_test_key_msg + '</span>' ); |
|
|
|
|
|
|
83
|
|
|
} else { |
|
84
|
|
|
$( this ).css( 'border-color', '' ); |
|
85
|
|
|
$( '.stripe-error-description', $( this ).parent() ).remove(); |
|
86
|
|
|
} |
|
87
|
|
|
}).trigger( 'input' ); |
|
88
|
|
|
} |
|
89
|
|
|
}; |
|
90
|
|
|
|
|
91
|
|
|
wc_stripe_admin.init(); |
|
92
|
|
|
}); |
|
93
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.