Skip to content

Commit 596fe5b

Browse files
authored
Merge pull request #48 from saucal/feature/account-matching
Implement account matching and creation
2 parents 907c109 + e22888a commit 596fe5b

File tree

2 files changed

+355
-28
lines changed

2 files changed

+355
-28
lines changed

assets/js/amazon-wc-checkout.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,58 @@
7878
}
7979
}
8080

81+
function is_blocked( $node ) {
82+
return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
83+
}
84+
85+
function block( $node ) {
86+
if ( ! is_blocked( $node ) ) {
87+
$node.addClass( 'processing' ).block( {
88+
message: null,
89+
overlayCSS: {
90+
background: '#fff',
91+
opacity: 0.6
92+
}
93+
} );
94+
}
95+
}
96+
97+
function unblock( $node ) {
98+
$node.removeClass( 'processing' ).unblock();
99+
}
100+
101+
function sendConfirmationCode( e ) {
102+
var $this = $( this );
103+
e.preventDefault();
104+
105+
if ( $this.data( 'sending' ) ) {
106+
return;
107+
}
108+
109+
$this.data( 'sending', true );
110+
111+
var $thisArea = $this.parents('.create-account');
112+
113+
block( $thisArea );
114+
115+
$.ajax(
116+
{
117+
type: 'post',
118+
url: $this.prop( 'href' ),
119+
success: function( result ) {
120+
unblock( $thisArea );
121+
$this.data( 'sending', false );
122+
// TODO: Maybe display some feedback
123+
},
124+
error: function( jqXHR, textStatus, errorThrown ) {
125+
unblock( $thisArea );
126+
$this.data( 'sending', false );
127+
// TODO: Maybe display some feedback about what went wrong?
128+
}
129+
}
130+
);
131+
}
132+
81133
function initAmazonPaymentFields() {
82134
if ( ! isAmazonCheckout() ) {
83135
return;
@@ -103,6 +155,8 @@
103155
$( '.woocommerce-shipping-fields' ).insertBefore( '#payment' );
104156
}
105157
$( '.woocommerce-additional-fields' ).insertBefore( '#payment' );
158+
159+
$( '.wc-apa-send-confirm-ownership-code' ).on( 'click', sendConfirmationCode );
106160
}
107161

108162
initAmazonPaymentFields();

0 commit comments

Comments
 (0)