mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Use the voucher adjustment amount for redeeming
This commit is contained in:
committed by
Rachel Arnould
parent
16d6e1f935
commit
f5b9ca361c
@@ -11,16 +11,16 @@ module Vine
|
||||
|
||||
def redeem
|
||||
# Do nothing if we don't have a vine voucher added to the order
|
||||
voucher_adjustment = order.voucher_adjustments.first
|
||||
@voucher = voucher_adjustment&.originator
|
||||
@voucher_adjustment = order.voucher_adjustments.first
|
||||
@voucher = @voucher_adjustment&.originator
|
||||
|
||||
return true if voucher_adjustment.nil? || !@voucher.is_a?(Vouchers::Vine)
|
||||
return true if @voucher_adjustment.nil? || !@voucher.is_a?(Vouchers::Vine)
|
||||
|
||||
return false if vine_settings.nil?
|
||||
|
||||
call_vine_api
|
||||
|
||||
voucher_adjustment.close
|
||||
@voucher_adjustment.close
|
||||
|
||||
true
|
||||
rescue Faraday::ClientError => e
|
||||
@@ -44,9 +44,10 @@ module Vine
|
||||
jwt_service = Vine::JwtService.new(secret: vine_settings["secret"])
|
||||
vine_api = Vine::ApiService.new(api_key: vine_settings["api_key"], jwt_generator: jwt_service)
|
||||
|
||||
# Voucher amount is stored in dollars, VINE expect cents
|
||||
# Voucher adjustment amount is stored in dollars and negative, VINE expect cents
|
||||
amount = -1 * @voucher_adjustment.amount * 100
|
||||
vine_api.voucher_redemptions(
|
||||
@voucher.external_voucher_id, @voucher.external_voucher_set_id, (@voucher.amount * 100)
|
||||
@voucher.external_voucher_id, @voucher.external_voucher_set_id, amount
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ RSpec.describe Vine::VoucherRedeemerService, feature: :connected_apps do
|
||||
|
||||
let(:vine_voucher) {
|
||||
create(:vine_voucher, code: 'some_code', enterprise: distributor,
|
||||
amount: 6, external_voucher_id: voucher_id,
|
||||
amount: 50, external_voucher_id: voucher_id,
|
||||
external_voucher_set_id: voucher_set_id )
|
||||
}
|
||||
let(:voucher_id) { "9d316d27-0dad-411a-8953-316a1aaf7742" }
|
||||
@@ -56,8 +56,9 @@ RSpec.describe Vine::VoucherRedeemerService, feature: :connected_apps do
|
||||
before { add_voucher(vine_voucher) }
|
||||
|
||||
it "redeems the voucher with VINE" do
|
||||
# Order pre discount total is $10, so we expect to redeen 1000 cents
|
||||
expect(vine_api_service).to receive(:voucher_redemptions)
|
||||
.with(voucher_id, voucher_set_id, 600)
|
||||
.with(voucher_id, voucher_set_id, 1000)
|
||||
.and_return(mock_api_response(data:))
|
||||
|
||||
voucher_redeemer_service.redeem
|
||||
|
||||
Reference in New Issue
Block a user