lavenda-pay-ruby 0.0.3 → 0.0.4
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/CHANGELOG.md +8 -0
- data/README.md +45 -1
- data/lib/lavenda_pay/orders/create.rb +2 -1
- data/lib/lavenda_pay/payment_links/create.rb +13 -0
- data/lib/lavenda_pay/payment_links/end.rb +14 -0
- data/lib/lavenda_pay/payment_links/find.rb +11 -0
- data/lib/lavenda_pay/payment_links/list.rb +14 -0
- data/lib/lavenda_pay/payments/simulate.rb +18 -0
- data/lib/lavenda_pay/resources/order.rb +2 -1
- data/lib/lavenda_pay/resources/payment.rb +2 -1
- data/lib/lavenda_pay/resources/payment_link.rb +10 -0
- data/lib/lavenda_pay/resources/payment_simulation.rb +14 -0
- data/lib/lavenda_pay/version.rb +1 -1
- data/lib/lavenda_pay.rb +7 -0
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab9c1f7169f3c8a9139e5ae77fd7d32c611e59b089c2210f81ef2670ae93983d
|
|
4
|
+
data.tar.gz: 3fd5edcbafd5aaf883942e2b49ca718efadd6c6457d5d42b7f5634609269b310
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e931c2d7c3b80e7c8c62957dcafe58be59331806ecac03e9bf7c5df469ec34832f14516b4af4f7d4d00a7a1fde7117bb7be0ab8bb463b9262b770801ac52f8c
|
|
7
|
+
data.tar.gz: a019be6f2a156a6e24afe598fafcf10272145d64d555d1cefe05b2a26aefd3f555f0003155aa78f3e9b381051b72cd896e4b0dd21ff1f2dc8f7002e1ea2fe25a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
- Add `LavendaPay::PaymentLinks` (`Create`, `Find`, `List`, `End`) and `LavendaPay::PaymentLink`.
|
|
6
|
+
- `LavendaPay::Order` exposes `payment_link_pid`.
|
|
7
|
+
- Add `LavendaPay::Payments::Simulate` to preview the options for an amount, with the card fee passed on to the customer.
|
|
8
|
+
- `LavendaPay::Orders::Create` accepts `max_installment_count`, and `LavendaPay::Order` exposes it.
|
|
9
|
+
- `LavendaPay::Payment` exposes `installment_count`, `surcharge` and `charged_total`.
|
|
10
|
+
|
|
3
11
|
## 0.0.3
|
|
4
12
|
|
|
5
13
|
- Add `LavendaPay::Payments::Confirm` to confirm a pending payment outside production.
|
data/README.md
CHANGED
|
@@ -77,7 +77,8 @@ order = LavendaPay::Orders::Create.call(
|
|
|
77
77
|
eid: "ORD-0123",
|
|
78
78
|
frequency: "once",
|
|
79
79
|
currency: "brl",
|
|
80
|
-
items_attributes: [{product_title: "Material didático", quantity: 1, unit_price: 450.0}]
|
|
80
|
+
items_attributes: [{product_title: "Material didático", quantity: 1, unit_price: 450.0}],
|
|
81
|
+
max_installment_count: 3 # optional: up to how many card installments, 1 to 12, defaults to 12
|
|
81
82
|
)
|
|
82
83
|
order.pid # => "order_..."
|
|
83
84
|
order.status # => "draft"
|
|
@@ -90,6 +91,20 @@ LavendaPay::Url.order_path(order.pid) # => "https://pay.example.com/orders/order
|
|
|
90
91
|
|
|
91
92
|
## Payments
|
|
92
93
|
|
|
94
|
+
Preview the options for the amount the merchant wants to receive, before redirecting the customer to
|
|
95
|
+
the order's payment page. The card fee is passed on to the customer; Pix passes nothing on, so its
|
|
96
|
+
`fee` and `net_amount` are `nil`, meaning unknown rather than zero. A simulation has no order, so it ignores
|
|
97
|
+
an order's `max_installment_count`, and it binds no price: the customer chooses the installments on the payment page, where the server computes the amount again.
|
|
98
|
+
Card data never goes through the API.
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
simulation = LavendaPay::Payments::Simulate.call(amount: 100.0)
|
|
102
|
+
simulation.options.map { |o| [o.payment_method_kind, o.installment_count, o.installment_value, o.total] }
|
|
103
|
+
# => [["pix", 1, 100.0, 100.0], ["credit_card", 1, 102.54, 102.54], ["credit_card", 2, 51.27, 102.54], ...]
|
|
104
|
+
|
|
105
|
+
LavendaPay::Url.order_path(order.pid) # send the customer here to choose and pay
|
|
106
|
+
```
|
|
107
|
+
|
|
93
108
|
Sandbox only: confirm a pending payment as if the customer had paid it, to test your payment flow
|
|
94
109
|
end to end. LavendaPay marks it as paid and, when the gateway supports it, confirms it there too.
|
|
95
110
|
The endpoint does not exist in production, where it raises `LavendaPay::NotFoundError`.
|
|
@@ -101,6 +116,35 @@ payment.status # => "paid"
|
|
|
101
116
|
payment.gateway_confirmation # => "confirmed", "failed" or "unsupported"
|
|
102
117
|
```
|
|
103
118
|
|
|
119
|
+
## Payment links
|
|
120
|
+
|
|
121
|
+
A reusable public page: each payer identifies themself there and generates their own order. Omit
|
|
122
|
+
`amount` to let the payer type it. `amount` is the base price: what a payment charges depends on
|
|
123
|
+
the payment method.
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
payment_link = LavendaPay::PaymentLinks::Create.call(
|
|
127
|
+
name: "Mentoria",
|
|
128
|
+
billing_type: "undefined", # "undefined" (Pix and card), "pix" or "credit_card"
|
|
129
|
+
charge_type: "detached",
|
|
130
|
+
amount: 150.0,
|
|
131
|
+
end_date: "2027-12-31",
|
|
132
|
+
due_date_limit_days: 3,
|
|
133
|
+
eid: "LINK-0123",
|
|
134
|
+
success_url: "https://example.com/thanks",
|
|
135
|
+
auto_redirect: true,
|
|
136
|
+
requires_billing_address: false
|
|
137
|
+
)
|
|
138
|
+
payment_link.url # => the public page to share
|
|
139
|
+
payment_link.status # => "active"
|
|
140
|
+
|
|
141
|
+
LavendaPay::PaymentLinks::Find.call(payment_link.pid)
|
|
142
|
+
LavendaPay::PaymentLinks::List.call(name: "Mentoria", eid: "LINK-0123", page: 1)
|
|
143
|
+
LavendaPay::PaymentLinks::End.call(payment_link.pid) # final; existing orders stay as they are
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Orders generated by a link carry its `payment_link_pid`.
|
|
147
|
+
|
|
104
148
|
## Errors
|
|
105
149
|
|
|
106
150
|
Non-2xx responses raise a `LavendaPay::ApiError` subclass exposing `status`, `body` and `errors`:
|
|
@@ -3,7 +3,8 @@ module LavendaPay
|
|
|
3
3
|
# LavendaPay::Orders::Create.call(
|
|
4
4
|
# customer_pid: "...", payment_method_kinds: ["pix", "credit_card"],
|
|
5
5
|
# description: "...", eid: "ORD-1", frequency: "once", currency: "brl",
|
|
6
|
-
# items_attributes: [{product_title: "...", quantity: 1, unit_price: 450.0}]
|
|
6
|
+
# items_attributes: [{product_title: "...", quantity: 1, unit_price: 450.0}],
|
|
7
|
+
# max_installment_count: 3 # optional, 1 to 12, defaults to 12
|
|
7
8
|
# ) # => LavendaPay::Order
|
|
8
9
|
class Create < Operation
|
|
9
10
|
def call(params)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
module PaymentLinks
|
|
3
|
+
# LavendaPay::PaymentLinks::Create.call(
|
|
4
|
+
# name: "Mentoria", billing_type: "undefined", charge_type: "detached", amount: 150.0
|
|
5
|
+
# ) # => LavendaPay::PaymentLink
|
|
6
|
+
class Create < Operation
|
|
7
|
+
def call(params)
|
|
8
|
+
body = http.post("/v1/payment_links", body: {payment_link: params})
|
|
9
|
+
PaymentLink.new(body["payment_link"] || body)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
module PaymentLinks
|
|
3
|
+
# Final: nobody can pay through the link anymore. Orders and payments it
|
|
4
|
+
# generated stay as they are.
|
|
5
|
+
#
|
|
6
|
+
# LavendaPay::PaymentLinks::End.call("payment_link_...") # => LavendaPay::PaymentLink
|
|
7
|
+
class End < Operation
|
|
8
|
+
def call(pid)
|
|
9
|
+
body = http.post("/v1/payment_links/#{escape(pid)}/ending")
|
|
10
|
+
PaymentLink.new(body["payment_link"] || body)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
module PaymentLinks
|
|
3
|
+
# LavendaPay::PaymentLinks::Find.call("payment_link_...") # => LavendaPay::PaymentLink
|
|
4
|
+
class Find < Operation
|
|
5
|
+
def call(pid)
|
|
6
|
+
body = http.get("/v1/payment_links/#{escape(pid)}")
|
|
7
|
+
PaymentLink.new(body["payment_link"] || body)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
module PaymentLinks
|
|
3
|
+
FILTER_KEYS = %i[name eid].freeze
|
|
4
|
+
|
|
5
|
+
# LavendaPay::PaymentLinks::List.call(name: "Mentoria", page: 1)
|
|
6
|
+
# # => [LavendaPay::PaymentLink, ...]
|
|
7
|
+
class List < Operation
|
|
8
|
+
def call(page: nil, **filters)
|
|
9
|
+
body = http.get("/v1/payment_links", params: {page:}.merge(filters.slice(*FILTER_KEYS)))
|
|
10
|
+
Array(body["payment_links"]).map { |attributes| PaymentLink.new(attributes) }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
module Payments
|
|
3
|
+
# Previews the options for the amount the merchant wants to receive: one per
|
|
4
|
+
# credit card installment count, with the card fee passed on to the customer,
|
|
5
|
+
# and one for Pix at the plain amount. It binds no price: the customer chooses
|
|
6
|
+
# the installments on the order's payment page, where the amount is computed
|
|
7
|
+
# again.
|
|
8
|
+
#
|
|
9
|
+
# LavendaPay::Payments::Simulate.call(amount: 100.0) # => LavendaPay::PaymentSimulation
|
|
10
|
+
class Simulate < Operation
|
|
11
|
+
def call(amount:)
|
|
12
|
+
body = http.post("/v1/payment_simulations", body: {payment_simulation: {amount: amount}})
|
|
13
|
+
|
|
14
|
+
PaymentSimulation.new(body["payment_simulation"] || body)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module LavendaPay
|
|
2
2
|
class Order < Resource
|
|
3
|
-
# Attributes: pid, status, expires_at, requires_billing_address,
|
|
3
|
+
# Attributes: pid, status, expires_at, requires_billing_address,
|
|
4
|
+
# max_installment_count, payment_link_pid, customer.
|
|
4
5
|
def customer
|
|
5
6
|
value = self["customer"]
|
|
6
7
|
value.is_a?(Hash) ? Customer.new(value) : value
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module LavendaPay
|
|
2
2
|
class Payment < Resource
|
|
3
|
-
# Attributes: pid, status,
|
|
3
|
+
# Attributes: pid, status, installment_count, surcharge (the fees passed on
|
|
4
|
+
# to the customer), charged_total, and gateway_confirmation after a sandbox
|
|
4
5
|
# confirmation ("confirmed", "failed" or "unsupported").
|
|
5
6
|
end
|
|
6
7
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
class PaymentLink < Resource
|
|
3
|
+
# Attributes: pid, status, url, name, description, billing_type, charge_type,
|
|
4
|
+
# amount, end_date, ended_at, due_date_limit_days, eid, success_url,
|
|
5
|
+
# auto_redirect, requires_billing_address.
|
|
6
|
+
#
|
|
7
|
+
# `amount` is the offer's base price, nil when the payer types it. What a
|
|
8
|
+
# payment charges depends on the payment method.
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module LavendaPay
|
|
2
|
+
class PaymentOption < Resource
|
|
3
|
+
# Attributes: payment_method_kind ("pix" or "credit_card"), installment_count,
|
|
4
|
+
# installment_value, total, fee, net_amount. On Pix, which passes nothing on,
|
|
5
|
+
# fee and net_amount are nil: unknown, not zero.
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class PaymentSimulation < Resource
|
|
9
|
+
# Attributes: amount, options.
|
|
10
|
+
def options
|
|
11
|
+
Array(self["options"]).map { |option| PaymentOption.new(option) }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/lavenda_pay/version.rb
CHANGED
data/lib/lavenda_pay.rb
CHANGED
|
@@ -6,6 +6,8 @@ require_relative "lavenda_pay/resource"
|
|
|
6
6
|
require_relative "lavenda_pay/resources/customer"
|
|
7
7
|
require_relative "lavenda_pay/resources/order"
|
|
8
8
|
require_relative "lavenda_pay/resources/payment"
|
|
9
|
+
require_relative "lavenda_pay/resources/payment_link"
|
|
10
|
+
require_relative "lavenda_pay/resources/payment_simulation"
|
|
9
11
|
require_relative "lavenda_pay/client"
|
|
10
12
|
require_relative "lavenda_pay/operation"
|
|
11
13
|
require_relative "lavenda_pay/customers/create"
|
|
@@ -15,6 +17,11 @@ require_relative "lavenda_pay/customers/find_by"
|
|
|
15
17
|
require_relative "lavenda_pay/orders/create"
|
|
16
18
|
require_relative "lavenda_pay/orders/find"
|
|
17
19
|
require_relative "lavenda_pay/payments/confirm"
|
|
20
|
+
require_relative "lavenda_pay/payment_links/create"
|
|
21
|
+
require_relative "lavenda_pay/payment_links/find"
|
|
22
|
+
require_relative "lavenda_pay/payment_links/list"
|
|
23
|
+
require_relative "lavenda_pay/payment_links/end"
|
|
24
|
+
require_relative "lavenda_pay/payments/simulate"
|
|
18
25
|
require_relative "lavenda_pay/url"
|
|
19
26
|
require_relative "lavenda_pay/webhooks"
|
|
20
27
|
require_relative "lavenda_pay/engine" if defined?(Rails::Engine)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lavenda-pay-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- La Venda Software
|
|
@@ -118,11 +118,18 @@ files:
|
|
|
118
118
|
- lib/lavenda_pay/operation.rb
|
|
119
119
|
- lib/lavenda_pay/orders/create.rb
|
|
120
120
|
- lib/lavenda_pay/orders/find.rb
|
|
121
|
+
- lib/lavenda_pay/payment_links/create.rb
|
|
122
|
+
- lib/lavenda_pay/payment_links/end.rb
|
|
123
|
+
- lib/lavenda_pay/payment_links/find.rb
|
|
124
|
+
- lib/lavenda_pay/payment_links/list.rb
|
|
121
125
|
- lib/lavenda_pay/payments/confirm.rb
|
|
126
|
+
- lib/lavenda_pay/payments/simulate.rb
|
|
122
127
|
- lib/lavenda_pay/resource.rb
|
|
123
128
|
- lib/lavenda_pay/resources/customer.rb
|
|
124
129
|
- lib/lavenda_pay/resources/order.rb
|
|
125
130
|
- lib/lavenda_pay/resources/payment.rb
|
|
131
|
+
- lib/lavenda_pay/resources/payment_link.rb
|
|
132
|
+
- lib/lavenda_pay/resources/payment_simulation.rb
|
|
126
133
|
- lib/lavenda_pay/url.rb
|
|
127
134
|
- lib/lavenda_pay/version.rb
|
|
128
135
|
- lib/lavenda_pay/webhooks.rb
|
|
@@ -153,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
153
160
|
- !ruby/object:Gem::Version
|
|
154
161
|
version: '0'
|
|
155
162
|
requirements: []
|
|
156
|
-
rubygems_version: 4.0.
|
|
163
|
+
rubygems_version: 4.0.20
|
|
157
164
|
specification_version: 4
|
|
158
165
|
summary: Ruby client for the Lavenda Pay payments API.
|
|
159
166
|
test_files: []
|