-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2940931
commit f162381
Showing
6 changed files
with
58 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow | ||
// TODO: we can probably re-use BraintreeForm here | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
import braintree from 'braintree-web' | ||
import { createBraintreeClient, createHostedFieldsInstance, hostedFieldOptions } from 'PaymentGateways/braintree/braintree' | ||
import { error } from 'utilities/alert' | ||
|
||
document.addEventListener('DOMContentLoaded', async () => { | ||
const submit = document.querySelector('button[type="submit"]') | ||
const data = document.querySelector('#braintree_data') | ||
const form = document.querySelector('form#new_customer') | ||
|
||
if (!submit || !data || !form) { | ||
throw new Error('Required Element not found') | ||
} | ||
const authorization = data.dataset?.authorization || '' | ||
|
||
const client = await createBraintreeClient(braintree.client, authorization) | ||
const instance = await createHostedFieldsInstance(braintree.hostedFields, client, hostedFieldOptions) | ||
|
||
submit.removeAttribute('disabled') | ||
form.addEventListener('submit', (event: Event) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
instance.tokenize((tokenizeErr, payload) => { | ||
if (tokenizeErr) { | ||
error('Some of the credit card details are wrong. Please update them.') | ||
} else { | ||
document.querySelector('input#braintree_nonce')?.setAttribute('value', payload.nonce) | ||
;((form: any): HTMLFormElement).submit() | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@javascript | ||
Feature: Credit card details | ||
In order to pay for the service | ||
As a provider | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters