lavenda-pay-ruby 0.0.1 → 0.0.2
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 +7 -3
- data/README.md +28 -10
- data/lib/lavenda_pay/configuration.rb +16 -3
- data/lib/lavenda_pay/url.rb +14 -0
- data/lib/lavenda_pay/version.rb +1 -1
- data/lib/lavenda_pay.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b22bd19fa8ee233967739f90119ba9159e36b5650f69a40ceb1aaf4283886e2
|
|
4
|
+
data.tar.gz: 90b7d4524c3a098c0f497945b6905e134872070449a308129d6a089ab38d8462
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ed16222d6590470b455d4dfb41657dc70716aee12f530faea840bfeab13b369e0fc2be5516bdbb06c21687f360aee9388495d7597689a6e17b6fdbb12a8bae1
|
|
7
|
+
data.tar.gz: e535aed1df0e7727729e7dae40dc987ac33bc9ac5a1cfe64e9fdb98965c5810fa35488156102d81aea2aea0efa37d52e1aabe0f09bc084c06ec8ad1f44c2664b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.0.2
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
|
|
5
|
+
- Read settings from the `lavenda_pay` Rails credentials when the environment variable is not set.
|
|
6
|
+
- Add `LavendaPay::Url.order_path` to build the public order page link.
|
|
7
|
+
|
|
8
|
+
## 0.0.1
|
|
9
|
+
|
|
10
|
+
- Initial release: customers, orders and webhook handling.
|
data/README.md
CHANGED
|
@@ -6,25 +6,40 @@ Framework-agnostic (no Rails/ActiveSupport dependency): create customers and ord
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
8
8
|
```ruby
|
|
9
|
-
gem "lavenda-pay-ruby"
|
|
9
|
+
gem "lavenda-pay-ruby"
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
## Configuration
|
|
13
13
|
|
|
14
|
+
Settings are read from `LAVENDA_PAY_*` environment variables and, inside a Rails app, from the `lavenda_pay`
|
|
15
|
+
credentials, so a Rails app needs no initializer:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
# bin/rails credentials:edit
|
|
19
|
+
lavenda_pay:
|
|
20
|
+
base_url: https://pay.example.com
|
|
21
|
+
api_token: ...
|
|
22
|
+
webhook_secret: ...
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
| Setting | Environment variable | Credential |
|
|
26
|
+
| ---------------- | ---------------------------- | ------------------------------ |
|
|
27
|
+
| `base_url` | `LAVENDA_PAY_BASE_URL` | `lavenda_pay.base_url` |
|
|
28
|
+
| `api_token` | `LAVENDA_PAY_API_TOKEN` | `lavenda_pay.api_token` |
|
|
29
|
+
| `webhook_secret` | `LAVENDA_PAY_WEBHOOK_SECRET` | `lavenda_pay.webhook_secret` |
|
|
30
|
+
|
|
31
|
+
`base_url` is the root of the Lavenda Pay installation, without the `/api` suffix. Use the company domain: the API
|
|
32
|
+
accepts any host, but the public order pages are only served on the company's own domain.
|
|
33
|
+
|
|
34
|
+
Values set explicitly win over both:
|
|
35
|
+
|
|
14
36
|
```ruby
|
|
15
|
-
# config/initializers/lavenda_pay.rb
|
|
16
37
|
LavendaPay.configure do |config|
|
|
17
|
-
config.base_url =
|
|
18
|
-
config.
|
|
19
|
-
config.webhook_secret = ENV.fetch("LAVENDA_PAY_WEBHOOK_SECRET", Rails.application.credentials.dig(:lavenda_pay, :webhook_secret))
|
|
38
|
+
config.base_url = "https://pay.example.com"
|
|
39
|
+
config.logger = Rails.logger
|
|
20
40
|
end
|
|
21
41
|
```
|
|
22
42
|
|
|
23
|
-
`base_url` is the root of the Lavenda Pay installation, without the `/api` suffix.
|
|
24
|
-
|
|
25
|
-
Outside Rails, set the values directly. Anything left unset falls back to the `LAVENDA_PAY_BASE_URL`,
|
|
26
|
-
`LAVENDA_PAY_API_TOKEN` and `LAVENDA_PAY_WEBHOOK_SECRET` environment variables.
|
|
27
|
-
|
|
28
43
|
Every operation is a class with `.call` that uses this global configuration. For several accounts, build a client and
|
|
29
44
|
pass it to the operation:
|
|
30
45
|
|
|
@@ -68,6 +83,9 @@ order.pid # => "order_..."
|
|
|
68
83
|
order.status # => "draft"
|
|
69
84
|
|
|
70
85
|
LavendaPay::Orders::Find.call(order.pid)
|
|
86
|
+
|
|
87
|
+
# Public payment page for the order, built from `base_url`.
|
|
88
|
+
LavendaPay::Url.order_path(order.pid) # => "https://pay.example.com/orders/order_..."
|
|
71
89
|
```
|
|
72
90
|
|
|
73
91
|
## Errors
|
|
@@ -14,11 +14,11 @@ module LavendaPay
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# Root URL of the Lavenda Pay installation, without the `/api` suffix.
|
|
17
|
-
def base_url = @base_url ||
|
|
17
|
+
def base_url = @base_url || setting(:base_url)
|
|
18
18
|
|
|
19
|
-
def api_token = @api_token ||
|
|
19
|
+
def api_token = @api_token || setting(:api_token)
|
|
20
20
|
|
|
21
|
-
def webhook_secret = @webhook_secret ||
|
|
21
|
+
def webhook_secret = @webhook_secret || setting(:webhook_secret)
|
|
22
22
|
|
|
23
23
|
def validate!
|
|
24
24
|
raise ConfigurationError, "LavendaPay base_url is not configured (LAVENDA_PAY_BASE_URL)" if blank?(base_url)
|
|
@@ -30,5 +30,18 @@ module LavendaPay
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
32
|
def blank?(value) = value.nil? || value.to_s.strip.empty?
|
|
33
|
+
|
|
34
|
+
# `LAVENDA_PAY_<KEY>` environment variable, then the `lavenda_pay` Rails
|
|
35
|
+
# credentials when running inside a Rails app.
|
|
36
|
+
def setting(key)
|
|
37
|
+
value = ENV["LAVENDA_PAY_#{key.to_s.upcase}"]
|
|
38
|
+
blank?(value) ? rails_credential(key) : value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def rails_credential(key)
|
|
42
|
+
return unless defined?(::Rails.application) && ::Rails.application
|
|
43
|
+
|
|
44
|
+
::Rails.application.credentials.dig(:lavenda_pay, key)
|
|
45
|
+
end
|
|
33
46
|
end
|
|
34
47
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "uri"
|
|
2
|
+
|
|
3
|
+
module LavendaPay
|
|
4
|
+
# Links to the public Lavenda Pay pages, built from `base_url`.
|
|
5
|
+
#
|
|
6
|
+
# LavendaPay::Url.order_path("order_...") # => "https://.../orders/order_..."
|
|
7
|
+
module Url
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def order_path(pid, configuration: LavendaPay.configuration)
|
|
11
|
+
"#{configuration.base_url.to_s.chomp("/")}/orders/#{URI.encode_www_form_component(pid.to_s)}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/lavenda_pay/version.rb
CHANGED
data/lib/lavenda_pay.rb
CHANGED
|
@@ -13,6 +13,7 @@ require_relative "lavenda_pay/customers/list"
|
|
|
13
13
|
require_relative "lavenda_pay/customers/find_by"
|
|
14
14
|
require_relative "lavenda_pay/orders/create"
|
|
15
15
|
require_relative "lavenda_pay/orders/find"
|
|
16
|
+
require_relative "lavenda_pay/url"
|
|
16
17
|
require_relative "lavenda_pay/webhooks"
|
|
17
18
|
require_relative "lavenda_pay/engine" if defined?(Rails::Engine)
|
|
18
19
|
|
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.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- La Venda Software
|
|
@@ -121,6 +121,7 @@ files:
|
|
|
121
121
|
- lib/lavenda_pay/resource.rb
|
|
122
122
|
- lib/lavenda_pay/resources/customer.rb
|
|
123
123
|
- lib/lavenda_pay/resources/order.rb
|
|
124
|
+
- lib/lavenda_pay/url.rb
|
|
124
125
|
- lib/lavenda_pay/version.rb
|
|
125
126
|
- lib/lavenda_pay/webhooks.rb
|
|
126
127
|
- lib/lavenda_pay/webhooks/construct_event.rb
|