pr-pin 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf49a91cbc72d1af5343df37fbd964f8bb43306f26f7352918658919afec0bbc
4
- data.tar.gz: c75dd94684dc08a730a3635644b4a2a497f0073d0e00334898cc521ddf62ef2b
3
+ metadata.gz: 3f65867e3c6f97d7f757e23c199c1b167aafd1a1767587d3d3bbe08b7723b1c3
4
+ data.tar.gz: cf527404ec9820b32de96b39f9fb6c0393de564839182a7ee0806dd456c74594
5
5
  SHA512:
6
- metadata.gz: 85489fea42558f6c607f6bd5fe558b24dd0b035303171692aba94e2b992ae63102c50291f10b0e97cce142ff0cb148a2bf299ce8e4c8ff00bff534c6073eeb19
7
- data.tar.gz: 4a2cd43d7a7687153833d5e69f467fa6694257dc6c3c79e701c68df98a86bfae3c2714db99248f98215851cf1e6f16849209ffc0d5b9e976024ffabd30718eed
6
+ metadata.gz: 1b54eb6c97cb8a674d1c89ec09f11b52d0d20fbd7c85dd28f5b5ffeee6c72e6deb57fcb40840721c23e39a1103e6f9342efbd877a70f634555b175f9fb4a522c
7
+ data.tar.gz: e630995c83be98c087a628f29e41048baa1c63d86d21f0c2dd6fde2e6727994b0c8b8302c6b0b903fbe5762bb1b8d6689f1ed26e515b8bd3e9cebf4cc3fa15b7
data/README.md CHANGED
@@ -66,6 +66,10 @@ charge = PR::Pin.charges.create(
66
66
  charge.success? # => true
67
67
  charge.error? # => false
68
68
  charge # => #<PR::Pin::Struct::Charge>
69
+
70
+ # Find a charge by token
71
+ PR::Pin.charges.find('ch_1ee2d1')
72
+ # => #<PR::Pin::Struct::Charge>
69
73
  ```
70
74
 
71
75
  ### Recurring payments
@@ -88,6 +92,35 @@ subscription = PR::Pin.subscriptions.create(
88
92
  subscription.success? # => true
89
93
  subscription.error? # => false
90
94
  subscription # => #<PR::Pin::Struct::Subscription>
95
+
96
+ ledger = PR::Pin.ledger.for_subscription('sub_293857')
97
+ subscription.success? # => true
98
+ subscription.error? # => false
99
+ ledger
100
+ # => [
101
+ # #<PR::Pin::Struct::Ledger type="credit" annotation="charge_credit" amount=1026 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:50+00:00 ((2459033j,8390s,0n),+0s,2299161j)>>,
102
+ # #<PR::Pin::Struct::Ledger type="debit" annotation="interval_fee" amount=1026 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:47+00:00 ((2459033j,8387s,0n),+0s,2299161j)>>,
103
+ # #<PR::Pin::Struct::Ledger type="debit" annotation="setup_fee" amount=0 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:47+00:00 ((2459033j,8387s,0n),+0s,2299161j)>>
104
+ # ]
105
+ ```
106
+
107
+ ### Refunds
108
+ ```ruby
109
+ # List refunds (paginated)
110
+ refunds = PR::Pin.refunds.list
111
+ # => [#<PR::Pin::Struct::Refund>, ...]
112
+
113
+ # Find a specific refund
114
+ refund = PR::Pin.refunds.find('rf_1e5429')
115
+ # => #<PR::Pin::Struct::Refund>
116
+
117
+ # Create a refund for a charge
118
+ PR::Pin.refunds.create_for_charge('ch_1ee2d1')
119
+ # => #<PR::Pin::Struct::Refund>
120
+
121
+ # List all refunds by charge
122
+ PR::Pin.refunds.for_charge('ch_1ee2d1')
123
+ # => [#<PR::Pin::Struct::Refund>, ...]
91
124
  ```
92
125
 
93
126
  ### Errors - See [PR::Pin::API::Error](https://github.com/PetRescue/pr-pin/blob/master/lib/pr/pin/api/error.rb)
@@ -115,7 +148,7 @@ Coverage of https://pinpayments.com/developers/api-reference
115
148
  | Charges | PUT /charges/charge-token/capture | Captures a previously authorised charge | [:link:](https://pinpayments.com/developers/api-reference/charges#put-charges) | :x: |
116
149
  | Charges | GET /charges | Returns a paginated list of all charges | [:link:](https://pinpayments.com/developers/api-reference/charges#get-charges) | :heavy_check_mark: |
117
150
  | Charges | GET /charges/search | Returns a paginated list of charges matching the search criteria | [:link:](https://pinpayments.com/developers/api-reference/charges#search-charges) | :heavy_check_mark: |
118
- | Charges | GET /charges/charge-token | Returns the details of a charge | [:link:](https://pinpayments.com/developers/api-reference/charges#get-charge) | :x: |
151
+ | Charges | GET /charges/charge-token | Returns the details of a charge | [:link:](https://pinpayments.com/developers/api-reference/charges#get-charge) | :heavy_check_mark: |
119
152
  | Customers | POST /customers | Creates a new customer | [:link:](https://pinpayments.com/developers/api-reference/customers#post-customers) | :heavy_check_mark: |
120
153
  | Customers | GET /customers | Returns a paginated list of all customers | [:link:](https://pinpayments.com/developers/api-reference/customers#get-customers) | :heavy_check_mark: |
121
154
  | Customers | GET /customers/customer-token | Returns the details of a customer | [:link:](https://pinpayments.com/developers/api-reference/customers#get-customer) | :x: |
@@ -141,16 +174,16 @@ Coverage of https://pinpayments.com/developers/api-reference
141
174
  | Subscriptions | PUT /subscriptions/sub-token | Updates the card associated with a subscription identified by subscription token | [:link:](https://pinpayments.com/developers/api-reference/subscriptions#update-subscription) | :x: |
142
175
  | Subscriptions | DELETE /subscriptions/sub-token | Cancels the subscription identified by subscription token | [:link:](https://pinpayments.com/developers/api-reference/subscriptions#delete-subscription) | :x: |
143
176
  | Subscriptions | PUT /subscriptions/sub-token/reactivate | Reactivates the subscription identified by subscription token | [:link:](https://pinpayments.com/developers/api-reference/subscriptions#reactivate-subscription) | :x: |
144
- | Subscriptions | GET /subscriptions/sub-token/ledger | Fetch the ledger entries relating to a subscription identified by subscription token | [:link:](https://pinpayments.com/developers/api-reference/subscriptions#ledger-subscription) | :x: |
177
+ | Subscriptions | GET /subscriptions/sub-token/ledger | Fetch the ledger entries relating to a subscription identified by subscription token | [:link:](https://pinpayments.com/developers/api-reference/subscriptions#ledger-subscription) | :heavy_check_mark: |
145
178
  | Recipients | POST /recipients | Creates a new recipient | [:link:](https://pinpayments.com/developers/api-reference/recipients#post-recipients) | :x: |
146
179
  | Recipients | GET /recipients | Returns a paginated list of all recipients | [:link:](https://pinpayments.com/developers/api-reference/recipients#get-recipients) | :x: |
147
180
  | Recipients | GET /recipients/recipient-token | Returns the details of a recipient | [:link:](https://pinpayments.com/developers/api-reference/recipients#get-recipient) | :x: |
148
181
  | Recipients | PUT /recipients/recipient-token | Updates the details of a recipient | [:link:](https://pinpayments.com/developers/api-reference/recipients#put-recipient) | :x: |
149
182
  | Recipients | GET /recipients/recipient-token/transfers | Returns a paginated list of a recipient's transfers | [:link:](https://pinpayments.com/developers/api-reference/recipients#get-recipients-transfers) | :x: |
150
- | Refunds | GET /refunds | Returns a paginated list of all refunds | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-refunds) | :x: |
151
- | Refunds | GET /refunds/refund-token | Returns the details of the specified refund | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-refund) | :x: |
152
- | Refunds | POST /charges/charge-token/refunds | Creates a new refund and returns its details | [:link:](https://pinpayments.com/developers/api-reference/refunds#post-refunds) | :x: |
153
- | Refunds | GET /charges/charge-token/refunds | Returns a list of all refunds for the specified charge | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-token-refunds) | :x: |
183
+ | Refunds | GET /refunds | Returns a paginated list of all refunds | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-refunds) | :heavy_check_mark: |
184
+ | Refunds | GET /refunds/refund-token | Returns the details of the specified refund | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-refund) | :heavy_check_mark: |
185
+ | Refunds | POST /charges/charge-token/refunds | Creates a new refund and returns its details | [:link:](https://pinpayments.com/developers/api-reference/refunds#post-refunds) | :heavy_check_mark: |
186
+ | Refunds | GET /charges/charge-token/refunds | Returns a list of all refunds for the specified charge | [:link:](https://pinpayments.com/developers/api-reference/refunds#get-token-refunds) | :heavy_check_mark: |
154
187
  | Transfers | POST /transfers | Creates a new transfer | [:link:](https://pinpayments.com/developers/api-reference/transfers#post-transfers) | :x: |
155
188
  | Transfers | GET /transfers | Returns a paginated list of all transfers | [:link:](https://pinpayments.com/developers/api-reference/transfers#get-transfers) | :x: |
156
189
  | Transfers | GET /transfers/search | Returns a paginated list of transfers matching the search criteria | [:link:](https://pinpayments.com/developers/api-reference/transfers#search-transfers) | :x: |
@@ -57,10 +57,18 @@ module PR
57
57
  Repositories::Customers.new(environments[identifier])
58
58
  end
59
59
 
60
+ def ledger(identifier = :default)
61
+ Repositories::Ledger.new(environments[identifier])
62
+ end
63
+
60
64
  def plans(identifier = :default)
61
65
  Repositories::Plans.new(environments[identifier])
62
66
  end
63
67
 
68
+ def refunds(identifier = :default)
69
+ Repositories::Refunds.new(environments[identifier])
70
+ end
71
+
64
72
  def subscriptions(identifier = :default)
65
73
  Repositories::Subscriptions.new(environments[identifier])
66
74
  end
@@ -4,6 +4,7 @@ module PR
4
4
  module Commands
5
5
  class Create < ROM::HTTP::Commands::Create
6
6
  adapter :pr_pin
7
+ restrictable true
7
8
 
8
9
  def execute(*args, &block)
9
10
  relation.new(super.map(&:to_h)).to_a
@@ -12,6 +13,7 @@ module PR
12
13
 
13
14
  class Update < ROM::HTTP::Commands::Update
14
15
  adapter :pr_pin
16
+ restrictable true
15
17
 
16
18
  def execute(*args, &block)
17
19
  relation.new(super.map(&:to_h)).to_a
@@ -20,6 +22,7 @@ module PR
20
22
 
21
23
  class Delete < ROM::HTTP::Commands::Delete
22
24
  adapter :pr_pin
25
+ restrictable true
23
26
  end
24
27
  end
25
28
  end
@@ -0,0 +1,19 @@
1
+ module PR
2
+ module Pin
3
+ module Relations
4
+ class Ledger < ROM::Relation[:pr_pin]
5
+ schema(:ledger) do
6
+ attribute :type, Types::Strict::String
7
+ attribute :annotation, Types::Strict::String
8
+ attribute :amount, Types::Strict::Integer
9
+ attribute :currency, Types::Strict::String
10
+ attribute :created_at, Types::JSON::DateTime
11
+ end
12
+
13
+ def for_subscription(token)
14
+ with_base_path("/subscriptions/#{token}/ledger")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module PR
2
+ module Pin
3
+ module Relations
4
+ class Refunds < ROM::Relation[:pr_pin]
5
+ schema(:refunds) do
6
+ attribute :token, Types::Strict::String
7
+ attribute :success, Types::Bool.optional
8
+ attribute :amount, Types::Strict::Integer
9
+ attribute :currency, Types::Strict::String
10
+ attribute :charge, Types::Strict::String
11
+ attribute :error_message, Types::Strict::String.optional
12
+ attribute :status_message, Types::Strict::String
13
+ attribute :created_at, Types::JSON::DateTime
14
+ end
15
+
16
+ def for_charge(token)
17
+ with_base_path("/charges/#{token}/refunds")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,7 @@ module PR
5
5
  schema(:subscriptions) do
6
6
  attribute :state, Types::Strict::String
7
7
  attribute :next_billing_date, Types::JSON::DateTime
8
- attribute :active_interval_started_at, Types::JSON::DateTime
8
+ attribute :active_interval_started_at, Types::JSON::DateTime.optional
9
9
  attribute :active_interval_finishes_at, Types::JSON::DateTime.optional
10
10
  attribute :cancelled_at, Types::JSON::DateTime.optional
11
11
  attribute :created_at, Types::JSON::DateTime
@@ -6,5 +6,7 @@ require 'pr/pin/struct'
6
6
  require 'pr/pin/repositories/concerns/common'
7
7
  require 'pr/pin/repositories/charges'
8
8
  require 'pr/pin/repositories/customers'
9
+ require 'pr/pin/repositories/ledger'
9
10
  require 'pr/pin/repositories/plans'
11
+ require 'pr/pin/repositories/refunds'
10
12
  require 'pr/pin/repositories/subscriptions'
@@ -4,6 +4,12 @@ module PR
4
4
  class Charges < ROM::Repository[:charges]
5
5
  include Concerns::Common
6
6
 
7
+ def find(token)
8
+ relation = root.with_path(token)
9
+
10
+ API::Result.wrap(relation) { relation.one }
11
+ end
12
+
7
13
  def search(**params)
8
14
  relation = root.append_path('search').with_params(params)
9
15
 
@@ -0,0 +1,18 @@
1
+ module PR
2
+ module Pin
3
+ module Repositories
4
+ class Ledger < ROM::Repository[:ledger]
5
+ struct_namespace PR::Pin::Struct
6
+
7
+ def for_subscription(token, page: 1, per_page: nil)
8
+ relation = root.for_subscription(token).with_params(
9
+ page: page,
10
+ per_page: per_page
11
+ )
12
+
13
+ API::PaginatedResult.wrap(relation) { relation.paginate }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ module PR
2
+ module Pin
3
+ module Repositories
4
+ class Refunds < ROM::Repository[:refunds]
5
+ struct_namespace PR::Pin::Struct
6
+
7
+ def list(page: 1, per_page: nil)
8
+ relation = root.with_params(
9
+ page: page,
10
+ per_page: per_page
11
+ )
12
+
13
+ API::PaginatedResult.wrap(relation) { relation.paginate }
14
+ end
15
+
16
+ def find(token)
17
+ relation = root.with_path(token)
18
+
19
+ API::Result.wrap(relation) { relation.one }
20
+ end
21
+
22
+ def create_for_charge(token, *args)
23
+ relation = root.for_charge(token)
24
+
25
+ API::Result.wrap(relation) do
26
+ relation.command(:create).call(*args)
27
+ end
28
+ end
29
+
30
+ def for_charge(token, page: 1, per_page: nil)
31
+ relation = root.for_charge(token).with_params(
32
+ page: page,
33
+ per_page: per_page
34
+ )
35
+
36
+ API::PaginatedResult.wrap(relation) { relation.paginate }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module PR
2
2
  module Pin
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pr-pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AMHOL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -192,13 +192,17 @@ files:
192
192
  - lib/pr/pin/inflector.rb
193
193
  - lib/pr/pin/relations/charges.rb
194
194
  - lib/pr/pin/relations/customers.rb
195
+ - lib/pr/pin/relations/ledger.rb
195
196
  - lib/pr/pin/relations/plans.rb
197
+ - lib/pr/pin/relations/refunds.rb
196
198
  - lib/pr/pin/relations/subscriptions.rb
197
199
  - lib/pr/pin/repositories.rb
198
200
  - lib/pr/pin/repositories/charges.rb
199
201
  - lib/pr/pin/repositories/concerns/common.rb
200
202
  - lib/pr/pin/repositories/customers.rb
203
+ - lib/pr/pin/repositories/ledger.rb
201
204
  - lib/pr/pin/repositories/plans.rb
205
+ - lib/pr/pin/repositories/refunds.rb
202
206
  - lib/pr/pin/repositories/subscriptions.rb
203
207
  - lib/pr/pin/struct.rb
204
208
  - lib/pr/pin/types.rb