Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtract store credit from total sent to PayBright #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/solidus_paybright/params_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_redirect_params
params = {
# mandatory parameters
"x_account_id" => credentials[:api_key],
"x_amount" => order.total.to_money.to_s,
"x_amount" => order.order_total_after_store_credit.to_money.to_s,
"x_currency" => order.currency,
"x_reference" => @payment.id,
"x_shop_country" => credentials[:shop_country_code],
Expand Down
22 changes: 12 additions & 10 deletions spec/lib/solidus_paybright/params_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require "spec_helper"

describe SolidusPaybright::ParamsHelper do
let(:payment_method) { create(:paybright_payment_method, preference_source: "paybright_credentials") }
let(:payment) { create(:paybright_payment, payment_method: payment_method) }
let(:order) { build_stubbed(:order, total: 110, number: "R123456789", email: "user@example.com") }
let(:payment_method) { build_stubbed(:paybright_payment_method, preference_source: "paybright_credentials") }
let(:payment) { build_stubbed(:paybright_payment, order: order, payment_method: payment_method) }

subject { described_class.new(payment) }

describe "#new" do
Expand All @@ -13,14 +15,6 @@
end

describe "#build_redirect_params" do
before do
allow_any_instance_of(Spree::Order).to receive_messages(
total: 110,
number: "R123456789",
email: "user@example.com"
)
end

it "build the correct parameters for the order" do
params = subject.build_redirect_params
expect(params["x_account_id"]).to eq("api-key")
Expand All @@ -40,5 +34,13 @@
allow_any_instance_of(Spree::Order).to receive_messages email: ""
expect(subject.build_redirect_params.key?("x_customer_email")).to be false
end

context "order has store credit applied" do
before { allow(order).to receive(:total_applicable_store_credit) { 10 } }

it "subtracts the credit from the total passed to Paybright" do
expect(subject.build_redirect_params["x_amount"]).to eq("100.00")
end
end
end
end