mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Merge pull request #14101 from mkllnk/taler-currency
Use real currency for Taler payments unless using demo backend
This commit is contained in:
@@ -18,6 +18,9 @@ module Spree
|
||||
# - backend_url: https://backend.demo.taler.net/instances/sandbox
|
||||
# - api_key: sandbox
|
||||
class Taler < PaymentMethod
|
||||
# Demo backend instances will use the KUDOS currency.
|
||||
DEMO_PREFIX = "https://backend.demo.taler.net/instances"
|
||||
|
||||
preference :backend_url, :string
|
||||
preference :api_key, :password
|
||||
|
||||
@@ -123,7 +126,7 @@ module Spree
|
||||
def create_taler_order(payment)
|
||||
# We are ignoring currency for now so that we can test with the
|
||||
# current demo backend only working with the KUDOS currency.
|
||||
taler_amount = "KUDOS:#{payment.amount}"
|
||||
taler_amount = "#{currency(payment)}:#{payment.amount}"
|
||||
urls = Rails.application.routes.url_helpers
|
||||
fulfillment_url = urls.payment_gateways_confirm_taler_url(payment_id: payment.id)
|
||||
taler_order.create(
|
||||
@@ -140,6 +143,12 @@ module Spree
|
||||
id:,
|
||||
)
|
||||
end
|
||||
|
||||
def currency(payment)
|
||||
return "KUDOS" if preferred_backend_url.starts_with?(DEMO_PREFIX)
|
||||
|
||||
payment.order.currency
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,8 +12,8 @@ RSpec.describe Spree::PaymentMethod::Taler do
|
||||
let(:backend_url) { "https://backend.demo.taler.net/instances/sandbox" }
|
||||
let(:token_url) { "#{backend_url}/private/token" }
|
||||
|
||||
describe "#external_payment_url", vcr: true do
|
||||
it "creates an order reference and retrieves a URL to pay at" do
|
||||
describe "#external_payment_url" do
|
||||
it "creates an order reference and retrieves a URL to pay at", vcr: true do
|
||||
order = create(:order_ready_for_confirmation, payment_method: taler)
|
||||
|
||||
url = subject.external_payment_url(order:)
|
||||
@@ -23,6 +23,26 @@ RSpec.describe Spree::PaymentMethod::Taler do
|
||||
payment = order.payments.last.reload
|
||||
expect(payment.response_code).to match "20...[0-9A-Z-]{17}$"
|
||||
end
|
||||
|
||||
it "creates the Taler order with the right currency" do
|
||||
order = create(:order_ready_for_confirmation, payment_method: taler)
|
||||
|
||||
backend_url = "https://taler.example.com"
|
||||
token_url = "https://taler.example.com/private/token"
|
||||
order_url = "https://taler.example.com/private/orders"
|
||||
taler = Spree::PaymentMethod::Taler.new(
|
||||
preferred_backend_url: "https://taler.example.com",
|
||||
preferred_api_key: "sandbox",
|
||||
)
|
||||
|
||||
stub_request(:post, token_url).to_return(body: { token: "1234" }.to_json)
|
||||
stub_request(:post, order_url)
|
||||
.with(body: /"amount":"AUD:10.0"/)
|
||||
.to_return(body: { order_id: "one" }.to_json)
|
||||
|
||||
url = taler.external_payment_url(order:)
|
||||
expect(url).to eq "#{backend_url}/orders/one"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#purchase" do
|
||||
|
||||
@@ -370,6 +370,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
Spree::PaymentMethod::Taler.create!(
|
||||
name: "Taler",
|
||||
environment: "test",
|
||||
preferred_backend_url: "https://taler.example.com/",
|
||||
distributors: [distributor]
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user