payload-api 0.4.1 → 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 +4 -4
- data/.github/workflows/test.yml +2 -0
- data/LICENSE +1 -1
- data/README.md +23 -2
- data/lib/payload/arm/attr.rb +169 -0
- data/lib/payload/arm/object.rb +44 -1
- data/lib/payload/arm/request.rb +66 -6
- data/lib/payload/arm/session.rb +13 -9
- data/lib/payload/exceptions.rb +15 -0
- data/lib/payload/objects.rb +81 -18
- data/lib/payload/version.rb +2 -2
- data/lib/payload.rb +15 -5
- data/spec/objects/v1/access_token_spec.rb +19 -0
- data/spec/objects/v1/account_spec.rb +97 -0
- data/spec/objects/v1/billing_spec.rb +54 -0
- data/spec/objects/v1/invoice_spec.rb +53 -0
- data/spec/objects/v1/payment_link_spec.rb +50 -0
- data/spec/objects/v1/payment_method_spec.rb +106 -0
- data/spec/objects/{payment_spec.rb → v1/payment_spec.rb} +5 -6
- data/spec/objects/v1/session_spec.rb +89 -0
- data/spec/objects/v1/transaction_spec.rb +55 -0
- data/spec/objects/v2/account_spec.rb +211 -0
- data/spec/objects/v2/invoice_spec.rb +53 -0
- data/spec/objects/v2/payment_method_spec.rb +106 -0
- data/spec/objects/v2/transaction_spec.rb +48 -0
- data/spec/payload/arm/arm_request_query_spec.rb +226 -0
- data/spec/payload/arm/attr_spec.rb +216 -0
- data/spec/payload/arm/object_spec.rb +114 -0
- data/spec/payload/arm/request_format_integration_spec.rb +166 -0
- data/spec/payload/arm/request_spec.rb +259 -1
- data/spec/payload/arm/session_spec.rb +40 -0
- data/spec/payload/exceptions_spec.rb +82 -0
- data/spec/support/helpers/v1_helpers.rb +159 -0
- data/spec/support/helpers/v2_helpers.rb +205 -0
- data/spec/support/helpers.rb +15 -0
- data/spec/support/helpers_spec.rb +21 -0
- metadata +28 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74c2fd7f99fba4cf6b0f1950d013debc81c56629a5b280e7ac79e4e4abd88838
|
|
4
|
+
data.tar.gz: abf8b305b33a0e9a5241f5664807842989b7d423781f35606607298c9297d35a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e34c4a1a585078565d876af179d8e9b3344888ca44a08f9465ac2e740f5f112990d8b7564b7c0394e21dc4eae22c9b5e0e804850c23cb39d5ffd789ad055319
|
|
7
|
+
data.tar.gz: ad8721f83c061113c6abcf4e26f7077e9c07b7a4d34b60d8cdaa9d4f61ad599443cc1e8511d46983d7acd368601b6596b42cd6cef9509dd3cc4a0a89c9492202
|
data/.github/workflows/test.yml
CHANGED
data/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Payload (http://payload.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -7,13 +7,13 @@ A RubyGem for integrating [Payload](https://payload.com).
|
|
|
7
7
|
To install using [Bundler](https://bundler.io):
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
|
-
gem 'payload-api', '~> 0.
|
|
10
|
+
gem 'payload-api', '~> 0.5.0'
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
To install using gem:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
gem install payload
|
|
16
|
+
gem install payload-api
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Get Started
|
|
@@ -34,6 +34,27 @@ require 'payload'
|
|
|
34
34
|
Payload.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### API Versioning
|
|
38
|
+
|
|
39
|
+
The Payload API supports multiple versions. You can specify which version to use when making requests:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'payload'
|
|
43
|
+
Payload.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE'
|
|
44
|
+
Payload.api_version = 'v2' # Use API v2
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or with sessions:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
pl = Payload::Session.new(
|
|
51
|
+
'secret_key_3bW9JMZtPVDOfFNzwRdfE',
|
|
52
|
+
api_version: 'v2'
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
API v2 introduces new objects including `Profile`, `Intent`, `Entity`, `Transfer`, `ProcessingAgreement`, and more. See the [Payload API Documentation](https://docs.payload.com) for details on API versions.
|
|
57
|
+
|
|
37
58
|
### Creating an Object
|
|
38
59
|
|
|
39
60
|
Interfacing with the Payload API is done primarily through Payload Objects. Below is an example of
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Payload
|
|
4
|
+
class ARMFilter
|
|
5
|
+
attr_reader :attr, :opval, :val
|
|
6
|
+
|
|
7
|
+
def initialize(attr, val)
|
|
8
|
+
@attr = attr.to_s
|
|
9
|
+
@val = val
|
|
10
|
+
@opval = self.class.op + val.to_s
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.op
|
|
14
|
+
''
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def |(other)
|
|
18
|
+
raise TypeError, 'invalid type' unless other.is_a?(Payload::ARMFilter)
|
|
19
|
+
raise ArgumentError, '`or` only works on the same attribute' if other.attr != @attr
|
|
20
|
+
joined = [@opval, other.opval].join('|')
|
|
21
|
+
Payload::ARMEqual.new(@attr, joined)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ARMEqual < ARMFilter
|
|
26
|
+
def self.op
|
|
27
|
+
''
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class ARMNotEqual < ARMFilter
|
|
32
|
+
def self.op
|
|
33
|
+
'!'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class ARMGreaterThan < ARMFilter
|
|
38
|
+
def self.op
|
|
39
|
+
'>'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class ARMLessThan < ARMFilter
|
|
44
|
+
def self.op
|
|
45
|
+
'<'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class ARMGreaterThanEqual < ARMFilter
|
|
50
|
+
def self.op
|
|
51
|
+
'>='
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class ARMLessThanEqual < ARMFilter
|
|
56
|
+
def self.op
|
|
57
|
+
'<='
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class ARMContains < ARMFilter
|
|
62
|
+
def self.op
|
|
63
|
+
'?*'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Root proxy for pl.attr so that pl.attr.name returns an Attr (not Class#name).
|
|
68
|
+
# Session#attr returns this instead of the Attr class to avoid Class/Module methods (e.g. .name) shadowing attribute names.
|
|
69
|
+
class AttrRoot
|
|
70
|
+
def method_missing(name, *args)
|
|
71
|
+
if args.size == 1 && args[0].is_a?(Symbol)
|
|
72
|
+
inner = Attr.new(name.to_s)
|
|
73
|
+
Attr.new(args[0].to_s, inner).call
|
|
74
|
+
else
|
|
75
|
+
Attr.new(name.to_s)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def respond_to_missing?(name, include_private = false)
|
|
80
|
+
true
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Attribute DSL for select/group_by/order_by and filter expressions.
|
|
85
|
+
# - pl.attr.id -> "id"
|
|
86
|
+
# - pl.attr.created_at(:month) -> "month(created_at)"
|
|
87
|
+
# - pl.attr.amount(:sum) -> "sum(amount)"
|
|
88
|
+
# - pl.attr.sender.account_id -> "sender[account_id]"
|
|
89
|
+
class Attr
|
|
90
|
+
attr_reader :param, :parent
|
|
91
|
+
|
|
92
|
+
class << self
|
|
93
|
+
def method_missing(name, *args)
|
|
94
|
+
new(name.to_s)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def respond_to_missing?(name, include_private = false)
|
|
98
|
+
true
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def initialize(param, parent = nil)
|
|
103
|
+
@param = param.to_s
|
|
104
|
+
@parent = parent
|
|
105
|
+
@is_method = false
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def key
|
|
109
|
+
@parent ? "#{@parent.key}[#{@param}]" : @param
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def to_s
|
|
113
|
+
@is_method ? "#{@param}(#{@parent.key})" : key
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def strip
|
|
117
|
+
to_s.strip
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def method_missing(name, *args)
|
|
121
|
+
raise "cannot get attr of method" if @is_method
|
|
122
|
+
|
|
123
|
+
if args.size == 1 && args[0].is_a?(Symbol)
|
|
124
|
+
inner = Attr.new(name.to_s, self)
|
|
125
|
+
Attr.new(args[0].to_s, inner).call
|
|
126
|
+
else
|
|
127
|
+
Attr.new(name.to_s, self)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def respond_to_missing?(name, include_private = false)
|
|
132
|
+
true
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Mark attribute as a function call (e.g. .month(), .sum())
|
|
136
|
+
def call
|
|
137
|
+
@is_method = true
|
|
138
|
+
self
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def ==(other)
|
|
142
|
+
ARMEqual.new(self, other)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def !=(other)
|
|
146
|
+
ARMNotEqual.new(self, other)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def >(other)
|
|
150
|
+
ARMGreaterThan.new(self, other)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def <(other)
|
|
154
|
+
ARMLessThan.new(self, other)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def >=(other)
|
|
158
|
+
ARMGreaterThanEqual.new(self, other)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def <=(other)
|
|
162
|
+
ARMLessThanEqual.new(self, other)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def contains(other)
|
|
166
|
+
ARMContains.new(self, other)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
data/lib/payload/arm/object.rb
CHANGED
|
@@ -30,6 +30,25 @@ module Payload
|
|
|
30
30
|
return @cls.get(id, :session => @session)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def select(*args, **data)
|
|
34
|
+
@cls.select(*args, **data, session: @session)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def order_by(*args, **data)
|
|
38
|
+
@cls.order_by(*args, **data, session: @session)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def limit(n, **data)
|
|
42
|
+
@cls.limit(n, **data, session: @session)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def offset(n, **data)
|
|
46
|
+
@cls.offset(n, **data, session: @session)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def group_by(*args, **data)
|
|
50
|
+
@cls.group_by(*args, **data, session: @session)
|
|
51
|
+
end
|
|
33
52
|
end
|
|
34
53
|
|
|
35
54
|
class ARMObject
|
|
@@ -99,7 +118,7 @@ module Payload
|
|
|
99
118
|
end
|
|
100
119
|
|
|
101
120
|
def [](key)
|
|
102
|
-
return @data[key]
|
|
121
|
+
return @data[key.to_s]
|
|
103
122
|
end
|
|
104
123
|
|
|
105
124
|
def _get_request()
|
|
@@ -114,6 +133,22 @@ module Payload
|
|
|
114
133
|
return self._get_request().select(*args, **data)
|
|
115
134
|
end
|
|
116
135
|
|
|
136
|
+
def self.order_by(*args, **data)
|
|
137
|
+
self._get_request().order_by(*args, **data)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def self.limit(n, **data)
|
|
141
|
+
self._get_request().limit(n)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def self.offset(n, **data)
|
|
145
|
+
self._get_request().offset(n)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def self.group_by(*args, **data)
|
|
149
|
+
self._get_request().group_by(*args, **data)
|
|
150
|
+
end
|
|
151
|
+
|
|
117
152
|
def self.filter_by(*args, **data)
|
|
118
153
|
session = data[:session]
|
|
119
154
|
data.delete(:session)
|
|
@@ -150,6 +185,10 @@ module Payload
|
|
|
150
185
|
return _get_request()._request('Delete', id: self.id)
|
|
151
186
|
end
|
|
152
187
|
|
|
188
|
+
def json
|
|
189
|
+
to_json
|
|
190
|
+
end
|
|
191
|
+
|
|
153
192
|
def to_json(*args)
|
|
154
193
|
serialized = {}
|
|
155
194
|
if self.class.poly
|
|
@@ -158,5 +197,9 @@ module Payload
|
|
|
158
197
|
serialized.merge!(@data)
|
|
159
198
|
return serialized.to_json(*args)
|
|
160
199
|
end
|
|
200
|
+
|
|
201
|
+
def respond_to_missing?(name, include_private = false)
|
|
202
|
+
@data && @data.key?(name.to_s) || super
|
|
203
|
+
end
|
|
161
204
|
end
|
|
162
205
|
end
|
data/lib/payload/arm/request.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "payload/exceptions"
|
|
2
2
|
require "payload/utils"
|
|
3
|
+
require "payload/arm/attr"
|
|
3
4
|
require "net/http"
|
|
4
5
|
require "uri"
|
|
5
6
|
require "json"
|
|
@@ -12,28 +13,65 @@ module Payload
|
|
|
12
13
|
@cls = cls
|
|
13
14
|
@session = session || Payload::Session.new(Payload::api_key, Payload::api_url)
|
|
14
15
|
@filters = {}
|
|
16
|
+
@group_by = []
|
|
17
|
+
@order_by = []
|
|
18
|
+
@limit = nil
|
|
19
|
+
@offset = nil
|
|
20
|
+
@filter_objects = []
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
def select(*args, **data)
|
|
18
|
-
@filters['fields'] = args.map {|a| a.strip }.join(',')
|
|
19
|
-
|
|
24
|
+
@filters['fields'] = args.map { |a| a.strip }.join(',')
|
|
20
25
|
return self
|
|
21
26
|
end
|
|
22
27
|
|
|
28
|
+
def group_by(*args, **data)
|
|
29
|
+
@group_by.concat(args)
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def order_by(*args, **data)
|
|
34
|
+
@order_by.concat(args)
|
|
35
|
+
self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def limit(n)
|
|
39
|
+
@limit = n
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def offset(n)
|
|
44
|
+
@offset = n
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
|
|
23
48
|
def filter_by(*args, **data)
|
|
49
|
+
args.each do |f|
|
|
50
|
+
@filter_objects << f if f.respond_to?(:attr) && f.respond_to?(:opval)
|
|
51
|
+
end
|
|
24
52
|
if !@cls.nil? && @cls.poly
|
|
25
53
|
data = data.merge(@cls.poly)
|
|
26
54
|
end
|
|
27
|
-
|
|
28
55
|
@filters = @filters.merge(data)
|
|
29
|
-
|
|
30
56
|
return self
|
|
31
57
|
end
|
|
32
58
|
|
|
33
59
|
def all()
|
|
60
|
+
# TODO: I don't think this applies the @poly variable as intended?
|
|
34
61
|
return self._request('Get')
|
|
35
62
|
end
|
|
36
63
|
|
|
64
|
+
def [](key)
|
|
65
|
+
case key
|
|
66
|
+
when Range
|
|
67
|
+
raise ArgumentError, 'Negative slice indices not supported' if key.begin && key.begin < 0
|
|
68
|
+
raise ArgumentError, 'Negative slice indices not supported' if key.end && key.end < 0
|
|
69
|
+
offset(key.begin).limit(key.size).all()
|
|
70
|
+
else
|
|
71
|
+
raise TypeError, "invalid key or index: #{key.inspect}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
37
75
|
def get(id)
|
|
38
76
|
if id.nil? || id.empty?
|
|
39
77
|
throw 'id cannot be empty'
|
|
@@ -126,6 +164,16 @@ module Payload
|
|
|
126
164
|
http.request(request)
|
|
127
165
|
end
|
|
128
166
|
|
|
167
|
+
def request_params
|
|
168
|
+
params = @filters.dup
|
|
169
|
+
@filter_objects.each { |f| params[f.attr] = f.opval }
|
|
170
|
+
@group_by.each_with_index { |v, i| params["group_by[#{i}]"] = v.to_s }
|
|
171
|
+
@order_by.each_with_index { |v, i| params["order_by[#{i}]"] = v.to_s }
|
|
172
|
+
params['limit'] = @limit.to_s if @limit
|
|
173
|
+
params['offset'] = @offset.to_s if @offset
|
|
174
|
+
params
|
|
175
|
+
end
|
|
176
|
+
|
|
129
177
|
def _request(method, id: nil, json: nil)
|
|
130
178
|
if !@cls.nil?
|
|
131
179
|
if @cls.spec.key?("endpoint")
|
|
@@ -145,8 +193,9 @@ module Payload
|
|
|
145
193
|
endpoint = File.join(endpoint, id)
|
|
146
194
|
end
|
|
147
195
|
|
|
196
|
+
params = request_params
|
|
148
197
|
url = URI.join(@session.api_url, endpoint)
|
|
149
|
-
url.query = URI.encode_www_form(
|
|
198
|
+
url.query = URI.encode_www_form(params)
|
|
150
199
|
|
|
151
200
|
http = Net::HTTP.new(url.host, url.port)
|
|
152
201
|
|
|
@@ -162,6 +211,10 @@ module Payload
|
|
|
162
211
|
request.add_field('Content-Type', 'application/json')
|
|
163
212
|
end
|
|
164
213
|
|
|
214
|
+
if @session.api_version
|
|
215
|
+
request.add_field('X-API-Version', @session.api_version)
|
|
216
|
+
end
|
|
217
|
+
|
|
165
218
|
response = self._execute_request(http, request)
|
|
166
219
|
|
|
167
220
|
begin
|
|
@@ -178,6 +231,7 @@ module Payload
|
|
|
178
231
|
if data['object'] == 'list'
|
|
179
232
|
return data['values'].map do |obj|
|
|
180
233
|
cls = Payload::get_cls(obj)
|
|
234
|
+
cls = @cls if cls.nil? && !@cls.nil?
|
|
181
235
|
if cls.nil?
|
|
182
236
|
obj
|
|
183
237
|
else
|
|
@@ -186,7 +240,13 @@ module Payload
|
|
|
186
240
|
end
|
|
187
241
|
end
|
|
188
242
|
else
|
|
189
|
-
|
|
243
|
+
cls = Payload::get_cls(data)
|
|
244
|
+
cls = @cls if cls.nil? && !@cls.nil?
|
|
245
|
+
if cls.nil?
|
|
246
|
+
return data
|
|
247
|
+
else
|
|
248
|
+
return cls.new(data, @session)
|
|
249
|
+
end
|
|
190
250
|
end
|
|
191
251
|
else
|
|
192
252
|
for error in Payload::subclasses(Payload::PayloadError)
|
data/lib/payload/arm/session.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
require 'payload/arm/request'
|
|
2
|
-
|
|
2
|
+
require 'payload/arm/attr'
|
|
3
3
|
|
|
4
4
|
module Payload
|
|
5
|
-
|
|
6
5
|
class Session
|
|
7
|
-
attr_accessor :api_key, :api_url
|
|
8
|
-
|
|
9
|
-
def initialize(api_key, api_url=nil)
|
|
10
|
-
@api_key = api_key
|
|
11
|
-
@api_url = api_url || Payload.URL
|
|
12
|
-
|
|
6
|
+
attr_accessor :api_key, :api_url, :api_version
|
|
7
|
+
|
|
8
|
+
def initialize(api_key = nil, api_url = nil, api_version = nil, **kwargs)
|
|
9
|
+
@api_key = kwargs[:api_key] || api_key
|
|
10
|
+
@api_url = kwargs[:api_url] || api_url || Payload.URL
|
|
11
|
+
@api_version = kwargs[:api_version] || api_version || Payload.api_version
|
|
12
|
+
|
|
13
13
|
Payload.constants.each do |c|
|
|
14
14
|
val = Payload.const_get(c)
|
|
15
15
|
if val.is_a?(Class) && val < Payload::ARMObject
|
|
@@ -17,11 +17,15 @@ module Payload
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
def _get_request(cls = nil)
|
|
22
22
|
return Payload::ARMRequest.new(cls, self)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def attr
|
|
26
|
+
Payload::AttrRoot.new
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
def query(cls)
|
|
26
30
|
return self._get_request(cls)
|
|
27
31
|
end
|
data/lib/payload/exceptions.rb
CHANGED
|
@@ -18,6 +18,21 @@ module Payload
|
|
|
18
18
|
@code='400'
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
class TransactionDeclined < BadRequest
|
|
22
|
+
attr_reader :transaction
|
|
23
|
+
|
|
24
|
+
def initialize(msg, data = nil)
|
|
25
|
+
super(msg, data)
|
|
26
|
+
@transaction = if data && data['details'].is_a?(Hash)
|
|
27
|
+
cls = Payload.get_cls(data['details'])
|
|
28
|
+
cls = Payload::Transaction if cls.nil?
|
|
29
|
+
cls.new(data['details'], nil)
|
|
30
|
+
else
|
|
31
|
+
nil
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
21
36
|
class InvalidAttributes < PayloadError
|
|
22
37
|
@code='400'
|
|
23
38
|
end
|
data/lib/payload/objects.rb
CHANGED
|
@@ -18,18 +18,6 @@ module Payload
|
|
|
18
18
|
@spec = { 'object' => 'account' }
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
class Customer < ARMObject
|
|
22
|
-
@spec = { 'object' => 'customer' }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class ProcessingAccount < ARMObject
|
|
26
|
-
@spec = { 'object' => 'processing_account' }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
class Org < ARMObject
|
|
30
|
-
@spec = { 'object' => 'org', 'endpoint' => '/account/orgs' }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
21
|
class Transaction < ARMObject
|
|
34
22
|
@spec = { 'object' => 'transaction' }
|
|
35
23
|
end
|
|
@@ -74,6 +62,27 @@ module Payload
|
|
|
74
62
|
@spec = { 'object' => 'invoice' }
|
|
75
63
|
end
|
|
76
64
|
|
|
65
|
+
class InvoiceAttachment < ARMObject
|
|
66
|
+
@spec = { 'object' => 'invoice_attachment' }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class PaymentActivation < ARMObject
|
|
70
|
+
@spec = { 'object' => 'payment_activation' }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class ProcessingSettings < ARMObject
|
|
74
|
+
@spec = { 'object' => 'processing_settings' }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class Webhook < ARMObject
|
|
78
|
+
@spec = { 'object' => 'webhook' }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class PaymentLink < ARMObject
|
|
82
|
+
@spec = { 'object' => 'payment_link' }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# V1 objects
|
|
77
86
|
class LineItem < ARMObject
|
|
78
87
|
@spec = { 'object' => 'line_item' }
|
|
79
88
|
end
|
|
@@ -88,15 +97,69 @@ module Payload
|
|
|
88
97
|
@poly = { 'entry_type' => 'payment' }
|
|
89
98
|
end
|
|
90
99
|
|
|
91
|
-
class
|
|
92
|
-
@spec = { 'object' => '
|
|
100
|
+
class Customer < ARMObject
|
|
101
|
+
@spec = { 'object' => 'customer' }
|
|
93
102
|
end
|
|
94
103
|
|
|
95
|
-
class
|
|
96
|
-
@spec = { 'object' => '
|
|
104
|
+
class ProcessingAccount < ARMObject
|
|
105
|
+
@spec = { 'object' => 'processing_account' }
|
|
97
106
|
end
|
|
98
107
|
|
|
99
|
-
class
|
|
100
|
-
@spec = { 'object' => '
|
|
108
|
+
class Org < ARMObject
|
|
109
|
+
@spec = { 'object' => 'org', 'endpoint' => '/account/orgs' }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# V2 objects
|
|
113
|
+
class InvoiceItem < ARMObject
|
|
114
|
+
@spec = { 'object' => 'invoice_item' }
|
|
101
115
|
end
|
|
116
|
+
|
|
117
|
+
class PaymentAllocation < ARMObject
|
|
118
|
+
@spec = { 'object' => 'payment_allocation' }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class Profile < ARMObject
|
|
122
|
+
@spec = { 'object' => 'profile' }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
class BillingItem < ARMObject
|
|
126
|
+
@spec = { 'object' => 'billing_item' }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class Intent < ARMObject
|
|
130
|
+
@spec = { 'object' => 'intent' }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class Entity < ARMObject
|
|
134
|
+
@spec = { 'object' => 'entity', 'endpoint' => 'entities' }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
class Stakeholder < ARMObject
|
|
138
|
+
@spec = { 'object' => 'stakeholder' }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
class ProcessingAgreement < ARMObject
|
|
142
|
+
@spec = { 'object' => 'processing_agreement' }
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class Transfer < ARMObject
|
|
146
|
+
@spec = { 'object' => 'transfer' }
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class TransactionOperation < ARMObject
|
|
150
|
+
@spec = { 'object' => 'transaction_operation' }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
class CheckFront < ARMObject
|
|
154
|
+
@spec = { 'object' => 'check_front' }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
class CheckBack < ARMObject
|
|
158
|
+
@spec = { 'object' => 'check_back' }
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
class ProcessingRule < ARMObject
|
|
162
|
+
@spec = { 'object' => 'processing_rule' }
|
|
163
|
+
end
|
|
164
|
+
|
|
102
165
|
end
|
data/lib/payload/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module Payload
|
|
2
|
-
VERSION = '0.
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.6.0'
|
|
3
|
+
end
|
data/lib/payload.rb
CHANGED
|
@@ -3,8 +3,8 @@ require "payload/objects"
|
|
|
3
3
|
require "payload/arm/session"
|
|
4
4
|
|
|
5
5
|
module Payload
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
@URL = "https://api.payload.com"
|
|
7
|
+
|
|
8
8
|
class << self
|
|
9
9
|
def api_key=(value)
|
|
10
10
|
session.api_key = value
|
|
@@ -22,15 +22,24 @@ module Payload
|
|
|
22
22
|
session.api_url
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def api_version=(version)
|
|
26
|
+
@api_version = version
|
|
27
|
+
@session = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def api_version
|
|
31
|
+
@api_version
|
|
32
|
+
end
|
|
33
|
+
|
|
25
34
|
def URL
|
|
26
35
|
@URL
|
|
27
36
|
end
|
|
28
37
|
|
|
29
38
|
private
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
def session
|
|
41
|
+
@session ||= Payload::Session.new(nil, @URL)
|
|
42
|
+
end
|
|
34
43
|
end
|
|
35
44
|
|
|
36
45
|
def self.create(objects)
|
|
@@ -44,4 +53,5 @@ module Payload
|
|
|
44
53
|
def self.delete(objects)
|
|
45
54
|
return Payload::ARMRequest.new().delete_all(objects)
|
|
46
55
|
end
|
|
56
|
+
|
|
47
57
|
end
|