From a0389e4da9d58bd168d7a940d77938163eb95b0a Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 21:52:56 +0100 Subject: [PATCH 1/6] Refund: add metadata attribute --- lib/mollie/refund.rb | 5 +++++ test/fixtures/refunds/get.json | 3 +++ test/mollie/refund_test.rb | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/lib/mollie/refund.rb b/lib/mollie/refund.rb index 01bdc32..86042cf 100644 --- a/lib/mollie/refund.rb +++ b/lib/mollie/refund.rb @@ -14,6 +14,7 @@ class Refund < Base :payment_id, :order_id, :description, + :metadata, :created_at, :_links @@ -47,6 +48,10 @@ def settlement_amount=(settlement_amount) @settlement_amount = Amount.new(settlement_amount) end + def metadata=(metadata) + @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) + end + def lines=(lines) @lines = lines.map { |line| Order::Line.new(line) } end diff --git a/test/fixtures/refunds/get.json b/test/fixtures/refunds/get.json index 3c6e1fb..236e7db 100644 --- a/test/fixtures/refunds/get.json +++ b/test/fixtures/refunds/get.json @@ -8,6 +8,9 @@ "status": "pending", "createdAt": "2018-09-25T17:40:23+00:00", "description": "Required quantity not in stock, refunding one photo book.", + "metadata": { + "bookkeeping_id": 12345 + }, "orderId": "ord_stTC2WHAuS", "paymentId": "tr_WDqYK6vllg", "settlementAmount": { diff --git a/test/mollie/refund_test.rb b/test/mollie/refund_test.rb index c1f524d..104bf38 100644 --- a/test/mollie/refund_test.rb +++ b/test/mollie/refund_test.rb @@ -180,5 +180,13 @@ def test_nil_order refund = Payment::Refund.new(id: 're_4qqhO89gsT') assert refund.order.nil? end + + def test_metadata_struct + stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT') + .to_return(status: 200, body: read_fixture('refunds/get.json'), headers: {}) + + refund = Payment::Refund.get('re_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') + assert_equal 12345, refund.metadata.bookkeeping_id + end end end From 82823b5ebddc96d8175487192e3f65fc99f54e0d Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 22:11:52 +0100 Subject: [PATCH 2/6] Refund: add settlement_id attribute --- lib/mollie/refund.rb | 2 +- test/mollie/refund_test.rb | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/mollie/refund.rb b/lib/mollie/refund.rb index 86042cf..582b89e 100644 --- a/lib/mollie/refund.rb +++ b/lib/mollie/refund.rb @@ -8,6 +8,7 @@ class Refund < Base attr_accessor :id, :amount, + :settlement_id, :settlement_amount, :status, :lines, @@ -69,7 +70,6 @@ def payment(options = {}) end def settlement(options = {}) - settlement_id = Util.extract_id(links, 'settlement') return if settlement_id.nil? Settlement.get(settlement_id, options) end diff --git a/test/mollie/refund_test.rb b/test/mollie/refund_test.rb index 104bf38..b895c29 100644 --- a/test/mollie/refund_test.rb +++ b/test/mollie/refund_test.rb @@ -126,13 +126,7 @@ def test_get_settlement { "resource": "refund", "id": "re_4qqhO89gsT", - "paymentId": "tr_WDqYK6vllg", - "_links": { - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - } - } + "settlementId": "stl_jDk30akdN" } ), headers: {}) From f4b270d31a546aa39c5b116cf4c41736109ab8c9 Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 22:44:14 +0100 Subject: [PATCH 3/6] Payment: add update example --- examples/payments/update.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/payments/update.rb diff --git a/examples/payments/update.rb b/examples/payments/update.rb new file mode 100644 index 0000000..1690cac --- /dev/null +++ b/examples/payments/update.rb @@ -0,0 +1,7 @@ +payment = Mollie::Payment.update( + 'tr_7UhSN1zuXS', + description: 'Order #98765', + metadata: { + order_id: '98765' + } +) From 251352f8e9d5f6198fd9cd8552db1fb271452a08 Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 22:48:59 +0100 Subject: [PATCH 4/6] Organization: add vat_regulation attribute --- lib/mollie/organization.rb | 1 + test/mollie/organization_test.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/mollie/organization.rb b/lib/mollie/organization.rb index 0f11575..369716b 100644 --- a/lib/mollie/organization.rb +++ b/lib/mollie/organization.rb @@ -7,6 +7,7 @@ class Organization < Base :address, :registration_number, :vat_number, + :vat_regulation, :_links alias links _links diff --git a/test/mollie/organization_test.rb b/test/mollie/organization_test.rb index 51fcad1..de30ef1 100644 --- a/test/mollie/organization_test.rb +++ b/test/mollie/organization_test.rb @@ -16,6 +16,7 @@ def test_setting_attributes }, registration_number: '30204462', vat_number: 'NL815839091B01', + vat_regulation: 'dutch', _links: { 'self' => { 'href' => 'https://api.mollie.com/v2/organizations/org_12345678', @@ -40,6 +41,7 @@ def test_setting_attributes assert_equal 'NL', organization.address.country assert_equal '30204462', organization.registration_number assert_equal 'NL815839091B01', organization.vat_number + assert_equal 'dutch', organization.vat_regulation assert_equal 'https://api.mollie.com/v2/organizations/org_12345678', organization.links['self']['href'] end From 99914c9ff45698e687417d45f4447c7f9f370239 Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 23:20:00 +0100 Subject: [PATCH 5/6] Subscription: add "list all" endpoint For consistency, `Customer::Subscription` now inherits from `Subscription`, similar to `Payment` and `Customer::Payment`. --- examples/subscriptions/list.rb | 4 + lib/mollie.rb | 5 +- lib/mollie/customer/subscription.rb | 105 +-------------------- lib/mollie/subscription.rb | 107 ++++++++++++++++++++++ test/mollie/customer/subscription_test.rb | 4 +- 5 files changed, 117 insertions(+), 108 deletions(-) create mode 100644 lib/mollie/subscription.rb diff --git a/examples/subscriptions/list.rb b/examples/subscriptions/list.rb index c28f826..7034749 100644 --- a/examples/subscriptions/list.rb +++ b/examples/subscriptions/list.rb @@ -1 +1,5 @@ +# List all subscriptions +subscriptions = Mollie::Subscription.all + +# List all subscriptions for a customer subscriptions = Mollie::Customer::Subscription.all(customer_id: 'cst_5a2pPrwaWy') diff --git a/lib/mollie.rb b/lib/mollie.rb index fc19b45..6334ff7 100644 --- a/lib/mollie.rb +++ b/lib/mollie.rb @@ -16,8 +16,6 @@ module Mollie require 'mollie/chargeback' require 'mollie/client' require 'mollie/customer' -require 'mollie/customer/mandate' -require 'mollie/customer/subscription' require 'mollie/invoice' require 'mollie/list' require 'mollie/method' @@ -28,8 +26,11 @@ module Mollie require 'mollie/profile' require 'mollie/refund' require 'mollie/settlement' +require 'mollie/subscription' +require 'mollie/customer/mandate' require 'mollie/customer/payment' +require 'mollie/customer/subscription' require 'mollie/onboarding' require 'mollie/order/line' require 'mollie/order/refund' diff --git a/lib/mollie/customer/subscription.rb b/lib/mollie/customer/subscription.rb index 0ccfa62..aff2eb5 100644 --- a/lib/mollie/customer/subscription.rb +++ b/lib/mollie/customer/subscription.rb @@ -1,109 +1,6 @@ module Mollie class Customer - class Subscription < Base - STATUS_ACTIVE = 'active'.freeze - STATUS_PENDING = 'pending'.freeze # Waiting for a valid mandate. - STATUS_CANCELED = 'canceled'.freeze - STATUS_SUSPENDED = 'suspended'.freeze # Active, but mandate became invalid. - STATUS_COMPLETED = 'completed'.freeze - - attr_accessor :id, - :customer_id, - :mode, - :created_at, - :status, - :amount, - :times, - :times_remaining, - :interval, - :next_payment_date, - :description, - :method, - :mandate_id, - :canceled_at, - :webhook_url, - :metadata, - :application_fee, - :_links - - alias links _links - - def active? - status == STATUS_ACTIVE - end - - def pending? - status == STATUS_PENDING - end - - def suspended? - status == STATUS_SUSPENDED - end - - def canceled? - status == STATUS_CANCELED - end - - def completed? - status == STATUS_COMPLETED - end - - def created_at=(created_at) - @created_at = begin - Time.parse(created_at.to_s) - rescue StandardError - nil - end - end - - def canceled_at=(canceled_at) - @canceled_at = begin - Time.parse(canceled_at.to_s) - rescue StandardError - nil - end - end - - def amount=(amount) - @amount = Mollie::Amount.new(amount) - end - - def times=(times) - @times = times.to_i - end - - def next_payment_date=(next_payment_date) - @next_payment_date = begin - Date.parse(next_payment_date) - rescue StandardError - nil - end - end - - def customer(options = {}) - Customer.get(customer_id, options) - end - - def payments(options = {}) - resource_url = Util.extract_url(links, 'payments') - return if resource_url.nil? - response = Mollie::Client.instance.perform_http_call('GET', resource_url, nil, {}, options) - Mollie::List.new(response, Payment) - end - - def metadata=(metadata) - @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) - end - - def application_fee=(application_fee) - amount = Amount.new(application_fee['amount']) - description = application_fee['description'] - - @application_fee = OpenStruct.new( - amount: amount, - description: description - ) - end + class Subscription < Mollie::Subscription end end end diff --git a/lib/mollie/subscription.rb b/lib/mollie/subscription.rb new file mode 100644 index 0000000..8a145dc --- /dev/null +++ b/lib/mollie/subscription.rb @@ -0,0 +1,107 @@ +module Mollie + class Subscription < Base + STATUS_ACTIVE = 'active'.freeze + STATUS_PENDING = 'pending'.freeze # Waiting for a valid mandate. + STATUS_CANCELED = 'canceled'.freeze + STATUS_SUSPENDED = 'suspended'.freeze # Active, but mandate became invalid. + STATUS_COMPLETED = 'completed'.freeze + + attr_accessor :id, + :customer_id, + :mode, + :created_at, + :status, + :amount, + :times, + :times_remaining, + :interval, + :next_payment_date, + :description, + :method, + :mandate_id, + :canceled_at, + :webhook_url, + :metadata, + :application_fee, + :_links + + alias links _links + + def active? + status == STATUS_ACTIVE + end + + def pending? + status == STATUS_PENDING + end + + def suspended? + status == STATUS_SUSPENDED + end + + def canceled? + status == STATUS_CANCELED + end + + def completed? + status == STATUS_COMPLETED + end + + def created_at=(created_at) + @created_at = begin + Time.parse(created_at.to_s) + rescue StandardError + nil + end + end + + def canceled_at=(canceled_at) + @canceled_at = begin + Time.parse(canceled_at.to_s) + rescue StandardError + nil + end + end + + def amount=(amount) + @amount = Mollie::Amount.new(amount) + end + + def times=(times) + @times = times.to_i + end + + def next_payment_date=(next_payment_date) + @next_payment_date = begin + Date.parse(next_payment_date) + rescue StandardError + nil + end + end + + def customer(options = {}) + Customer.get(customer_id, options) + end + + def payments(options = {}) + resource_url = Util.extract_url(links, 'payments') + return if resource_url.nil? + response = Mollie::Client.instance.perform_http_call('GET', resource_url, nil, {}, options) + Mollie::List.new(response, Mollie::Payment) + end + + def metadata=(metadata) + @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) + end + + def application_fee=(application_fee) + amount = Amount.new(application_fee['amount']) + description = application_fee['description'] + + @application_fee = OpenStruct.new( + amount: amount, + description: description + ) + end + end +end diff --git a/test/mollie/customer/subscription_test.rb b/test/mollie/customer/subscription_test.rb index ed94c32..86492aa 100644 --- a/test/mollie/customer/subscription_test.rb +++ b/test/mollie/customer/subscription_test.rb @@ -154,8 +154,8 @@ def test_get_payments subscription = Customer::Subscription.get('sub_8JfGzs6v3K', customer_id: 'cst_8wmqcHMN4U') payments = subscription.payments - assert_equal payments.klass, Payment - assert_equal payments.first.id, 'tr_DtKxVP2AgW' + assert_equal Mollie::Payment, payments.klass + assert_equal 'tr_DtKxVP2AgW', payments.first.id end end end From 80bf9c5e4d54fa0e4f2d4f74da9d5b3cdb03e320 Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 26 Jan 2020 23:39:34 +0100 Subject: [PATCH 6/6] Method: add `include=pricing` example --- examples/methods/get.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/methods/get.rb b/examples/methods/get.rb index 0b2d522..5a7b5c8 100644 --- a/examples/methods/get.rb +++ b/examples/methods/get.rb @@ -1,4 +1,11 @@ method = Mollie::Method.get('ideal') -# Include iDEAL issuers +# Include issuers available for the payment method (e.g. for +# iDEAL, KBC/CBC payment button or gift cards). method = Mollie::Method.get('ideal', include: 'issuers') + +# Include pricing for each payment method +method = Mollie::Method.get('ideal', include: 'pricing') + +# Include both issuers and pricing +method = Mollie::Method.get('ideal', include: 'issuers,pricing')