Skip to content

Commit be1b4e8

Browse files
Add Affirm::Struct::Transaction#provider (#10)
Affirm returns a magic number for the provider used on the platform. This commit adds a provider method on the transaction to return the proper name for the provider.
1 parent e52f1d2 commit be1b4e8

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/affirm/structs/transaction.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ class Transaction < Base
1212
attr_accessor :order_id
1313
attr_accessor :provider_id
1414
attr_accessor :status
15+
16+
def provider
17+
case provider_id
18+
when 1
19+
:affirm
20+
when 2
21+
:katapult
22+
end
23+
end
1524
end
1625
end
1726
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require "spec_helper"
2+
3+
RSpec.describe Affirm::Struct::Transaction do
4+
describe "#provider" do
5+
context "when provider_id is 1" do
6+
let(:transaction) { Affirm::Struct::Transaction.new(provider_id: 1) }
7+
it "returns :affirm" do
8+
expect(transaction.provider).to eql :affirm
9+
end
10+
end
11+
12+
context "when provider_id is 2" do
13+
let(:transaction) { Affirm::Struct::Transaction.new(provider_id: 2) }
14+
it "returns :katapult" do
15+
expect(transaction.provider).to eql :katapult
16+
end
17+
end
18+
19+
context "when provider_id is nil" do
20+
let(:transaction) { Affirm::Struct::Transaction.new }
21+
it "returns nil" do
22+
expect(transaction.provider).to eql nil
23+
end
24+
end
25+
26+
context "when provider_id is anything else" do
27+
let(:transaction) { Affirm::Struct::Transaction.new(provider_id: 99) }
28+
it "returns nil" do
29+
expect(transaction.provider).to eql nil
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)