forked from solidusio/solidus_paypal_braintree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue: solidusio#309 Braintree comes with free basic fraud protection. One of the tools is Risk Threshold Rules (velocity checks) [1]. One of the checks is checking amount of transactions per customer email. However, the email was not being attached to the customer when creating it before the transaction. This fixes that so developers can utilize this check. [1] https://developer.paypal.com/braintree/articles/guides/fraud-tools/basic/risk-threshold-rules
- Loading branch information
1 parent
e2b87a4
commit 384490e
Showing
3 changed files
with
131 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -544,6 +544,56 @@ | |
end | ||
end | ||
|
||
describe '#customer_profile_params' do | ||
subject(:params) { gateway.send(:customer_profile_params, payment) } | ||
|
||
let(:payment) do | ||
build(:payment, { | ||
payment_method: gateway, | ||
source: source | ||
}) | ||
end | ||
|
||
context 'when payment does not belong to an order' do | ||
before { allow(payment).to receive(:order).and_return(nil) } | ||
|
||
it 'has the email param as nil' do | ||
expect(subject[:email]).to be_nil | ||
end | ||
end | ||
|
||
context 'when payment belongs to an order' do | ||
it 'has no email param' do | ||
expect(subject[:email]).to eq(payment.order.email) | ||
end | ||
end | ||
end | ||
|
||
describe "Braintree Customer" do | ||
subject(:customer) { braintree.customer.create(params).customer } | ||
|
||
let(:params) { gateway.send(:customer_profile_params, payment) } | ||
|
||
let(:payment) do | ||
build(:payment, { | ||
payment_method: gateway, | ||
source: source | ||
}) | ||
end | ||
|
||
cassette_options = { | ||
cassette_name: 'gateway/customer', | ||
match_requests_on: [:braintree_uri] | ||
} | ||
|
||
context "with customer", vcr: cassette_options do | ||
it 'saves the customer email correctly' do | ||
allow(payment.order).to receive(:email).and_return('[email protected]') | ||
expect(subject.email).to eq(payment.order.email) | ||
end | ||
end | ||
end | ||
|
||
shared_examples "sources_by_order" do | ||
let(:order) { FactoryBot.create :order, user: user, state: "complete", completed_at: Time.current } | ||
let(:gateway) { new_gateway.tap(&:save!) } | ||
|