как использовать onReady или что нибудь взамен в 3 версии braintree ( creditcard )
Версия 2
connectCreditCard(clientToken: string, paymentType: string, orderCallBack: any) {
const wrapStoreCheckOutId = this.storeCheckOutId.bind(this);
braintree.setup(clientToken, 'custom', {
id: 'credit-card-form',
hostedFields: {
number: {
selector: '#card-number'
},
cvv: {
selector: '#cvv'
},
expirationDate: {
selector: '#expiration-date'
},
styles: {
'input': {
'font-size': '18px'
},
'.valid': {
'color': 'green',
'font-weight': 'bold'
},
'.invalid': {
'color': 'red',
'font-weight': 'bold'
},
}
},
onReady: function (integration) {
wrapStoreCheckOutId(integration);
},
onPaymentMethodReceived: function (paymentObject) {
orderCallBack(paymentType, paymentObject.nonce);
}
});
}
storeCheckOutId(checkoutObj: any) {
this.checkOutId = checkoutObj;
}
}
Версия 3
connectCreditCard(clientToken: string, paymentType: string, orderCallBack: any) {
const wrapStoreCheckOutId = this.storeCheckOutId.bind(this)
braintree.client.create({
authorization: clientToken
}).then(function (clientInstance) {
return braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': {
'font-size': '18px'
},
'.valid': {
'color': 'green',
'font-weight': 'bold'
},
'.invalid': {
'color': 'red',
'font-weight': 'bold'
}
},
fields: {
number: {
selector: '#card-number'
},
cvv: {
selector: '#cvv'
},
expirationDate: {
selector: '#expiration-date'
},
}
})
}).then(async function (hostedFieldsInstance) {
let form = await document.querySelector('#creditCardForm');
await form.addEventListener('submit', async function (event) {
event.preventDefault();
await hostedFieldsInstance.tokenize().then(async function (payload) {
return orderCallBack(paymentType, payload.nonce)
})
})
}, false)
}
storeCheckOutId(checkoutObj: any) {
this.checkOutId = checkoutObj
}
}