-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bigdecimal' | ||
|
||
module Kentaa | ||
module Api | ||
module Resources | ||
class Payment < Resource | ||
def object_key | ||
"Payment_#{id}" | ||
end | ||
|
||
def site | ||
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options) | ||
end | ||
|
||
def site_id | ||
data[:site_id] | ||
end | ||
|
||
def currency | ||
data[:currency] | ||
end | ||
|
||
def amount | ||
BigDecimal(data[:amount]) | ||
end | ||
|
||
def invoicenumber | ||
data[:invoicenumber] | ||
end | ||
|
||
def payment_method | ||
data[:payment_method] | ||
end | ||
|
||
def payment_status | ||
data[:payment_status] | ||
end | ||
|
||
def transaction_id | ||
data[:transaction_id] | ||
end | ||
|
||
def payment_id | ||
data[:payment_id] | ||
end | ||
|
||
def account_iban | ||
data[:account_iban] | ||
end | ||
|
||
def account_bic | ||
data[:account_bic] | ||
end | ||
|
||
def account_name | ||
data[:account_name] | ||
end | ||
|
||
def description | ||
data[:description] | ||
end | ||
|
||
def donations | ||
@donations ||= begin | ||
donations = [] | ||
|
||
if data[:donations] | ||
data[:donations].each do |donation| | ||
donations << Kentaa::Api::Resources::Donation.new(config, data: donation, options: options) | ||
end | ||
end | ||
|
||
donations | ||
end | ||
end | ||
|
||
def orders | ||
@orders ||= begin | ||
orders = [] | ||
|
||
if data[:orders] | ||
data[:orders].each do |order| | ||
orders << Kentaa::Api::Resources::Order.new(config, data: order, options: options) | ||
end | ||
end | ||
|
||
orders | ||
end | ||
end | ||
|
||
private | ||
|
||
def load_resource | ||
request.get("/payments/#{id}", options) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"payment": { | ||
"id": 1, | ||
"site_id": 4, | ||
"created_at": "2021-03-30T14:41:48Z", | ||
"updated_at": "2021-03-30T14:46:25Z", | ||
"currency": "EUR", | ||
"amount": "90.4", | ||
"invoicenumber": "T2021.0004.0000001", | ||
"payment_method": "ideal", | ||
"payment_status": "paid", | ||
"transaction_id": "B5C7B7BCAF1ADF6E2032C7CF56969876", | ||
"payment_id": "116D10DD544ECD1E2D77762C5C3E6D61", | ||
"account_iban": "NL44RABO0123456789", | ||
"account_bic": "RABONL2U", | ||
"account_name": "J. de Tester", | ||
"description": "Example payment", | ||
"donations": [ | ||
{ | ||
"id": 1, | ||
"site_id": 4, | ||
"created_at": "2021-03-30T14:41:48Z", | ||
"updated_at": "2021-03-30T14:46:25Z", | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"anonymous": false, | ||
"contact_details_type": "visible", | ||
"email": "[email protected]", | ||
"newsletter": false, | ||
"device_type": "desktop", | ||
"locale": "nl", | ||
"frequency_type": "oneoff", | ||
"currency": "EUR", | ||
"amount": "15.0", | ||
"transaction_costs": "0.4", | ||
"start_donation": false, | ||
"registration_fee": true, | ||
"registration_fee_amount": "10.0", | ||
"total_amount": "25.4", | ||
"receivable_amount": "24.0", | ||
"countable": true, | ||
"invoicenumber": "T2021.0004.0000001", | ||
"payment_method": "ideal", | ||
"payment_status": "paid", | ||
"payment_status_at": "2016-03-30T14:46:25Z", | ||
"transaction_id": "B5C7B7BCAF1ADF6E2032C7CF56969876", | ||
"payment_id": "116D10DD544ECD1E2D77762C5C3E6D61", | ||
"payment_description": "Example payment", | ||
"target_url": "https://demo1.kentaa.nl/" | ||
} | ||
], | ||
"orders": [ | ||
{ | ||
"id": 21059, | ||
"site_id": 4, | ||
"action_id": 8755, | ||
"created_at": "2021-03-30T14:41:48Z", | ||
"updated_at": "2021-03-30T14:46:25Z", | ||
"invoicenumber": "T2021.0004.0000001", | ||
"total_amount": "65.0", | ||
"currency": "EUR", | ||
"payment_status": "paid", | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"address": { | ||
"address": "Jansbuitensingel 29", | ||
"street": "Jansbuitensingel", | ||
"house_number": "29", | ||
"zipcode": "6811AD", | ||
"city": "Arnhem", | ||
"country": "NL" | ||
}, | ||
"items": [ | ||
{ | ||
"product": { | ||
"id": 26, | ||
"variant_id": 3, | ||
"title": "Sweater", | ||
"variant_title": "XL", | ||
"price": "25.0", | ||
"currency": "EUR" | ||
}, | ||
"quantity": 2, | ||
"amount": "50.0", | ||
"currency": "EUR" | ||
}, | ||
{ | ||
"product": { | ||
"id": 25, | ||
"variant_id": 2, | ||
"title": "T-shirt", | ||
"variant_title": "L", | ||
"price": "15.0", | ||
"currency": "EUR" | ||
}, | ||
"quantity": 1, | ||
"amount": "15.0", | ||
"currency": "EUR" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Kentaa::Api::Resources::Payment do | ||
subject(:response) { described_class.new(config, data: data[:payment]) } | ||
|
||
let(:config) { Kentaa::Api::Config.new(api_key: '12345') } | ||
let(:data) { JSON.parse(File.read('spec/fixtures/responses/payment.json'), symbolize_names: true) } | ||
|
||
describe '#object_key' do | ||
it 'returns the object key' do | ||
expect(response.object_key).to eq('Payment_1') | ||
end | ||
end | ||
|
||
describe '#id' do | ||
it 'returns the resource id' do | ||
expect(response.id).to eq(1) | ||
end | ||
end | ||
|
||
describe '#site' do | ||
it 'returns the site resource' do | ||
expect(response.site).to be_a(Kentaa::Api::Resources::Site) | ||
end | ||
end | ||
|
||
describe '#site_id' do | ||
it 'returns the site id' do | ||
expect(response.site_id).to eq(4) | ||
end | ||
end | ||
|
||
describe '#created_at' do | ||
it 'returns the created_at timestamp' do | ||
expect(response.created_at).to be_a(Time) | ||
end | ||
end | ||
|
||
describe '#updated_at' do | ||
it 'returns the updated_at timestamp' do | ||
expect(response.updated_at).to be_a(Time) | ||
end | ||
end | ||
|
||
describe '#currency' do | ||
it 'returns the payment currency' do | ||
expect(response.currency).to eq('EUR') | ||
end | ||
end | ||
|
||
describe '#amount' do | ||
it 'returns the payment amount' do | ||
expect(response.amount).to eq(BigDecimal('90.4')) | ||
end | ||
end | ||
|
||
describe '#invoicenumber' do | ||
it 'returns the invoice number' do | ||
expect(response.invoicenumber).to eq('T2021.0004.0000001') | ||
end | ||
end | ||
|
||
describe '#payment_method' do | ||
it 'returns the payment method' do | ||
expect(response.payment_method).to eq('ideal') | ||
end | ||
end | ||
|
||
describe '#payment_status' do | ||
it 'returns the payment status' do | ||
expect(response.payment_status).to eq('paid') | ||
end | ||
end | ||
|
||
describe '#transaction_id' do | ||
it 'returns the PSP transaction ID' do | ||
expect(response.transaction_id).to eq('B5C7B7BCAF1ADF6E2032C7CF56969876') | ||
end | ||
end | ||
|
||
describe '#payment_id' do | ||
it 'returns the PSP payment ID' do | ||
expect(response.payment_id).to eq('116D10DD544ECD1E2D77762C5C3E6D61') | ||
end | ||
end | ||
|
||
describe '#account_iban' do | ||
it 'returns the consumer IBAN' do | ||
expect(response.account_iban).to eq('NL44RABO0123456789') | ||
end | ||
end | ||
|
||
describe '#account_bic' do | ||
it 'returns the consumer BIC' do | ||
expect(response.account_bic).to eq('RABONL2U') | ||
end | ||
end | ||
|
||
describe '#account_name' do | ||
it 'returns the consumer name' do | ||
expect(response.account_name).to eq('J. de Tester') | ||
end | ||
end | ||
|
||
describe '#description' do | ||
it 'returns the payment description' do | ||
expect(response.description).to eq('Example payment') | ||
end | ||
end | ||
|
||
describe '#donations' do | ||
it 'returns the associated donations' do | ||
expect(response.donations).not_to be_empty | ||
expect(response.donations.count).to eq(1) | ||
|
||
donation = response.donations.first | ||
expect(donation).to be_a(Kentaa::Api::Resources::Donation) | ||
expect(donation.first_name).to eq('John') | ||
expect(donation.last_name).to eq('Doe') | ||
expect(donation.total_amount).to eq(BigDecimal('25.4')) | ||
end | ||
end | ||
|
||
describe '#orders' do | ||
it 'returns the associated orders' do | ||
expect(response.orders).not_to be_empty | ||
expect(response.orders.count).to eq(1) | ||
|
||
order = response.orders.first | ||
expect(order).to be_a(Kentaa::Api::Resources::Order) | ||
expect(order.first_name).to eq('John') | ||
expect(order.last_name).to eq('Doe') | ||
expect(order.total_amount).to eq(65) | ||
end | ||
end | ||
end |