This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Enable Braintree credit card payments via hosted fields #39
Merged
Conversation
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
luukveenis
force-pushed
the
add/reusable-sources
branch
8 times, most recently
from
November 1, 2016 22:00
f9fe454
to
3084a6a
Compare
adammathys
force-pushed
the
add/reusable-sources
branch
from
January 31, 2017 23:37
3084a6a
to
055b50e
Compare
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
force-pushed
the
add/reusable-sources
branch
from
February 1, 2017 22:46
d4871d6
to
5377da5
Compare
adammathys
force-pushed
the
add/reusable-sources
branch
from
February 2, 2017 18:56
5377da5
to
8480ea2
Compare
Should help make them a little bit more consistent since the specs need to communicate with Braintree for the hosted fields.
adammathys
force-pushed
the
add/reusable-sources
branch
from
February 3, 2017 21:55
1a3dee9
to
1d6b93e
Compare
I am 👍 on the changes @adammathys added, but would be good to get another set of eyes on this. |
stewart
approved these changes
Feb 6, 2017
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.