Skip to content

Commit

Permalink
Add fee field
Browse files Browse the repository at this point in the history
  • Loading branch information
TechiRexach committed Nov 14, 2023
1 parent 45e1503 commit 3ae0372
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 16 deletions.
6 changes: 5 additions & 1 deletion lib/devengo/resources/incoming_payments/incoming_payment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
require "byebug"


module Devengo
module Resources
Expand All @@ -15,13 +17,15 @@ class IncomingPayment < Shared::BaseResponse
map :created_at
map :instant
map :processor
map :fee

def self.from_raw(api_response:, **attributes)
super api_response: api_response,
**attributes,
amount: Shared::Money.from_raw(**attributes[:amount]),
third_party: Shared::ThirdParties::ThirdParty.from_raw(**attributes[:third_party]),
processor: Shared::Processor.from_raw(**attributes[:processor])
processor: Shared::Processor.from_raw(**attributes[:processor]),
fee: Shared::Money.from_raw(**attributes[:fee])
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/devengo/resources/payments/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Payment < Shared::BaseResponse
map :error
map :links
map :third_party
map :fee
map :metadata

def self.from_raw(api_response:, **attributes)
Expand All @@ -30,7 +31,8 @@ def self.from_raw(api_response:, **attributes)
processor: Shared::Processor.from_raw(**attributes[:processor]),
error: Shared::Error.from_raw_nullable(attributes[:error]),
third_party: Shared::ThirdParties::ThirdParty.from_raw(**attributes[:third_party]),
links: Links.from_raw_nullable(attributes[:links])
links: Links.from_raw_nullable(attributes[:links]),
fee: Shared::Money.from_raw(**attributes[:fee])
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/devengo/resources/verifications/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class Verification < Shared::BaseResponse
map :expired_at
map :created_at
map :error
map :fee
map :metadata

def self.from_raw(api_response:, **attributes)
super api_response: api_response,
**attributes,
third_party: Shared::ThirdParties::ThirdParty.from_raw(**attributes[:third_party]),
error: Shared::Error.from_raw_nullable(attributes[:error])
error: Shared::Error.from_raw_nullable(attributes[:error]),
fee: Shared::Money.from_raw(**attributes[:fee])
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/devengo/api/incoming_payments_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
shared_examples "incoming payment expects" do
it "incoming payment with expected data" do
expect(incoming_payment).to be_a Devengo::Resources::IncomingPayments::IncomingPayment
expect(instance_methods_count(incoming_payment)).to eq 11
expect(instance_methods_count(incoming_payment)).to eq 12
expect(incoming_payment.id).to eq "pyi_7FssaPM2jVvKGwoRJB1R36"
expect(incoming_payment.account_id).to eq "acc_7SZwPFdReAtDu8aNr1T5dE"
expect(incoming_payment.status).to eq "confirmed"
Expand All @@ -29,6 +29,9 @@
expect(incoming_payment.third_party.account.bank.name).to eq "Revolut Payments UAB"
expect(incoming_payment.third_party.account.bank.bic).to eq "REVOLT21"
expect(incoming_payment.created_at).to eq "2022-01-01T12:00:00Z"
expect(incoming_payment.fee).to be_a Devengo::Resources::Shared::Money
expect(incoming_payment.fee.cents).to eq 10
expect(incoming_payment.fee.currency).to eq "EUR"
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/devengo/api/payments_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
shared_examples "payment expects" do
it "payment with expected data" do
expect(payment).to be_a Devengo::Resources::Payments::Payment
expect(instance_methods_count(payment)).to eq 17
expect(instance_methods_count(payment)).to eq 18
expect(payment.id).to eq "pyo_4JgnTOvdXQWn81NK1bOhIY"
expect(payment.status).to eq "confirmed"
expect(payment.recipient).to eq "Ana Devenger"
Expand Down Expand Up @@ -38,6 +38,9 @@
expect(payment.third_party.account.bank.name).to eq "Banco de Sabadell, S.A."
expect(payment.third_party.account.bank.bic).to eq "BSABESBBXXX"
expect(payment.metadata).to eq example_key: "example_value"
expect(payment.fee).to be_a Devengo::Resources::Shared::Money
expect(payment.fee.cents).to eq 10
expect(payment.fee.currency).to eq "EUR"
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/devengo/api/verifications_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
shared_examples "verification expects" do
it "verification with expected data" do
expect(verification).to be_a Devengo::Resources::Verifications::Verification
expect(instance_methods_count(verification)).to eq 10
expect(instance_methods_count(verification)).to eq 11
expect(verification.id).to eq "vrf_4krc1kE2lQL7nE7yT4wBHH"
expect(verification.status).to eq "error"
expect(verification.company_reference).to be_nil
Expand All @@ -27,6 +27,9 @@
expect(verification.error.type).to eq "blocked_account"
expect(verification.error.reason).to eq "AC06"
expect(verification.metadata).to eq example_key: "example_value"
expect(verification.fee).to be_a Devengo::Resources::Shared::Money
expect(verification.fee.cents).to eq 10
expect(verification.fee.currency).to eq "EUR"
end
end

Expand Down
8 changes: 6 additions & 2 deletions spec/fixtures/responses/incoming_payments/find/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Via: 1.1 vegur
}
}
},
"created_at": "2022-01-01T12:00:00Z"
"created_at": "2022-01-01T12:00:00Z",
"fee": {
"cents": 10,
"currency": "EUR"
}
}
}
}
8 changes: 6 additions & 2 deletions spec/fixtures/responses/incoming_payments/list/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ Via: 1.1 vegur
}
}
},
"created_at": "2022-01-01T12:00:00Z"
"created_at": "2022-01-01T12:00:00Z",
"fee": {
"cents": 10,
"currency": "EUR"
}
}
],
"links": {
Expand All @@ -64,4 +68,4 @@ Via: 1.1 vegur
"total_items": 1
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/payments/create/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ Via: 1.1 vegur
}
}
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/payments/find/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ Via: 1.1 vegur
}
}
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/payments/list/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Via: 1.1 vegur
}
}
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
Expand All @@ -76,4 +80,4 @@ Via: 1.1 vegur
"total_items": 1
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/verifications/create/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ Via: 1.1 vegur
"type": "blocked_account",
"reason": "AC06"
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/verifications/find/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ Via: 1.1 vegur
"type": "blocked_account",
"reason": "AC06"
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
}
}
}
6 changes: 5 additions & 1 deletion spec/fixtures/responses/verifications/list/success.http
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Via: 1.1 vegur
"type": "blocked_account",
"reason": "AC06"
},
"fee": {
"cents": 10,
"currency": "EUR"
},
"metadata": {
"example_key": "example_value"
}
Expand All @@ -64,4 +68,4 @@ Via: 1.1 vegur
"last": "http://localhost:3000/v1/verifications?page=7&page_size=2",
"next": "http://localhost:3000/v1/verifications?page=2&page_size=2"
}
}
}

0 comments on commit 3ae0372

Please sign in to comment.