processout 1.2.2 → 2.0.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 +4 -4
- data/lib/processout.rb +37 -0
- data/lib/processout/activity.rb +15 -0
- data/lib/processout/addon.rb +352 -0
- data/lib/processout/api_request.rb +274 -0
- data/lib/processout/api_version.rb +82 -0
- data/lib/processout/authorization_request.rb +62 -17
- data/lib/processout/card.rb +137 -10
- data/lib/processout/coupon.rb +22 -17
- data/lib/processout/customer.rb +180 -14
- data/lib/processout/discount.rb +69 -19
- data/lib/processout/dunning_action.rb +72 -0
- data/lib/processout/event.rb +15 -0
- data/lib/processout/gateway.rb +30 -0
- data/lib/processout/gateway_configuration.rb +90 -0
- data/lib/processout/gateway_request.rb +26 -0
- data/lib/processout/invoice.rb +119 -62
- data/lib/processout/invoice_detail.rb +20 -0
- data/lib/processout/networking/request.rb +1 -2
- data/lib/processout/plan.rb +15 -0
- data/lib/processout/product.rb +15 -0
- data/lib/processout/project.rb +100 -0
- data/lib/processout/refund.rb +32 -7
- data/lib/processout/subscription.rb +267 -117
- data/lib/processout/token.rb +62 -2
- data/lib/processout/transaction.rb +159 -0
- data/lib/processout/transaction_operation.rb +248 -0
- data/lib/processout/version.rb +1 -1
- data/lib/processout/webhook.rb +30 -0
- data/lib/processout/webhook_endpoint.rb +135 -0
- metadata +9 -2
@@ -0,0 +1,26 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module ProcessOut
|
5
|
+
class GatewayRequest
|
6
|
+
attr_accessor :gateway_configuration_id, :method, :url, :headers, :body
|
7
|
+
|
8
|
+
def initialize(gateway_configuration_id, data = {})
|
9
|
+
self.gateway_configuration_id = gateway_configuration_id
|
10
|
+
self.method = data.fetch(:method, nil)
|
11
|
+
self.url = data.fetch(:url, nil)
|
12
|
+
self.headers = data.fetch(:headers, {})
|
13
|
+
self.body = data.fetch(:body, nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"gway_req_" + Base64.strict_encode64(JSON.generate({
|
18
|
+
gateway_configuration_id: self.gateway_configuration_id,
|
19
|
+
method: self.method,
|
20
|
+
url: self.url,
|
21
|
+
headers: self.headers,
|
22
|
+
body: self.body
|
23
|
+
}))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/processout/invoice.rb
CHANGED
@@ -9,19 +9,25 @@ module ProcessOut
|
|
9
9
|
|
10
10
|
attr_reader :id
|
11
11
|
attr_reader :project
|
12
|
+
attr_reader :project_id
|
12
13
|
attr_reader :transaction
|
14
|
+
attr_reader :transaction_id
|
13
15
|
attr_reader :customer
|
16
|
+
attr_reader :customer_id
|
14
17
|
attr_reader :subscription
|
18
|
+
attr_reader :subscription_id
|
19
|
+
attr_reader :token
|
20
|
+
attr_reader :token_id
|
15
21
|
attr_reader :details
|
16
22
|
attr_reader :url
|
17
23
|
attr_reader :name
|
24
|
+
attr_reader :amount
|
25
|
+
attr_reader :currency
|
18
26
|
attr_reader :statement_descriptor
|
19
27
|
attr_reader :statement_descriptor_phone
|
20
28
|
attr_reader :statement_descriptor_city
|
21
29
|
attr_reader :statement_descriptor_company
|
22
30
|
attr_reader :statement_descriptor_url
|
23
|
-
attr_reader :amount
|
24
|
-
attr_reader :currency
|
25
31
|
attr_reader :metadata
|
26
32
|
attr_reader :return_url
|
27
33
|
attr_reader :cancel_url
|
@@ -34,6 +40,11 @@ module ProcessOut
|
|
34
40
|
end
|
35
41
|
|
36
42
|
def project=(val)
|
43
|
+
if val.nil?
|
44
|
+
@project = val
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
37
48
|
if val.instance_of? Project
|
38
49
|
@project = val
|
39
50
|
else
|
@@ -44,7 +55,16 @@ module ProcessOut
|
|
44
55
|
|
45
56
|
end
|
46
57
|
|
58
|
+
def project_id=(val)
|
59
|
+
@project_id = val
|
60
|
+
end
|
61
|
+
|
47
62
|
def transaction=(val)
|
63
|
+
if val.nil?
|
64
|
+
@transaction = val
|
65
|
+
return
|
66
|
+
end
|
67
|
+
|
48
68
|
if val.instance_of? Transaction
|
49
69
|
@transaction = val
|
50
70
|
else
|
@@ -55,7 +75,16 @@ module ProcessOut
|
|
55
75
|
|
56
76
|
end
|
57
77
|
|
78
|
+
def transaction_id=(val)
|
79
|
+
@transaction_id = val
|
80
|
+
end
|
81
|
+
|
58
82
|
def customer=(val)
|
83
|
+
if val.nil?
|
84
|
+
@customer = val
|
85
|
+
return
|
86
|
+
end
|
87
|
+
|
59
88
|
if val.instance_of? Customer
|
60
89
|
@customer = val
|
61
90
|
else
|
@@ -66,7 +95,16 @@ module ProcessOut
|
|
66
95
|
|
67
96
|
end
|
68
97
|
|
98
|
+
def customer_id=(val)
|
99
|
+
@customer_id = val
|
100
|
+
end
|
101
|
+
|
69
102
|
def subscription=(val)
|
103
|
+
if val.nil?
|
104
|
+
@subscription = val
|
105
|
+
return
|
106
|
+
end
|
107
|
+
|
70
108
|
if val.instance_of? Subscription
|
71
109
|
@subscription = val
|
72
110
|
else
|
@@ -77,7 +115,36 @@ module ProcessOut
|
|
77
115
|
|
78
116
|
end
|
79
117
|
|
118
|
+
def subscription_id=(val)
|
119
|
+
@subscription_id = val
|
120
|
+
end
|
121
|
+
|
122
|
+
def token=(val)
|
123
|
+
if val.nil?
|
124
|
+
@token = val
|
125
|
+
return
|
126
|
+
end
|
127
|
+
|
128
|
+
if val.instance_of? Token
|
129
|
+
@token = val
|
130
|
+
else
|
131
|
+
obj = Token.new(@client)
|
132
|
+
obj.fill_with_data(val)
|
133
|
+
@token = obj
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
def token_id=(val)
|
139
|
+
@token_id = val
|
140
|
+
end
|
141
|
+
|
80
142
|
def details=(val)
|
143
|
+
if val.nil?
|
144
|
+
@details = []
|
145
|
+
return
|
146
|
+
end
|
147
|
+
|
81
148
|
if val.length > 0 and val[0].instance_of? InvoiceDetail
|
82
149
|
@details = val
|
83
150
|
else
|
@@ -100,6 +167,14 @@ module ProcessOut
|
|
100
167
|
@name = val
|
101
168
|
end
|
102
169
|
|
170
|
+
def amount=(val)
|
171
|
+
@amount = val
|
172
|
+
end
|
173
|
+
|
174
|
+
def currency=(val)
|
175
|
+
@currency = val
|
176
|
+
end
|
177
|
+
|
103
178
|
def statement_descriptor=(val)
|
104
179
|
@statement_descriptor = val
|
105
180
|
end
|
@@ -120,14 +195,6 @@ module ProcessOut
|
|
120
195
|
@statement_descriptor_url = val
|
121
196
|
end
|
122
197
|
|
123
|
-
def amount=(val)
|
124
|
-
@amount = val
|
125
|
-
end
|
126
|
-
|
127
|
-
def currency=(val)
|
128
|
-
@currency = val
|
129
|
-
end
|
130
|
-
|
131
198
|
def metadata=(val)
|
132
199
|
@metadata = val
|
133
200
|
end
|
@@ -158,19 +225,25 @@ module ProcessOut
|
|
158
225
|
|
159
226
|
self.id = data.fetch(:id, nil)
|
160
227
|
self.project = data.fetch(:project, nil)
|
228
|
+
self.project_id = data.fetch(:project_id, nil)
|
161
229
|
self.transaction = data.fetch(:transaction, nil)
|
230
|
+
self.transaction_id = data.fetch(:transaction_id, nil)
|
162
231
|
self.customer = data.fetch(:customer, nil)
|
232
|
+
self.customer_id = data.fetch(:customer_id, nil)
|
163
233
|
self.subscription = data.fetch(:subscription, nil)
|
234
|
+
self.subscription_id = data.fetch(:subscription_id, nil)
|
235
|
+
self.token = data.fetch(:token, nil)
|
236
|
+
self.token_id = data.fetch(:token_id, nil)
|
164
237
|
self.details = data.fetch(:details, nil)
|
165
238
|
self.url = data.fetch(:url, nil)
|
166
239
|
self.name = data.fetch(:name, nil)
|
240
|
+
self.amount = data.fetch(:amount, nil)
|
241
|
+
self.currency = data.fetch(:currency, nil)
|
167
242
|
self.statement_descriptor = data.fetch(:statement_descriptor, nil)
|
168
243
|
self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, nil)
|
169
244
|
self.statement_descriptor_city = data.fetch(:statement_descriptor_city, nil)
|
170
245
|
self.statement_descriptor_company = data.fetch(:statement_descriptor_company, nil)
|
171
246
|
self.statement_descriptor_url = data.fetch(:statement_descriptor_url, nil)
|
172
|
-
self.amount = data.fetch(:amount, nil)
|
173
|
-
self.currency = data.fetch(:currency, nil)
|
174
247
|
self.metadata = data.fetch(:metadata, nil)
|
175
248
|
self.return_url = data.fetch(:return_url, nil)
|
176
249
|
self.cancel_url = data.fetch(:cancel_url, nil)
|
@@ -197,15 +270,33 @@ module ProcessOut
|
|
197
270
|
if data.include? "project"
|
198
271
|
self.project = data["project"]
|
199
272
|
end
|
273
|
+
if data.include? "project_id"
|
274
|
+
self.project_id = data["project_id"]
|
275
|
+
end
|
200
276
|
if data.include? "transaction"
|
201
277
|
self.transaction = data["transaction"]
|
202
278
|
end
|
279
|
+
if data.include? "transaction_id"
|
280
|
+
self.transaction_id = data["transaction_id"]
|
281
|
+
end
|
203
282
|
if data.include? "customer"
|
204
283
|
self.customer = data["customer"]
|
205
284
|
end
|
285
|
+
if data.include? "customer_id"
|
286
|
+
self.customer_id = data["customer_id"]
|
287
|
+
end
|
206
288
|
if data.include? "subscription"
|
207
289
|
self.subscription = data["subscription"]
|
208
290
|
end
|
291
|
+
if data.include? "subscription_id"
|
292
|
+
self.subscription_id = data["subscription_id"]
|
293
|
+
end
|
294
|
+
if data.include? "token"
|
295
|
+
self.token = data["token"]
|
296
|
+
end
|
297
|
+
if data.include? "token_id"
|
298
|
+
self.token_id = data["token_id"]
|
299
|
+
end
|
209
300
|
if data.include? "details"
|
210
301
|
self.details = data["details"]
|
211
302
|
end
|
@@ -215,6 +306,12 @@ module ProcessOut
|
|
215
306
|
if data.include? "name"
|
216
307
|
self.name = data["name"]
|
217
308
|
end
|
309
|
+
if data.include? "amount"
|
310
|
+
self.amount = data["amount"]
|
311
|
+
end
|
312
|
+
if data.include? "currency"
|
313
|
+
self.currency = data["currency"]
|
314
|
+
end
|
218
315
|
if data.include? "statement_descriptor"
|
219
316
|
self.statement_descriptor = data["statement_descriptor"]
|
220
317
|
end
|
@@ -230,12 +327,6 @@ module ProcessOut
|
|
230
327
|
if data.include? "statement_descriptor_url"
|
231
328
|
self.statement_descriptor_url = data["statement_descriptor_url"]
|
232
329
|
end
|
233
|
-
if data.include? "amount"
|
234
|
-
self.amount = data["amount"]
|
235
|
-
end
|
236
|
-
if data.include? "currency"
|
237
|
-
self.currency = data["currency"]
|
238
|
-
end
|
239
330
|
if data.include? "metadata"
|
240
331
|
self.metadata = data["metadata"]
|
241
332
|
end
|
@@ -264,19 +355,25 @@ module ProcessOut
|
|
264
355
|
end
|
265
356
|
self.id = data.fetch(:id, self.id)
|
266
357
|
self.project = data.fetch(:project, self.project)
|
358
|
+
self.project_id = data.fetch(:project_id, self.project_id)
|
267
359
|
self.transaction = data.fetch(:transaction, self.transaction)
|
360
|
+
self.transaction_id = data.fetch(:transaction_id, self.transaction_id)
|
268
361
|
self.customer = data.fetch(:customer, self.customer)
|
362
|
+
self.customer_id = data.fetch(:customer_id, self.customer_id)
|
269
363
|
self.subscription = data.fetch(:subscription, self.subscription)
|
364
|
+
self.subscription_id = data.fetch(:subscription_id, self.subscription_id)
|
365
|
+
self.token = data.fetch(:token, self.token)
|
366
|
+
self.token_id = data.fetch(:token_id, self.token_id)
|
270
367
|
self.details = data.fetch(:details, self.details)
|
271
368
|
self.url = data.fetch(:url, self.url)
|
272
369
|
self.name = data.fetch(:name, self.name)
|
370
|
+
self.amount = data.fetch(:amount, self.amount)
|
371
|
+
self.currency = data.fetch(:currency, self.currency)
|
273
372
|
self.statement_descriptor = data.fetch(:statement_descriptor, self.statement_descriptor)
|
274
373
|
self.statement_descriptor_phone = data.fetch(:statement_descriptor_phone, self.statement_descriptor_phone)
|
275
374
|
self.statement_descriptor_city = data.fetch(:statement_descriptor_city, self.statement_descriptor_city)
|
276
375
|
self.statement_descriptor_company = data.fetch(:statement_descriptor_company, self.statement_descriptor_company)
|
277
376
|
self.statement_descriptor_url = data.fetch(:statement_descriptor_url, self.statement_descriptor_url)
|
278
|
-
self.amount = data.fetch(:amount, self.amount)
|
279
|
-
self.currency = data.fetch(:currency, self.currency)
|
280
377
|
self.metadata = data.fetch(:metadata, self.metadata)
|
281
378
|
self.return_url = data.fetch(:return_url, self.return_url)
|
282
379
|
self.cancel_url = data.fetch(:cancel_url, self.cancel_url)
|
@@ -296,7 +393,6 @@ module ProcessOut
|
|
296
393
|
request = Request.new(@client)
|
297
394
|
path = "/invoices/" + CGI.escape(@id) + "/authorize"
|
298
395
|
data = {
|
299
|
-
"authorize_only" => options.fetch(:authorize_only, nil),
|
300
396
|
"synchronous" => options.fetch(:synchronous, nil),
|
301
397
|
"source" => source
|
302
398
|
}
|
@@ -476,6 +572,7 @@ module ProcessOut
|
|
476
572
|
request = Request.new(@client)
|
477
573
|
path = "/invoices"
|
478
574
|
data = {
|
575
|
+
"customer_id" => @customer_id,
|
479
576
|
"name" => @name,
|
480
577
|
"amount" => @amount,
|
481
578
|
"currency" => @currency,
|
@@ -487,47 +584,7 @@ module ProcessOut
|
|
487
584
|
"statement_descriptor_company" => @statement_descriptor_company,
|
488
585
|
"statement_descriptor_url" => @statement_descriptor_url,
|
489
586
|
"return_url" => @return_url,
|
490
|
-
"cancel_url" => @cancel_url
|
491
|
-
"customer_id" => options.fetch(:customer_id, nil)
|
492
|
-
}
|
493
|
-
|
494
|
-
response = Response.new(request.post(path, data, options))
|
495
|
-
return_values = Array.new
|
496
|
-
|
497
|
-
body = response.body
|
498
|
-
body = body["invoice"]
|
499
|
-
|
500
|
-
|
501
|
-
return_values.push(self.fill_with_data(body))
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
return_values[0]
|
506
|
-
end
|
507
|
-
|
508
|
-
# Create a new invoice for the given customer ID.
|
509
|
-
# Params:
|
510
|
-
# +customer_id+:: ID of the customer
|
511
|
-
# +options+:: +Hash+ of options
|
512
|
-
def create_for_customer(customer_id, options = {})
|
513
|
-
self.prefill(options)
|
514
|
-
|
515
|
-
request = Request.new(@client)
|
516
|
-
path = "/invoices"
|
517
|
-
data = {
|
518
|
-
"name" => @name,
|
519
|
-
"amount" => @amount,
|
520
|
-
"currency" => @currency,
|
521
|
-
"metadata" => @metadata,
|
522
|
-
"details" => @details,
|
523
|
-
"statement_descriptor" => @statement_descriptor,
|
524
|
-
"statement_descriptor_phone" => @statement_descriptor_phone,
|
525
|
-
"statement_descriptor_city" => @statement_descriptor_city,
|
526
|
-
"statement_descriptor_company" => @statement_descriptor_company,
|
527
|
-
"statement_descriptor_url" => @statement_descriptor_url,
|
528
|
-
"return_url" => @return_url,
|
529
|
-
"cancel_url" => @cancel_url,
|
530
|
-
"customer_id" => customer_id
|
587
|
+
"cancel_url" => @cancel_url
|
531
588
|
}
|
532
589
|
|
533
590
|
response = Response.new(request.post(path, data, options))
|
@@ -7,11 +7,17 @@ require "processout/networking/response"
|
|
7
7
|
module ProcessOut
|
8
8
|
class InvoiceDetail
|
9
9
|
|
10
|
+
attr_reader :name
|
10
11
|
attr_reader :type
|
11
12
|
attr_reader :amount
|
13
|
+
attr_reader :quantity
|
12
14
|
attr_reader :metadata
|
13
15
|
|
14
16
|
|
17
|
+
def name=(val)
|
18
|
+
@name = val
|
19
|
+
end
|
20
|
+
|
15
21
|
def type=(val)
|
16
22
|
@type = val
|
17
23
|
end
|
@@ -20,6 +26,10 @@ module ProcessOut
|
|
20
26
|
@amount = val
|
21
27
|
end
|
22
28
|
|
29
|
+
def quantity=(val)
|
30
|
+
@quantity = val
|
31
|
+
end
|
32
|
+
|
23
33
|
def metadata=(val)
|
24
34
|
@metadata = val
|
25
35
|
end
|
@@ -32,8 +42,10 @@ module ProcessOut
|
|
32
42
|
def initialize(client, data = {})
|
33
43
|
@client = client
|
34
44
|
|
45
|
+
self.name = data.fetch(:name, nil)
|
35
46
|
self.type = data.fetch(:type, nil)
|
36
47
|
self.amount = data.fetch(:amount, nil)
|
48
|
+
self.quantity = data.fetch(:quantity, nil)
|
37
49
|
self.metadata = data.fetch(:metadata, nil)
|
38
50
|
|
39
51
|
end
|
@@ -50,12 +62,18 @@ module ProcessOut
|
|
50
62
|
if data.nil?
|
51
63
|
return self
|
52
64
|
end
|
65
|
+
if data.include? "name"
|
66
|
+
self.name = data["name"]
|
67
|
+
end
|
53
68
|
if data.include? "type"
|
54
69
|
self.type = data["type"]
|
55
70
|
end
|
56
71
|
if data.include? "amount"
|
57
72
|
self.amount = data["amount"]
|
58
73
|
end
|
74
|
+
if data.include? "quantity"
|
75
|
+
self.quantity = data["quantity"]
|
76
|
+
end
|
59
77
|
if data.include? "metadata"
|
60
78
|
self.metadata = data["metadata"]
|
61
79
|
end
|
@@ -70,8 +88,10 @@ module ProcessOut
|
|
70
88
|
if data.nil?
|
71
89
|
return self
|
72
90
|
end
|
91
|
+
self.name = data.fetch(:name, self.name)
|
73
92
|
self.type = data.fetch(:type, self.type)
|
74
93
|
self.amount = data.fetch(:amount, self.amount)
|
94
|
+
self.quantity = data.fetch(:quantity, self.quantity)
|
75
95
|
self.metadata = data.fetch(:metadata, self.metadata)
|
76
96
|
|
77
97
|
self
|
@@ -12,7 +12,7 @@ module ProcessOut
|
|
12
12
|
def apply_headers(req, options)
|
13
13
|
req.basic_auth @client.project_id, @client.project_secret
|
14
14
|
req.content_type = "application/json"
|
15
|
-
req["API-Version"] = "1.
|
15
|
+
req["API-Version"] = "1.4.0.0"
|
16
16
|
req["User-Agent"] = "utf-8"
|
17
17
|
|
18
18
|
unless options.nil?
|
@@ -28,7 +28,6 @@ module ProcessOut
|
|
28
28
|
data["expand"] = options.fetch(:expand, [])
|
29
29
|
data["filter"] = options.fetch(:filter, "")
|
30
30
|
data["limit"] = options.fetch(:limit, "")
|
31
|
-
data["page"] = options.fetch(:page, "")
|
32
31
|
data["end_before"] = options.fetch(:end_before, "")
|
33
32
|
data["start_after"] = options.fetch(:start_after, "")
|
34
33
|
end
|
data/lib/processout/plan.rb
CHANGED
@@ -9,6 +9,7 @@ module ProcessOut
|
|
9
9
|
|
10
10
|
attr_reader :id
|
11
11
|
attr_reader :project
|
12
|
+
attr_reader :project_id
|
12
13
|
attr_reader :url
|
13
14
|
attr_reader :name
|
14
15
|
attr_reader :amount
|
@@ -27,6 +28,11 @@ module ProcessOut
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def project=(val)
|
31
|
+
if val.nil?
|
32
|
+
@project = val
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
30
36
|
if val.instance_of? Project
|
31
37
|
@project = val
|
32
38
|
else
|
@@ -37,6 +43,10 @@ module ProcessOut
|
|
37
43
|
|
38
44
|
end
|
39
45
|
|
46
|
+
def project_id=(val)
|
47
|
+
@project_id = val
|
48
|
+
end
|
49
|
+
|
40
50
|
def url=(val)
|
41
51
|
@url = val
|
42
52
|
end
|
@@ -91,6 +101,7 @@ module ProcessOut
|
|
91
101
|
|
92
102
|
self.id = data.fetch(:id, nil)
|
93
103
|
self.project = data.fetch(:project, nil)
|
104
|
+
self.project_id = data.fetch(:project_id, nil)
|
94
105
|
self.url = data.fetch(:url, nil)
|
95
106
|
self.name = data.fetch(:name, nil)
|
96
107
|
self.amount = data.fetch(:amount, nil)
|
@@ -123,6 +134,9 @@ module ProcessOut
|
|
123
134
|
if data.include? "project"
|
124
135
|
self.project = data["project"]
|
125
136
|
end
|
137
|
+
if data.include? "project_id"
|
138
|
+
self.project_id = data["project_id"]
|
139
|
+
end
|
126
140
|
if data.include? "url"
|
127
141
|
self.url = data["url"]
|
128
142
|
end
|
@@ -169,6 +183,7 @@ module ProcessOut
|
|
169
183
|
end
|
170
184
|
self.id = data.fetch(:id, self.id)
|
171
185
|
self.project = data.fetch(:project, self.project)
|
186
|
+
self.project_id = data.fetch(:project_id, self.project_id)
|
172
187
|
self.url = data.fetch(:url, self.url)
|
173
188
|
self.name = data.fetch(:name, self.name)
|
174
189
|
self.amount = data.fetch(:amount, self.amount)
|