Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'braintree-web' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
ApplePayView.prototype.initialize = function () {
var self = this;
var isProduction = self.client.getConfiguration().gatewayConfiguration.environment === 'production';
self.applePayConfiguration = assign({}, self.model.merchantConfiguration.applePay);
self.applePaySessionVersion = self.applePayConfiguration.applePaySessionVersion || DEFAULT_APPLE_PAY_SESSION_VERSION;
delete self.applePayConfiguration.applePaySessionVersion;
self.model.asyncDependencyStarting();
return btApplePay.create({client: this.client}).then(function (applePayInstance) {
var buttonDiv = self.getElementById('apple-pay-button');
self.applePayInstance = applePayInstance;
self.model.on('changeActivePaymentView', function (paymentViewID) {
if (paymentViewID !== self.ID) {
return;
}
global.ApplePaySession.canMakePaymentsWithActiveCard(self.applePayInstance.merchantIdentifier).then(function (canMakePayments) {
if (!canMakePayments) {
if (isProduction) {
self.model.reportError('applePayActiveCardError');
} else {
console.error('Could not find an active card. This may be because you\'re using a production iCloud account in a sandbox Apple Pay Session. Log in to a Sandbox iCloud account to test this flow, and add a card to your wallet. For additional assistance, visit https://help.braintreepayments.com'); // eslint-disable-line no-console
self.model.reportError('developerError');
PayPalView.prototype._initialize = function () {
var paypalButton;
BasePaymentMethodView.prototype._initialize.apply(this, arguments);
this._createPayPalButton();
this.model.asyncDependencyStarting();
PayPal.create({client: this.options.client}, function (err, paypalInstance) {
if (err) {
// TODO: handle errors in PayPal creation
console.error(err);
return;
}
this.paypalInstance = paypalInstance;
paypalButton = this.getElementById('paypal-button');
paypalButton.addEventListener('click', this._tokenize.bind(this));
this.model.asyncDependencyReady();
}.bind(this));
};
it('includes braintreeLibraryVersion', function () {
var postArgs;
analytics.sendEvent(this.client, 'test.event.kind');
expect(this.client._request).to.have.been.called;
postArgs = this.client._request.firstCall.args;
expect(postArgs[0].data.braintreeLibraryVersion).to.equal(braintreeClientVersion);
});
});
export function addCreditCard({braintreeToken, creditCard, fetch=api.fetch,
BraintreeClient=braintree.api.Client,
processingId}) {
return (dispatch, getState) => {
dispatch(processingActions.beginProcessing(processingId));
var client = new BraintreeClient({
clientToken: braintreeToken,
});
client.tokenizeCard({
number: creditCard.number,
expirationDate: creditCard.expiration,
cvv: creditCard.cvv,
}, function(err, nonce) {
if (err) {
console.error('Braintree tokenization error:', err);
dispatch(notificationActions.showError(
{errorCode: errorCodes.BRAINTREE_TOKENIZATION_ERROR}));
} else {
export function addCreditCard({braintreeToken, creditCard, fetch=api.fetch,
BraintreeClient=braintree.api.Client,
processingId}) {
return (dispatch, getState) => {
dispatch(processingActions.beginProcessing(processingId));
var client = new BraintreeClient({
clientToken: braintreeToken,
});
client.tokenizeCard({
number: creditCard.number,
expirationDate: creditCard.expiration,
cvv: creditCard.cvv,
}, function(err, nonce) {
if (err) {
console.error('Braintree tokenization error:', err);
dispatch(notificationActions.showError(
{errorCode: errorCodes.BRAINTREE_TOKENIZATION_ERROR}));
} else {
export function processPayment({productId, braintreeToken, creditCard,
payMethodUri, processingId,
BraintreeClient=braintree.api.Client,
createSubscription=defaultCreateSubscription,
payOnce=_processOneTimePayment,
...args}) {
return (dispatch, getState) => {
dispatch(processingActions.beginProcessing(processingId));
var product = products.get(productId);
var payForProduct;
if (product.recurrence === 'monthly') {
console.log('calling _createSubscription for product',
product.id);
payForProduct = createSubscription;
} else {
console.log('calling _processOneTimePayment for product',
product.id);
payForProduct = payOnce;
export function processPayment({productId, braintreeToken, creditCard,
payMethodUri,
BraintreeClient=braintree.api.Client,
createSubscription=defaultCreateSubscription,
payOnce=processOneTimePayment,
...args}) {
return (dispatch, getState) => {
var product = products.get(productId);
var payForProduct;
if (product.recurrence === 'monthly') {
console.log('calling createSubscription for product',
product.id);
payForProduct = createSubscription;
} else {
console.log('calling processOneTimePayment for product',
product.id);
payForProduct = payOnce;
}
export function processPayment({productId, braintreeToken, creditCard,
payMethodUri, processingId,
BraintreeClient=braintree.api.Client,
createSubscription=defaultCreateSubscription,
payOnce=_processOneTimePayment,
...args}) {
return (dispatch, getState) => {
dispatch(processingActions.beginProcessing(processingId));
var product = products.get(productId);
var payForProduct;
if (product.recurrence === 'monthly') {
console.log('calling _createSubscription for product',
product.id);
payForProduct = createSubscription;
} else {
console.log('calling _processOneTimePayment for product',
product.id);
payForProduct = payOnce;
function initHostedFields() {
client.create({ authorization: braintreeParams.token }, function (
clientErr,
clientInstance
) {
if (clientErr) {
showErrorMessage(loadingErrorMsg);
return;
}
dataCollector.create({ client: clientInstance, kount: true }, function (
clientErr,
dataCollectorInstance
) {
if (clientErr) {
showErrorMessage(loadingErrorMsg);
return;
}
setAuthorization(authorization, onAuthorizationSuccess) {
if (!authorization && this.authorization) {
this.teardown();
} else if (authorization && authorization !== this.authorization) {
if (this.authorization) { this.teardown(); }
this.authorization = authorization;
Braintree.create({ authorization }, (err, clientInstance) => {
if (err) {
this.onError(err);
} else {
this.create(clientInstance, onAuthorizationSuccess);
if (this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
client: clientInstance,
kount: true,
}, this.wrapperHandlers.onDataCollectorInstanceReady);
}
}
});
}
}