zai_payment 1.0.1
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 +7 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +135 -0
- data/Rakefile +12 -0
- data/lib/zai_payment/auth/token_provider.rb +97 -0
- data/lib/zai_payment/auth/token_store.rb +13 -0
- data/lib/zai_payment/auth/token_stores/memory_store.rb +29 -0
- data/lib/zai_payment/config.rb +40 -0
- data/lib/zai_payment/errors.rb +9 -0
- data/lib/zai_payment/version.rb +5 -0
- data/lib/zai_payment.rb +33 -0
- data/sig/zai_payment.rbs +4 -0
- metadata +75 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 719c0663d33f0ced4d8bcc6627dd58ce98b8c14f436d9ce02210f01fc04b99d3
|
|
4
|
+
data.tar.gz: 85e8ae991cec90cd59e11f8234cdff9a7f684d4c5632bd9fd4659dc1af4ccedf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1536177552b6ba2e10bb61734f574e697275cba87c74af530bbf8c125f37927f1cb2bf5de7dc4b94dffaaccd563f4d9f49ab96d1d40bf6fc5511f1ddf51adf11
|
|
7
|
+
data.tar.gz: 843f7c8d8650fc974af5a701d33e139cc1170a84cf064d765bc31729a0c3cd95487e4e51d4c06595a2e70bcc3f104a908d39c00343acc89d9054d146c7f31d9a
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [1.0.0] - 2025-10-21
|
|
4
|
+
|
|
5
|
+
- Initial release: token auth client with in-memory caching (`ZaiPayment.token`, `refresh_token!`, `clear_token!`, `token_type`, `token_expiry`)
|
|
6
|
+
|
|
7
|
+
**Full Changelog**: https://github.com/Sentia/zai-payment/commits/v1.0.0
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
contact@sentia.com.au.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Eddy Jaga
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Zai Payment Ruby Library
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Sentia/zai-payment/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
A lightweight and extensible Ruby client for the **Zai (AssemblyPay)** API — starting with secure OAuth2 authentication, and ready for Payments, Virtual Accounts, Webhooks, and more.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- 🔐 OAuth2 Client Credentials authentication with automatic token management
|
|
12
|
+
- 🧠 Smart token caching and refresh
|
|
13
|
+
- ⚙️ Environment-aware (Pre-live / Production)
|
|
14
|
+
- 🧱 Modular structure: easy to extend to Payments, Wallets, Webhooks, etc.
|
|
15
|
+
- 🧩 Thread-safe in-memory store (Redis support coming soon)
|
|
16
|
+
- 🧰 Simple Ruby API, no heavy dependencies
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🧭 Installation
|
|
21
|
+
|
|
22
|
+
### From GitHub (private repo)
|
|
23
|
+
Add this line to your Gemfile:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
gem "zai_payment",
|
|
27
|
+
git: "https://github.com/Sentia/zai-payment.git",
|
|
28
|
+
branch: "main"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bundle install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## ⚙️ Configuration
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
# config/initializers/zai_payment.rb
|
|
41
|
+
ZaiPayment.configure do |c|
|
|
42
|
+
c.environment = Rails.env.production? ? :production : :prelive
|
|
43
|
+
c.client_id = ENV.fetch("ZAI_CLIENT_ID")
|
|
44
|
+
c.client_secret = ENV.fetch("ZAI_CLIENT_SECRET")
|
|
45
|
+
c.scope = ENV.fetch("ZAI_OAUTH_SCOPE")
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 🚀 Authentication
|
|
50
|
+
|
|
51
|
+
The Zai Payment gem implements OAuth2 Client Credentials flow for secure authentication with the Zai API. The gem intelligently manages your authentication tokens behind the scenes, so you don't have to worry about token expiration or manual refreshes.
|
|
52
|
+
|
|
53
|
+
When you request a token, the gem automatically caches it and reuses it for subsequent requests. Since Zai tokens expire after 60 minutes, the gem monitors the token lifetime and seamlessly refreshes it before expiration — ensuring your API calls never fail due to stale credentials.
|
|
54
|
+
|
|
55
|
+
This automatic token management means you can focus on building your integration while the gem handles all the authentication complexity for you. Simply configure your credentials once, and the gem takes care of the rest.
|
|
56
|
+
|
|
57
|
+
For more details about Zai's OAuth2 authentication, see the [official documentation](https://developer.hellozai.com/reference/overview#authentication).
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
client = ZaiPayment::Auth::TokenProvider.new(config: ZaiPayment.config)
|
|
61
|
+
|
|
62
|
+
client.bearer_token
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or, more easily, you can get a token with the convenience one-liner:
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
ZaiPayment.token
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 🧩 Roadmap
|
|
73
|
+
|
|
74
|
+
| Area | Description | Status |
|
|
75
|
+
| ------------------------------- | --------------------------------- | -------------- |
|
|
76
|
+
| ✅ Authentication | OAuth2 Client Credentials flow | Done |
|
|
77
|
+
| 💳 Payments | Single and recurring payments | 🚧 In progress |
|
|
78
|
+
| 🏦 Virtual Accounts (VA / PIPU) | Manage virtual accounts & PayTo | ⏳ Planned |
|
|
79
|
+
| 🧾 Webhooks | CRUD for webhook endpoints | ⏳ Planned |
|
|
80
|
+
| 👤 Users | Manage PayIn / PayOut users | ⏳ Planned |
|
|
81
|
+
| 💼 Wallets | Create and manage wallet accounts | ⏳ Planned |
|
|
82
|
+
|
|
83
|
+
## 🧪 Development
|
|
84
|
+
|
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
86
|
+
|
|
87
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
88
|
+
|
|
89
|
+
### Running Tests
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
bundle exec rspec
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Code Quality
|
|
96
|
+
|
|
97
|
+
This project uses RuboCop for linting. Run it with:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
bundle exec rubocop
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Interactive Console
|
|
104
|
+
|
|
105
|
+
For development and testing, use the interactive console:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bin/console
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This will load the gem and all its dependencies, allowing you to experiment with the API in a REPL environment.
|
|
112
|
+
|
|
113
|
+
## 🧾 Versioning
|
|
114
|
+
This gem follows [Semantic Versioning](https://semver.org).
|
|
115
|
+
|
|
116
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## 🤝 Contributing
|
|
120
|
+
|
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Sentia/zai-payment. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Sentia/zai-payment/blob/main/CODE_OF_CONDUCT.md).
|
|
122
|
+
|
|
123
|
+
## 🪪 License
|
|
124
|
+
|
|
125
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
126
|
+
|
|
127
|
+
## Code of Conduct
|
|
128
|
+
|
|
129
|
+
Everyone interacting in the ZaiPayment project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Sentia/zai-payment/blob/main/CODE_OF_CONDUCT.md).
|
|
130
|
+
|
|
131
|
+
## 🔗 Resources
|
|
132
|
+
|
|
133
|
+
- [Zai Developer Portal](https://developer.hellozai.com/)
|
|
134
|
+
- [Zai API Reference](https://developer.hellozai.com/reference)
|
|
135
|
+
- [AssemblyPay Auth Documentation](https://developer.hellozai.com/docs/introduction)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module ZaiPayment
|
|
6
|
+
module Auth
|
|
7
|
+
class TokenProvider
|
|
8
|
+
def initialize(config:, store: nil)
|
|
9
|
+
@config = config
|
|
10
|
+
@store = store || TokenStores::MemoryStore.new
|
|
11
|
+
@mutex = Mutex.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Returns "Bearer <token>"
|
|
15
|
+
def bearer_token
|
|
16
|
+
token = @store.fetch
|
|
17
|
+
return "Bearer #{token.value}" if token && Time.now < token.expires_at
|
|
18
|
+
|
|
19
|
+
@mutex.synchronize do
|
|
20
|
+
token = @store.fetch
|
|
21
|
+
return "Bearer #{token.value}" if token && Time.now < token.expires_at
|
|
22
|
+
|
|
23
|
+
new_token = request_token!
|
|
24
|
+
@store.write(new_token)
|
|
25
|
+
"Bearer #{new_token.value}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Force refresh: clears current token then fetches a new one
|
|
30
|
+
def refresh_token
|
|
31
|
+
clear_token
|
|
32
|
+
bearer_token
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Clear cached token (next call will re-auth)
|
|
36
|
+
def clear_token
|
|
37
|
+
@store.clear
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Returns a Time (or nil if no token cached)
|
|
41
|
+
def token_expiry
|
|
42
|
+
token = @store.fetch
|
|
43
|
+
token&.expires_at
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Returns the token type string (e.g., "Bearer") or nil if none cached
|
|
47
|
+
def token_type
|
|
48
|
+
token = @store.fetch
|
|
49
|
+
token&.type
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def request_token!
|
|
55
|
+
resp = perform_token_request
|
|
56
|
+
parse_token_response(resp)
|
|
57
|
+
rescue Faraday::Error => e
|
|
58
|
+
raise ZaiPayment::Errors::AuthError, "Token request failed: #{e.message}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def perform_token_request
|
|
62
|
+
connection.post('/tokens') do |req|
|
|
63
|
+
req.body = {
|
|
64
|
+
grant_type: 'client_credentials',
|
|
65
|
+
client_id: @config.client_id,
|
|
66
|
+
client_secret: @config.client_secret,
|
|
67
|
+
scope: @config.scope
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def connection
|
|
73
|
+
Faraday.new do |faraday|
|
|
74
|
+
faraday.request :url_encoded
|
|
75
|
+
faraday.response :json
|
|
76
|
+
faraday.adapter Faraday.default_adapter
|
|
77
|
+
faraday.url_prefix = @config.endpoints[:auth_base]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def parse_token_response(resp)
|
|
82
|
+
data = resp.body
|
|
83
|
+
token_value = data['access_token'] || data['token']
|
|
84
|
+
expires_in = (data['expires_in'] || 3600).to_i
|
|
85
|
+
token_type = data['token_type'] || 'Bearer'
|
|
86
|
+
|
|
87
|
+
raise ZaiPayment::Errors::AuthError, 'No access_token found' unless token_value
|
|
88
|
+
|
|
89
|
+
TokenStore::Token.new(
|
|
90
|
+
value: token_value,
|
|
91
|
+
expires_at: Time.now + expires_in - 60,
|
|
92
|
+
type: token_type
|
|
93
|
+
)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ZaiPayment
|
|
4
|
+
module Auth
|
|
5
|
+
class TokenStore
|
|
6
|
+
Token = Struct.new(:value, :expires_at, :type, keyword_init: true)
|
|
7
|
+
|
|
8
|
+
def fetch = raise(NotImplementedError)
|
|
9
|
+
def write(token) = raise(NotImplementedError)
|
|
10
|
+
def clear = raise(NotImplementedError)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'monitor'
|
|
4
|
+
|
|
5
|
+
module ZaiPayment
|
|
6
|
+
module Auth
|
|
7
|
+
module TokenStores
|
|
8
|
+
class MemoryStore < TokenStore
|
|
9
|
+
def initialize
|
|
10
|
+
super
|
|
11
|
+
@token = nil
|
|
12
|
+
@monitor = Monitor.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def fetch
|
|
16
|
+
@monitor.synchronize { @token }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write(token)
|
|
20
|
+
@monitor.synchronize { @token = token }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def clear
|
|
24
|
+
@monitor.synchronize { @token = nil }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ZaiPayment
|
|
4
|
+
class Config
|
|
5
|
+
attr_accessor :environment, :client_id, :client_secret, :scope,
|
|
6
|
+
:timeout, :open_timeout
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@environment = :prelive # or :production
|
|
10
|
+
@client_id = nil
|
|
11
|
+
@client_secret = nil
|
|
12
|
+
@scope = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def validate!
|
|
16
|
+
raise Errors::ConfigurationError, 'client_id is required' if client_id.nil? || client_id.empty?
|
|
17
|
+
raise Errors::ConfigurationError, 'client_secret is required' if client_secret.nil? || client_secret.empty?
|
|
18
|
+
raise Errors::ConfigurationError, 'scope is required' if scope.nil? || scope.empty?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def endpoints
|
|
22
|
+
case environment.to_sym
|
|
23
|
+
when :prelive
|
|
24
|
+
{
|
|
25
|
+
core_base: 'https://test.api.promisepay.com',
|
|
26
|
+
va_base: 'https://sandbox.au-0000.api.assemblypay.com',
|
|
27
|
+
auth_base: 'https://au-0000.sandbox.auth.assemblypay.com'
|
|
28
|
+
}
|
|
29
|
+
when :production
|
|
30
|
+
{
|
|
31
|
+
core_base: 'https://au-0000.api.assemblypay.com',
|
|
32
|
+
va_base: 'https://secure.api.promisepay.com',
|
|
33
|
+
auth_base: 'https://au-0000.auth.assemblypay.com'
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
raise "Unknown environment: #{environment}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/zai_payment.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require_relative 'zai_payment/version'
|
|
5
|
+
require_relative 'zai_payment/config'
|
|
6
|
+
require_relative 'zai_payment/errors'
|
|
7
|
+
require_relative 'zai_payment/auth/token_provider'
|
|
8
|
+
require_relative 'zai_payment/auth/token_store'
|
|
9
|
+
require_relative 'zai_payment/auth/token_stores/memory_store'
|
|
10
|
+
|
|
11
|
+
module ZaiPayment
|
|
12
|
+
class << self
|
|
13
|
+
def config
|
|
14
|
+
@config ||= Config.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def configure
|
|
18
|
+
yield config
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Singleton auth token provider (uses default MemoryStore under the hood)
|
|
22
|
+
def auth
|
|
23
|
+
@auth ||= ZaiPayment::Auth::TokenProvider.new(config: config)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# --- Convenience one-liners ---
|
|
27
|
+
def token = auth.bearer_token
|
|
28
|
+
def refresh_token! = auth.refresh_token
|
|
29
|
+
def clear_token! = auth.clear_token
|
|
30
|
+
def token_expiry = auth.token_expiry
|
|
31
|
+
def token_type = auth.token_type
|
|
32
|
+
end
|
|
33
|
+
end
|
data/sig/zai_payment.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zai_payment
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Eddy Jaga
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-10-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
description: A Ruby gem for integrating with Zai payment platform APIs.
|
|
28
|
+
email:
|
|
29
|
+
- eddy.jaga@sentia.com.au
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- CHANGELOG.md
|
|
35
|
+
- CODE_OF_CONDUCT.md
|
|
36
|
+
- LICENSE.txt
|
|
37
|
+
- README.md
|
|
38
|
+
- Rakefile
|
|
39
|
+
- lib/zai_payment.rb
|
|
40
|
+
- lib/zai_payment/auth/token_provider.rb
|
|
41
|
+
- lib/zai_payment/auth/token_store.rb
|
|
42
|
+
- lib/zai_payment/auth/token_stores/memory_store.rb
|
|
43
|
+
- lib/zai_payment/config.rb
|
|
44
|
+
- lib/zai_payment/errors.rb
|
|
45
|
+
- lib/zai_payment/version.rb
|
|
46
|
+
- sig/zai_payment.rbs
|
|
47
|
+
homepage: https://github.com/Sentia/zai-payment
|
|
48
|
+
licenses:
|
|
49
|
+
- MIT
|
|
50
|
+
metadata:
|
|
51
|
+
allowed_push_host: https://rubygems.org
|
|
52
|
+
homepage_uri: https://github.com/Sentia/zai-payment
|
|
53
|
+
source_code_uri: https://github.com/Sentia/zai-payment
|
|
54
|
+
changelog_uri: https://github.com/Sentia/zai-payment/CHANGELOG.md
|
|
55
|
+
rubygems_mfa_required: 'true'
|
|
56
|
+
post_install_message:
|
|
57
|
+
rdoc_options: []
|
|
58
|
+
require_paths:
|
|
59
|
+
- lib
|
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 3.2.0
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
requirements: []
|
|
71
|
+
rubygems_version: 3.5.11
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 4
|
|
74
|
+
summary: Ruby gem for Zai payment integration
|
|
75
|
+
test_files: []
|