-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests, skip confirm step, support non-decimal currencies, domain_…
…verification_certificate as textarea
- Loading branch information
Showing
10 changed files
with
136 additions
and
17 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
module Spree | ||
class Gateway::StripeApplePayGateway < Gateway::StripeGateway | ||
preference :country_code, :string, default: 'US' | ||
preference :domain_verification_certificate, :string | ||
preference :domain_verification_certificate, :text | ||
|
||
def method_type | ||
'stripe_apple_pay' | ||
end | ||
end | ||
end | ||
end |
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,15 @@ | ||
module SpreeGateway | ||
module ApplePayOrderDecorator | ||
def confirmation_required? | ||
return false if paid_with_apple_pay? | ||
|
||
super | ||
end | ||
|
||
def paid_with_apple_pay? | ||
payments.any?(&:apple_pay?) | ||
end | ||
end | ||
end | ||
|
||
Spree::Order.prepend SpreeGateway::OrderDecorator |
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,9 @@ | ||
module SpreeGateway | ||
module ApplePayPaymentDecorator | ||
def apple_pay? | ||
payment_method.is_a? Spree::Gateway::StripeApplePayGateway | ||
end | ||
end | ||
end | ||
|
||
Spree::Payment.prepend SpreeGateway::PaymentDecorator |
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
16 changes: 8 additions & 8 deletions
16
lib/views/frontend/spree/checkout/payment/_stripe_additional_info.html.erb
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,13 +1,13 @@ | ||
<%- if @order.has_checkout_step?('address') -%> | ||
<script> | ||
Spree.stripeAdditionalInfo = { | ||
name: "<%= @order.bill_address.full_name %>", | ||
address_line1: "<%= @order.bill_address.address1 %>", | ||
address_line2: "<%= @order.bill_address.address2 %>", | ||
address_city: "<%= @order.bill_address.city %>", | ||
address_state: "<%= @order.bill_address.state_text %>", | ||
address_zip: "<%= @order.bill_address.zipcode %>", | ||
address_country: "<%= @order.bill_address.country %>" | ||
name: "<%= bill_address.full_name %>", | ||
address_line1: "<%= bill_address.address1 %>", | ||
address_line2: "<%= bill_address.address2 %>", | ||
address_city: "<%= bill_address.city %>", | ||
address_state: "<%= bill_address.state_text %>", | ||
address_zip: "<%= bill_address.zipcode %>", | ||
address_country: "<%= bill_address.country %>" | ||
} | ||
</script> | ||
<%- end -%> | ||
<%- end -%> |
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
18 changes: 18 additions & 0 deletions
18
spec/controllers/spree/apple_pay_domain_verification_spec.rb
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,18 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::ApplePayDomainVerificationController do | ||
let(:domain_verification_certificate) { FFaker::Lorem.characters(20) } | ||
let!(:stripe_apple_pay_payment_method) do | ||
Spree::Gateway::StripeApplePayGateway.create!( | ||
name: 'ApplePay', | ||
preferred_domain_verification_certificate: domain_verification_certificate | ||
) | ||
end | ||
|
||
context '#show' do | ||
it 'renders domain verification certificate' do | ||
get :show | ||
expect(response.body).to eq domain_verification_certificate | ||
end | ||
end | ||
end |
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,74 @@ | ||
require 'spec_helper' | ||
|
||
describe Spree::Order do | ||
let(:order_one) { OrderWalkthrough.up_to(:payment) } | ||
let(:order_two) { OrderWalkthrough.up_to(:payment) } | ||
let(:stripe_apple_pay_payment_method) do | ||
Spree::Gateway::StripeApplePayGateway.create!( | ||
name: 'ApplePay', | ||
preferred_domain_verification_certificate: FFaker::Lorem.characters(20) | ||
) | ||
end | ||
let(:stripe_credit_card_payment_method) do | ||
Spree::Gateway::StripeGateway.create!( | ||
name: 'CreditCard', | ||
preferred_secret_key: FFaker::Lorem.characters(20), | ||
preferred_publishable_key: FFaker::Lorem.characters(20) | ||
) | ||
end | ||
|
||
before do | ||
order_one.payments.create(payment_method_id: stripe_apple_pay_payment_method.id, | ||
amount: 29.99, | ||
state: 'completed') | ||
order_two.payments.create(payment_method_id: stripe_credit_card_payment_method.id, | ||
amount: 29.99, | ||
state: 'completed') | ||
order_one.update_totals | ||
order_two.update_totals | ||
end | ||
|
||
describe '#paid_with_apple_pay?' do | ||
context 'when an order was paid with Apply Pay' do | ||
it 'returns true' do | ||
expect(order_one.paid_with_apple_pay?).to eq true | ||
end | ||
end | ||
|
||
context 'when an order was paid with Credit Card' do | ||
it 'returns false' do | ||
expect(order_two.paid_with_apple_pay?).to eq false | ||
end | ||
end | ||
end | ||
|
||
describe '#confirmation_required?' do | ||
context 'when an order was paid with Apply Pay' do | ||
it 'returns false' do | ||
expect(order_one.confirmation_required?).to eq false | ||
end | ||
end | ||
|
||
context 'when an order was paid with Credit Card' do | ||
it 'returns true' do | ||
expect(order_two.confirmation_required?).to eq true | ||
end | ||
end | ||
end | ||
|
||
context 'when an order was paid with Apply Pay' do | ||
it 'proceeds to Complete order state' do | ||
order_one.next | ||
|
||
expect(order_one.state).to eq 'complete' | ||
end | ||
end | ||
|
||
context 'when an order was paid with Credit Card' do | ||
it 'proceeds to Confirm order state' do | ||
order_two.next | ||
|
||
expect(order_two.state).to eq 'confirm' | ||
end | ||
end | ||
end |
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