wariguai 1.3.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +30 -0
- data/lib/wariguai.rb +211 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c9f86f163a671fe47d8452bfadd0b6ec304d24fd53db629f44e1841510d78e61
|
|
4
|
+
data.tar.gz: e6732ed5e001af2ed34171cc42347aebfa756a9586c53ffc664edf7c171597b1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b9ddc2db8d5b8896b27707f7ed0da8429cb613a984cbcc7f0313130871f4cfa21caaa981d19905adff70fac0a429739e0505ebe5575c23ee0b8e0d429c8b79e1
|
|
7
|
+
data.tar.gz: b51498d32a42f823fd1300f0a45194f9263d101ecc5779164cceacbe901bbc8023247f3e5ffc853f37d1174502f00cc7d0488e23987be42c1fc591018fb8a1a2
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Historique des versions
|
|
2
|
+
|
|
3
|
+
## 1.3.0 (2026-12-02)
|
|
4
|
+
- Adresse officielle de l'API : https://api.wariguai.com/api/v1
|
|
5
|
+
- Prise en charge complète : Payin (paiements entrants), Payout (retraits / versements sortants), Liens de paiement, API SMS (format international +indicatif), Solde, Moyens de paiement et vérification HMAC-SHA256 des webhooks.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wariguai
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# wariguai (Ruby)
|
|
2
|
+
|
|
3
|
+
Gem officiel **Wariguai** pour **Ruby 3.0+** (Rails, Sinatra…), **zéro dépendance externe**.
|
|
4
|
+
API officielle : `https://api.wariguai.com/api/v1` · Documentation : https://developpeur.wariguai.com/docs#sdk
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
gem install wariguai
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Exemple rapide (Payin, Payout, SMS & Webhook)
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
require 'wariguai'
|
|
16
|
+
|
|
17
|
+
client = Wariguai::Client.new(ENV.fetch('WARIGUAI_SECRET_KEY'))
|
|
18
|
+
|
|
19
|
+
# Payin
|
|
20
|
+
paiement = client.create_payment(amount: 5000, reference: 'CMD-1001', return_url: 'https://maboutique.bf/merci')
|
|
21
|
+
|
|
22
|
+
# Payout
|
|
23
|
+
retrait = client.create_payout(idempotency_key: 'vers-01', channel: 'ORANGE_MONEY', number: '76123456', amount: 25_000)
|
|
24
|
+
|
|
25
|
+
# API SMS (+indicatif obligatoire)
|
|
26
|
+
client.send_sms(to: '+22670123456', message: 'Votre commande est confirmee.')
|
|
27
|
+
|
|
28
|
+
# Webhook
|
|
29
|
+
evt = Wariguai::Webhook.verify(request.raw_post, request.headers['Wariguai-Signature'], ENV.fetch('WARIGUAI_WEBHOOK_SECRET'))
|
|
30
|
+
```
|
data/lib/wariguai.rb
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Bibliothèque officielle Wariguai pour Ruby (3.0+, Rails, Sinatra…). Zéro dépendance externe.
|
|
4
|
+
# Documentation : https://developpeur.wariguai.com/docs#sdk
|
|
5
|
+
#
|
|
6
|
+
# Payin (encaissement) :
|
|
7
|
+
# require_relative 'wariguai'
|
|
8
|
+
# client = Wariguai::Client.new(ENV.fetch('WARIGUAI_SECRET_KEY'))
|
|
9
|
+
# paiement = client.create_payment(amount: 5000, reference: 'CMD-1001', return_url: 'https://monsite.bf/merci')
|
|
10
|
+
# redirect_to paiement['checkout_url'], allow_other_host: true
|
|
11
|
+
#
|
|
12
|
+
# Payout (retrait / versement sortant) :
|
|
13
|
+
# retrait = client.create_payout(channel: 'ORANGE_MONEY', number: '76123456', amount: 25_000, reference: 'VERS-01')
|
|
14
|
+
#
|
|
15
|
+
# Webhook :
|
|
16
|
+
# evt = Wariguai::Webhook.verify(request.raw_post, request.headers['Wariguai-Signature'], ENV.fetch('WARIGUAI_WEBHOOK_SECRET'))
|
|
17
|
+
|
|
18
|
+
require 'json'
|
|
19
|
+
require 'net/http'
|
|
20
|
+
require 'openssl'
|
|
21
|
+
require 'securerandom'
|
|
22
|
+
require 'uri'
|
|
23
|
+
|
|
24
|
+
module Wariguai
|
|
25
|
+
VERSION = '1.3.0'
|
|
26
|
+
DEFAULT_BASE_URL = 'https://api.wariguai.com/api/v1'
|
|
27
|
+
|
|
28
|
+
class Error < StandardError
|
|
29
|
+
attr_reader :status, :code, :raw
|
|
30
|
+
|
|
31
|
+
def initialize(message, status: 0, code: 'network_error', raw: nil)
|
|
32
|
+
super(message)
|
|
33
|
+
@status = status
|
|
34
|
+
@code = code
|
|
35
|
+
@raw = raw
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module Webhook
|
|
40
|
+
module_function
|
|
41
|
+
|
|
42
|
+
def verify(payload, signature_header, secret, tolerance_seconds: 300)
|
|
43
|
+
raise Error.new('Secret du webhook manquant (whsec_…)', code: 'missing_secret') if secret.to_s.empty?
|
|
44
|
+
|
|
45
|
+
parts = {}
|
|
46
|
+
signature_header.to_s.split(',').each do |item|
|
|
47
|
+
k, v = item.split('=', 2)
|
|
48
|
+
parts[k.strip] = v.strip if k && v
|
|
49
|
+
end
|
|
50
|
+
ts = parts['t'].to_i
|
|
51
|
+
given = parts['v1'].to_s
|
|
52
|
+
if ts <= 0 || given.empty?
|
|
53
|
+
raise Error.new('En-tête Wariguai-Signature absent ou mal formé', status: 400, code: 'invalid_signature')
|
|
54
|
+
end
|
|
55
|
+
if (Time.now.to_i - ts).abs > tolerance_seconds
|
|
56
|
+
raise Error.new('Webhook trop ancien (horodatage dépassé)', status: 400, code: 'timestamp_too_old')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
expected = OpenSSL::HMAC.hexdigest('SHA256', secret, "#{ts}.#{payload}")
|
|
60
|
+
unless OpenSSL.fixed_length_secure_compare(expected, given)
|
|
61
|
+
raise Error.new('Signature du webhook invalide', status: 400, code: 'invalid_signature')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
JSON.parse(payload)
|
|
65
|
+
rescue ArgumentError
|
|
66
|
+
raise Error.new('Signature du webhook invalide', status: 400, code: 'invalid_signature')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class Client
|
|
71
|
+
attr_reader :mode, :base_url
|
|
72
|
+
|
|
73
|
+
def initialize(secret_key, base_url: DEFAULT_BASE_URL, timeout: 20)
|
|
74
|
+
unless secret_key.to_s.match?(/\Ask_(test|live)_[0-9A-Za-z]{32}\z/)
|
|
75
|
+
raise ArgumentError, 'Clé secrète Wariguai invalide : utilise sk_test_… ou sk_live_…'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
@secret_key = secret_key
|
|
79
|
+
@mode = secret_key.start_with?('sk_live_') ? 'live' : 'test'
|
|
80
|
+
@base_url = base_url.to_s.sub(%r{/+\z}, '')
|
|
81
|
+
@timeout = timeout
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# ───── Payin (Paiements entrants) ─────
|
|
85
|
+
def create_payment(idempotency_key: nil, **params)
|
|
86
|
+
request(:post, '/payments', body: params, idempotency_key: idempotency_key)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def get_payment(payment_id)
|
|
90
|
+
request(:get, "/payments/#{URI.encode_www_form_component(payment_id.to_s)}")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def list_payments(**query)
|
|
94
|
+
request(:get, "/payments#{qs(query)}")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def cancel_payment(payment_id)
|
|
98
|
+
request(:post, "/payments/#{URI.encode_www_form_component(payment_id.to_s)}/cancel")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def simulate_payment(payment_id, outcome: 'succeeded')
|
|
102
|
+
request(:post, "/payments/#{URI.encode_www_form_component(payment_id.to_s)}/simulate", body: { outcome: outcome })
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def paid?(payment_id)
|
|
106
|
+
get_payment(payment_id)['status'] == 'succeeded'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# ───── Payout (Retraits / Versements sortants) ─────
|
|
110
|
+
def create_payout(idempotency_key: nil, **params)
|
|
111
|
+
request(:post, '/payouts', body: params, idempotency_key: idempotency_key)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def get_payout(payout_id)
|
|
115
|
+
request(:get, "/payouts/#{URI.encode_www_form_component(payout_id.to_s)}")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def list_payouts(**query)
|
|
119
|
+
request(:get, "/payouts#{qs(query)}")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# ───── Liens de paiement ─────
|
|
123
|
+
def create_link(**params)
|
|
124
|
+
request(:post, '/links', body: params)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def get_link(link_id)
|
|
128
|
+
request(:get, "/links/#{URI.encode_www_form_component(link_id.to_s)}")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def list_links(**query)
|
|
132
|
+
request(:get, "/links#{qs(query)}")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# ───── API SMS (format international +indicatif obligatoire) ─────
|
|
136
|
+
def send_sms(idempotency_key: nil, **params)
|
|
137
|
+
request(:post, '/sms', body: params, idempotency_key: idempotency_key)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def get_sms(sms_id)
|
|
141
|
+
request(:get, "/sms/#{URI.encode_www_form_component(sms_id.to_s)}")
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def sms_balance
|
|
145
|
+
request(:get, '/sms/balance')
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# ───── Solde & Moyens de paiement ─────
|
|
149
|
+
def balance
|
|
150
|
+
request(:get, '/balance')
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def channels
|
|
154
|
+
request(:get, '/channels')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def request(method, path, body: nil, idempotency_key: nil)
|
|
158
|
+
key = method == :post ? (idempotency_key || SecureRandom.hex(16)) : nil
|
|
159
|
+
last_error = nil
|
|
160
|
+
|
|
161
|
+
2.times do |attempt|
|
|
162
|
+
uri = URI("#{@base_url}#{path}")
|
|
163
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
164
|
+
http.use_ssl = uri.scheme == 'https'
|
|
165
|
+
http.open_timeout = 10
|
|
166
|
+
http.read_timeout = @timeout
|
|
167
|
+
|
|
168
|
+
req = method == :post ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
|
|
169
|
+
req['Authorization'] = "Bearer #{@secret_key}"
|
|
170
|
+
req['Accept'] = 'application/json'
|
|
171
|
+
req['User-Agent'] = "wariguai-ruby/#{VERSION}"
|
|
172
|
+
if method == :post
|
|
173
|
+
req['Content-Type'] = 'application/json'
|
|
174
|
+
req['Idempotency-Key'] = key
|
|
175
|
+
req.body = JSON.generate(body || {})
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
res = http.request(req)
|
|
179
|
+
status = res.code.to_i
|
|
180
|
+
parsed = begin
|
|
181
|
+
res.body.to_s.empty? ? {} : JSON.parse(res.body)
|
|
182
|
+
rescue JSON::ParserError
|
|
183
|
+
{}
|
|
184
|
+
end
|
|
185
|
+
return parsed if status >= 200 && status < 300
|
|
186
|
+
|
|
187
|
+
err = parsed.is_a?(Hash) && parsed['error'].is_a?(Hash) ? parsed['error'] : {}
|
|
188
|
+
last_error = Error.new(err['message'] || "Erreur Wariguai #{status}", status: status, code: err['code'] || 'api_error', raw: parsed)
|
|
189
|
+
raise last_error if status < 500 || attempt == 1
|
|
190
|
+
|
|
191
|
+
sleep 0.8
|
|
192
|
+
rescue Error
|
|
193
|
+
raise
|
|
194
|
+
rescue StandardError => e
|
|
195
|
+
last_error = Error.new("Wariguai injoignable : #{e.message}")
|
|
196
|
+
raise last_error if attempt == 1
|
|
197
|
+
|
|
198
|
+
sleep 0.8
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
raise last_error
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
private
|
|
205
|
+
|
|
206
|
+
def qs(query)
|
|
207
|
+
filtered = query.compact.reject { |_, v| v.to_s.empty? }
|
|
208
|
+
filtered.empty? ? '' : "?#{URI.encode_www_form(filtered)}"
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: wariguai
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Wariguai
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-12-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Bibliotheque officielle Wariguai pour Ruby et Rails (Payin, Payout, Liens de paiement, API SMS et Webhooks signes).
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/wariguai.rb
|
|
20
|
+
- README.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- CHANGELOG.md
|
|
23
|
+
homepage: https://developpeur.wariguai.com/docs#ruby
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '3.0'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubygems_version: 3.5.0
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Bibliotheque officielle Wariguai pour Ruby (Payin, Payout, Liens, SMS, Webhooks)
|
|
46
|
+
test_files: []
|