Skip to content

Commit

Permalink
Subtract store credit from total sent to PayBright
Browse files Browse the repository at this point in the history
Since PayBright doesn't allow us to modify payments before capturing
them like some other payment methods, we need to ensure we send them the
correct amount right away.
  • Loading branch information
Luuk Veenis committed Jan 15, 2018
1 parent 06802a6 commit e2518aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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: "[email protected]") }
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: "[email protected]"
)
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

0 comments on commit e2518aa

Please sign in to comment.