@@ -6,17 +6,43 @@ define(
6
6
[
7
7
'ko' ,
8
8
'Magento_Payment/js/view/payment/cc-form' ,
9
+ 'Magento_Checkout/js/action/set-payment-information' ,
9
10
'Magento_Checkout/js/model/quote' ,
10
11
'braintree' ,
11
12
'underscore' ,
12
13
'jquery' ,
13
14
'Magento_Ui/js/model/messageList' ,
14
15
'mage/translate'
15
16
] ,
16
- function ( ko , Component , quote , braintreeClientSDK , _ , $ , messageList , $t ) {
17
+ function ( ko , Component , setPaymentInformationAction , quote , braintreeClientSDK , _ , $ , messageList , $t ) {
17
18
'use strict' ;
18
19
var configBraintree = window . checkoutConfig . payment . braintree ;
19
20
return Component . extend ( {
21
+
22
+ placeOrderHandler : null ,
23
+ validateHandler : null ,
24
+ setPlaceOrderHandler : function ( handler ) {
25
+ this . placeOrderHandler = handler ;
26
+ } ,
27
+ setValidateHandler : function ( handler ) {
28
+ this . validateHandler = handler ;
29
+ } ,
30
+ isShowLegend : function ( ) {
31
+ return true ;
32
+ } ,
33
+ getSource : function ( ) {
34
+ return window . checkoutConfig . payment . iframe . source [ this . getCode ( ) ] ;
35
+ } ,
36
+ getControllerName : function ( ) {
37
+ return window . checkoutConfig . payment . iframe . controllerName [ this . getCode ( ) ] ;
38
+ } ,
39
+ getPlaceOrderUrl : function ( ) {
40
+ return window . checkoutConfig . payment . iframe . placeOrderUrl [ this . getCode ( ) ] ;
41
+ } ,
42
+
43
+ isActive : function ( ) {
44
+ return true ;
45
+ } ,
20
46
defaults : {
21
47
template : 'Magento_Braintree/payment/cc-form' ,
22
48
isCcFormShown : true ,
@@ -79,60 +105,64 @@ define(
79
105
* Prepare and process payment information
80
106
*/
81
107
preparePayment : function ( ) {
82
- var self = this ,
83
- cardInfo = null ;
84
-
85
- messageList . clear ( ) ;
86
- this . quoteBaseGrandTotals = quote . totals ( ) . base_grand_total ;
108
+ if ( this . validateHandler ( ) ) {
109
+ var self = this ,
110
+ cardInfo = null ;
87
111
88
- this . isPaymentProcessing = $ . Deferred ( ) ;
89
- $ . when ( this . isPaymentProcessing ) . done (
90
- function ( ) {
91
- self . placeOrder ( ) ;
92
- }
93
- ) . fail (
94
- function ( result ) {
95
- self . handleError ( result ) ;
96
- }
97
- ) ;
112
+ messageList . clear ( ) ;
113
+ this . quoteBaseGrandTotals = quote . totals ( ) . base_grand_total ;
98
114
99
- this . getFraudAdditionalData ( ) ;
115
+ this . isPaymentProcessing = $ . Deferred ( ) ;
116
+ $ . when ( this . isPaymentProcessing ) . done (
100
117
101
- if ( this . selectedCardToken ( ) ) {
102
- if ( self . show3dSecure ) {
103
- self . verify3DSWithToken ( ) ;
104
- } else {
105
- this . isPaymentProcessing . resolve ( ) ;
106
- }
118
+ function ( ) {
119
+ self . placeOrder ( ) ;
120
+ }
121
+ ) . fail (
122
+ function ( result ) {
123
+ self . handleError ( result ) ;
124
+ }
125
+ ) ;
107
126
108
- return ;
109
- }
127
+ this . getFraudAdditionalData ( ) ;
110
128
111
- cardInfo = {
112
- number : this . creditCardNumber ( ) ,
113
- expirationMonth : this . creditCardExpMonth ( ) ,
114
- expirationYear : this . creditCardExpYear ( ) ,
115
- cvv : this . creditCardVerificationNumber ( )
116
- } ;
117
- this . braintreeClient . tokenizeCard ( cardInfo , function ( error , nonce ) {
118
- if ( error ) {
119
- this . isPaymentProcessing . reject ( error ) ;
129
+ if ( this . selectedCardToken ( ) ) {
130
+ if ( self . show3dSecure ) {
131
+ self . verify3DSWithToken ( ) ;
132
+ } else {
133
+ this . isPaymentProcessing . resolve ( ) ;
134
+ }
120
135
121
136
return ;
122
137
}
123
138
124
- self . paymentMethodNonce ( nonce ) ;
139
+ cardInfo = {
140
+ number : this . creditCardNumber ( ) ,
141
+ expirationMonth : this . creditCardExpMonth ( ) ,
142
+ expirationYear : this . creditCardExpYear ( ) ,
143
+ cvv : this . creditCardVerificationNumber ( )
144
+ } ;
145
+ this . braintreeClient . tokenizeCard ( cardInfo , function ( error , nonce ) {
146
+ if ( error ) {
147
+ this . isPaymentProcessing . reject ( error ) ;
125
148
126
- if ( self . show3dSecure ) {
127
- self . verify3DS ( ) ;
128
- } else {
129
- self . isPaymentProcessing . resolve ( ) ;
130
- }
131
- } ) ;
149
+ return ;
150
+ }
151
+
152
+ self . paymentMethodNonce ( nonce ) ;
153
+
154
+ if ( self . show3dSecure ) {
155
+ self . verify3DS ( ) ;
156
+ } else {
157
+ self . isPaymentProcessing . resolve ( ) ;
158
+ }
159
+ } ) ;
160
+ }
132
161
} ,
133
162
/**
134
163
* @override
135
164
*/
165
+
136
166
getData : function ( ) {
137
167
return {
138
168
'method' : this . item . method ,
@@ -148,6 +178,7 @@ define(
148
178
}
149
179
} ;
150
180
} ,
181
+
151
182
/**
152
183
* Display error message on the top of the page and reset payment method nonce.
153
184
* @param {* } error - error message
@@ -278,6 +309,9 @@ define(
278
309
}
279
310
return availableTypes ;
280
311
} ,
312
+ context : function ( ) {
313
+ return this ;
314
+ } ,
281
315
/**
282
316
* Get fraud control token.
283
317
*/
0 commit comments