Skip to content

Commit

Permalink
Merge pull request #130 from mollie/changelog
Browse files Browse the repository at this point in the history
Changelog updates
  • Loading branch information
vernondegoede authored Feb 3, 2020
2 parents 88be910 + 80bf9c5 commit 893bb48
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 117 deletions.
9 changes: 8 additions & 1 deletion examples/methods/get.rb
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 7 additions & 0 deletions examples/payments/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
payment = Mollie::Payment.update(
'tr_7UhSN1zuXS',
description: 'Order #98765',
metadata: {
order_id: '98765'
}
)
4 changes: 4 additions & 0 deletions examples/subscriptions/list.rb
Original file line number Diff line number Diff line change
@@ -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')
5 changes: 3 additions & 2 deletions lib/mollie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
105 changes: 1 addition & 104 deletions lib/mollie/customer/subscription.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/mollie/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Organization < Base
:address,
:registration_number,
:vat_number,
:vat_regulation,
:_links

alias links _links
Expand Down
7 changes: 6 additions & 1 deletion lib/mollie/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class Refund < Base

attr_accessor :id,
:amount,
:settlement_id,
:settlement_amount,
:status,
:lines,
:payment_id,
:order_id,
:description,
:metadata,
:created_at,
:_links

Expand Down Expand Up @@ -47,6 +49,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
Expand All @@ -64,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
Expand Down
107 changes: 107 additions & 0 deletions lib/mollie/subscription.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/fixtures/refunds/get.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions test/mollie/customer/subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/mollie/organization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

Expand Down
16 changes: 9 additions & 7 deletions test/mollie/refund_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})

Expand Down Expand Up @@ -180,5 +174,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

0 comments on commit 893bb48

Please sign in to comment.