Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Enable Braintree credit card payments via hosted fields #39

Merged
merged 23 commits into from
Feb 6, 2017

Conversation

luukveenis
Copy link
Contributor

This adds the ability to make credit card payments using Braintree's hosted fields. We provide both frontend and backend views, but at the moment sources are reusable only in the backend.

@luukveenis luukveenis force-pushed the add/reusable-sources branch 8 times, most recently from f9fe454 to 3084a6a Compare November 1, 2016 22:00
@adammathys adammathys force-pushed the add/reusable-sources branch from 3084a6a to 055b50e Compare January 31, 2017 23:37
stewart and others added 16 commits February 1, 2017 14:46
This method is used for the source_form in the admin, to show admins
existing payment methods that can be used to create payments on an
order. Since we inherit directly from Spree::PaymentMethod, the existing
method implementation just returned an empty array.
This commit provides some pseudo-inputs to the source form. These inputs
are then enabled by braintree's Hosted Fields JS.

A further commit will hook into the form submit to create a nonce and
submit it to the backend.
This generates a token nonce from the hosted fields, and re-submits the
form after setting the nonce.

The nonce is also added to the permitted source attributes.
This code is going to be identical to what will be required on the
frontend, so pulling it out will allow it to be used there as well.
I pulled the hosted fields into a partial that could be shared between
the front and back end, each of which can provide their own custom
styles.
We likely want to handle errors differently on the frontend and backend,
so we should let users provide the error callback function.
Because we prevent the form from submitting if tokenization fails, we
need to re-enable the submit button. I discovered running this in a
sandbox that jquery-ujs will automatically disable the submit button
because the submit_tag handles adds `data-disable-with` to the button.
UJS disables the button in a setTimeout, which prevents us from
immediately re-enabling it. The only two options were to either stop
propagation, which could prevent users from adding other submit
handlers, or to re-enable it in a setTimeout that waits longer.
This will default JS feature specs to use poltergeist, but if we provide
driver: :chrome in the metadata for a spec, it will use selenium
instead. This is useful for writing specs and we want to see what's
happening
While working on this, I ran into issues with UJS disabling the submit
button when tokenization failed and not being able to submit again. I
added tests here to verify that we can still submit after a failed
attempt has been made.
When the page first loads, this form should not be visible. We want it
to be displayed when the user selects "new card". Otherwise it's visible
when a reusable source is selected.
Because that's a silly rule.
@adammathys adammathys force-pushed the add/reusable-sources branch from d4871d6 to 5377da5 Compare February 1, 2017 22:46
@adammathys adammathys force-pushed the add/reusable-sources branch from 5377da5 to 8480ea2 Compare February 2, 2017 18:56
Should help make them a little bit more consistent since the specs need
to communicate with Braintree for the hosted fields.
@adammathys adammathys force-pushed the add/reusable-sources branch from 1a3dee9 to 1d6b93e Compare February 3, 2017 21:55
@luukveenis
Copy link
Contributor Author

I am 👍 on the changes @adammathys added, but would be good to get another set of eyes on this.

@adammathys adammathys merged commit 51ed4bd into master Feb 6, 2017
@adammathys adammathys deleted the add/reusable-sources branch February 6, 2017 22:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants