fawry 1.0.0 → 1.3.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 +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.rubocop.yml +4 -3
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +57 -56
- data/README-ar.md +184 -0
- data/README.md +75 -22
- data/Rakefile +8 -1
- data/fawry.gemspec +7 -7
- data/lib/fawry.rb +100 -1
- data/lib/fawry/config.rb +17 -0
- data/lib/fawry/connection.rb +22 -6
- data/lib/fawry/contracts/charge_request_contract.rb +7 -4
- data/lib/fawry/contracts/create_card_token_request_contract.rb +33 -0
- data/lib/fawry/contracts/delete_token_request_contract.rb +30 -0
- data/lib/fawry/contracts/list_tokens_request_contract.rb +29 -0
- data/lib/fawry/contracts/payment_status_request_contract.rb +6 -4
- data/lib/fawry/contracts/refund_request_contract.rb +6 -4
- data/lib/fawry/errors.rb +1 -0
- data/lib/fawry/fawry_callback.rb +1 -1
- data/lib/fawry/fawry_request.rb +14 -0
- data/lib/fawry/requests/charge_request.rb +5 -4
- data/lib/fawry/requests/create_card_token_request.rb +57 -0
- data/lib/fawry/requests/delete_token_request.rb +62 -0
- data/lib/fawry/requests/list_tokens_request.rb +57 -0
- data/lib/fawry/requests/payment_status_request.rb +3 -3
- data/lib/fawry/requests/refund_request.rb +3 -3
- data/lib/fawry/utils.rb +3 -1
- data/lib/fawry/version.rb +1 -1
- metadata +26 -29
- data/.github/workflows/greetings.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67bf2df195ce85382e7bd0d9f6d6b2111e5204d59fbc4091a5d9b31b7dde9a5f
|
4
|
+
data.tar.gz: 8a1ebb82a2b6a4937358193ae8c843f7dfcab971ed82c757171a1387c711d9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61914bd40afa7f491abc7f4f65b98e4f4b5e7e384335a7359028c548ec683a88035fef1799e844084e706ca7856828534a72f8a637676d4217510f008db2dfd3
|
7
|
+
data.tar.gz: 16b0687a4eee80795b08f1f71697c25619318b0b1fad49ca455f55527892aa97ea87e95e3edda5d3544433cbc33647a4e2e1524256874737ec8eb1d543c248e4
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
AllCops:
|
2
|
+
NewCops: enable
|
2
3
|
TargetRubyVersion: 2.6
|
3
|
-
|
4
|
+
Layout/LineLength:
|
4
5
|
Max: 120
|
5
6
|
Metrics/BlockLength:
|
6
|
-
|
7
|
+
IgnoredMethods: ['describe', 'context']
|
7
8
|
Style/Documentation:
|
8
|
-
Enabled: false
|
9
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Fawry Changelog
|
2
|
+
|
3
|
+
## [v1.3.1](https://github.com/fawry-api/fawry/releases/tag/v1.3.1) (15.08.2021)
|
4
|
+
- Add language param to charge request params
|
5
|
+
|
6
|
+
## [v1.2.1](https://github.com/fawry-api/fawry/releases/tag/v1.2.1) (14.03.2021)
|
7
|
+
- Update gem and dependencies to support Ruby 3.0
|
data/Gemfile.lock
CHANGED
@@ -1,95 +1,96 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fawry (1.
|
4
|
+
fawry (1.3.1)
|
5
5
|
dry-validation (~> 1.3, >= 1.3.1)
|
6
6
|
faraday (~> 0.17.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
11
|
+
addressable (2.8.0)
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
|
-
ast (2.4.
|
14
|
-
byebug (11.
|
15
|
-
concurrent-ruby (1.1.
|
16
|
-
crack (0.4.
|
17
|
-
|
18
|
-
diff-lcs (1.
|
19
|
-
dry-configurable (0.
|
13
|
+
ast (2.4.2)
|
14
|
+
byebug (11.1.3)
|
15
|
+
concurrent-ruby (1.1.8)
|
16
|
+
crack (0.4.5)
|
17
|
+
rexml
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
dry-configurable (0.12.1)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
|
-
dry-core (~> 0.
|
21
|
+
dry-core (~> 0.5, >= 0.5.0)
|
22
22
|
dry-container (0.7.2)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
24
|
dry-configurable (~> 0.1, >= 0.1.3)
|
25
|
-
dry-core (0.
|
25
|
+
dry-core (0.5.0)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
dry-equalizer (0.3.0)
|
28
28
|
dry-inflector (0.2.0)
|
29
|
-
dry-initializer (3.0.
|
30
|
-
dry-logic (1.0
|
29
|
+
dry-initializer (3.0.4)
|
30
|
+
dry-logic (1.2.0)
|
31
31
|
concurrent-ruby (~> 1.0)
|
32
|
-
dry-core (~> 0.
|
33
|
-
|
34
|
-
dry-schema (1.4.2)
|
32
|
+
dry-core (~> 0.5, >= 0.5)
|
33
|
+
dry-schema (1.6.2)
|
35
34
|
concurrent-ruby (~> 1.0)
|
36
35
|
dry-configurable (~> 0.8, >= 0.8.3)
|
37
|
-
dry-core (~> 0.
|
38
|
-
dry-equalizer (~> 0.2)
|
36
|
+
dry-core (~> 0.5, >= 0.5)
|
39
37
|
dry-initializer (~> 3.0)
|
40
38
|
dry-logic (~> 1.0)
|
41
|
-
dry-types (~> 1.
|
42
|
-
dry-types (1.
|
39
|
+
dry-types (~> 1.5)
|
40
|
+
dry-types (1.5.1)
|
43
41
|
concurrent-ruby (~> 1.0)
|
44
42
|
dry-container (~> 0.3)
|
45
|
-
dry-core (~> 0.
|
46
|
-
dry-equalizer (~> 0.3)
|
43
|
+
dry-core (~> 0.5, >= 0.5)
|
47
44
|
dry-inflector (~> 0.1, >= 0.1.2)
|
48
45
|
dry-logic (~> 1.0, >= 1.0.2)
|
49
|
-
dry-validation (1.
|
46
|
+
dry-validation (1.6.0)
|
50
47
|
concurrent-ruby (~> 1.0)
|
51
48
|
dry-container (~> 0.7, >= 0.7.1)
|
52
49
|
dry-core (~> 0.4)
|
53
50
|
dry-equalizer (~> 0.2)
|
54
51
|
dry-initializer (~> 3.0)
|
55
|
-
dry-schema (~> 1.
|
56
|
-
faraday (0.17.
|
52
|
+
dry-schema (~> 1.5, >= 1.5.2)
|
53
|
+
faraday (0.17.4)
|
57
54
|
multipart-post (>= 1.2, < 3)
|
58
|
-
hashdiff (1.0.
|
59
|
-
jaro_winkler (1.5.4)
|
55
|
+
hashdiff (1.0.1)
|
60
56
|
multipart-post (2.1.1)
|
61
|
-
parallel (1.
|
62
|
-
parser (
|
63
|
-
ast (~> 2.4.
|
64
|
-
public_suffix (4.0.
|
57
|
+
parallel (1.20.1)
|
58
|
+
parser (3.0.1.1)
|
59
|
+
ast (~> 2.4.1)
|
60
|
+
public_suffix (4.0.6)
|
65
61
|
rainbow (3.0.0)
|
66
|
-
rake (
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
rspec-
|
71
|
-
|
72
|
-
rspec-
|
73
|
-
rspec-
|
62
|
+
rake (13.0.3)
|
63
|
+
regexp_parser (2.1.1)
|
64
|
+
rexml (3.2.5)
|
65
|
+
rspec (3.10.0)
|
66
|
+
rspec-core (~> 3.10.0)
|
67
|
+
rspec-expectations (~> 3.10.0)
|
68
|
+
rspec-mocks (~> 3.10.0)
|
69
|
+
rspec-core (3.10.1)
|
70
|
+
rspec-support (~> 3.10.0)
|
71
|
+
rspec-expectations (3.10.1)
|
74
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
-
rspec-support (~> 3.
|
76
|
-
rspec-mocks (3.
|
73
|
+
rspec-support (~> 3.10.0)
|
74
|
+
rspec-mocks (3.10.2)
|
77
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-support (3.
|
76
|
+
rspec-support (~> 3.10.0)
|
77
|
+
rspec-support (3.10.2)
|
80
78
|
rspec_junit_formatter (0.4.1)
|
81
79
|
rspec-core (>= 2, < 4, != 2.12.0)
|
82
|
-
rubocop (
|
83
|
-
jaro_winkler (~> 1.5.1)
|
80
|
+
rubocop (1.13.0)
|
84
81
|
parallel (~> 1.10)
|
85
|
-
parser (>=
|
82
|
+
parser (>= 3.0.0.0)
|
86
83
|
rainbow (>= 2.2.2, < 4.0)
|
84
|
+
regexp_parser (>= 1.8, < 3.0)
|
85
|
+
rexml
|
86
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
87
87
|
ruby-progressbar (~> 1.7)
|
88
|
-
unicode-display_width (>= 1.4.0, <
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
89
|
+
rubocop-ast (1.5.0)
|
90
|
+
parser (>= 3.0.1.1)
|
91
|
+
ruby-progressbar (1.11.0)
|
92
|
+
unicode-display_width (2.0.0)
|
93
|
+
webmock (3.12.2)
|
93
94
|
addressable (>= 2.3.6)
|
94
95
|
crack (>= 0.3.2)
|
95
96
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -99,13 +100,13 @@ PLATFORMS
|
|
99
100
|
|
100
101
|
DEPENDENCIES
|
101
102
|
bundler (~> 2.0)
|
102
|
-
byebug (~> 11.0
|
103
|
+
byebug (~> 11.0)
|
103
104
|
fawry!
|
104
|
-
rake (~>
|
105
|
+
rake (~> 13.0)
|
105
106
|
rspec (~> 3.0)
|
106
107
|
rspec_junit_formatter
|
107
|
-
rubocop (~>
|
108
|
-
webmock (~> 3.
|
108
|
+
rubocop (~> 1.11)
|
109
|
+
webmock (~> 3.12)
|
109
110
|
|
110
111
|
BUNDLED WITH
|
111
|
-
2.
|
112
|
+
2.2.3
|
data/README-ar.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
[](https://circleci.com/gh/fawry-api/fawry)
|
2
|
+
|
3
|
+
# Fawry
|
4
|
+
|
5
|
+
**تنويه:** نحن لسنا تابعين رسميًا لشركة فوري.
|
6
|
+
|
7
|
+
مكتبة لتسهيل التعامل مع خدمات الدفع الخاصة بشبكة الدفع الإلكتروني فوري:
|
8
|
+
|
9
|
+
_المكتبة تدعم النظام التجريبي لفوري ايضا_
|
10
|
+
|
11
|
+
## لإضافة وتشغيل المكتبة
|
12
|
+
|
13
|
+
أضف هذا السطر إلى ملف Gemfile الخاص بتطبيقك:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'fawry'
|
17
|
+
```
|
18
|
+
|
19
|
+
ثم نفذ:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
أو قم بتثبيته بنفسك على النحو التالي:
|
24
|
+
|
25
|
+
$ gem install fawry
|
26
|
+
|
27
|
+
## تهيئة فوري للاستخدام
|
28
|
+
|
29
|
+
لبرنامجك لتهيئة المكتبة `fawry.rb` أضف مهيئ
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Fawry.configure do |config|
|
33
|
+
config.sandbox = Rails.env.staging?
|
34
|
+
config.fawry_secure_key = 'fawry_secure_key'
|
35
|
+
config.fawry_merchant_code = 'fawry_merchant_code'
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
`FAWRY_SANDBOX`, `FAWRY_SECURE_KEY`, `FAWRY_MERCHANT_CODE` _(environment variables)_ او يمكنك بدلا من ذلك، استخدام المتغيرات البيئية
|
40
|
+
|
41
|
+
## طريقة الإستعمال
|
42
|
+
|
43
|
+
### لإجراء عملية دفع
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
params = { "merchant_code": 'merchant_code',
|
47
|
+
"merchant_ref_num": 'io5jxf3jp27kfh8m719arcqgw7izo7db',
|
48
|
+
"customer_profile_id": 'ocvsydvbu2gcp528wvl64i9z5srdalg5',
|
49
|
+
"customer_mobile": '012345678901',
|
50
|
+
"payment_method": 'PAYATFAWRY',
|
51
|
+
"currency_code": 'EGP',
|
52
|
+
"amount": 20,
|
53
|
+
"language": "ar-eg",
|
54
|
+
"fawry_secure_key": 'fawry_secure_key',
|
55
|
+
"description": 'the charge request description',
|
56
|
+
"charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
|
57
|
+
"description": 'desc', "price": 20, "quantity": 1 }] }
|
58
|
+
|
59
|
+
res = Fawry.charge(params)
|
60
|
+
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
|
61
|
+
# @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
|
62
|
+
# @expiration_time=1573153206979, @status_code=200,
|
63
|
+
# @status_description="Operation done successfully">
|
64
|
+
|
65
|
+
res.success? # => true
|
66
|
+
res.reference_number # => 931600239
|
67
|
+
```
|
68
|
+
|
69
|
+
### لإجراء عملية استرداد
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
params = { "merchant_code": 'merchant_code',
|
73
|
+
"reference_number": '931337410',
|
74
|
+
"refund_amount": 20,
|
75
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
76
|
+
|
77
|
+
res = Fawry.refund(params)
|
78
|
+
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
|
79
|
+
# @status_description="Operation done successfully">
|
80
|
+
|
81
|
+
res.success? # => true
|
82
|
+
```
|
83
|
+
|
84
|
+
### حالة الدفع
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
params = { "merchant_code": 'merchant_code',
|
88
|
+
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
89
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
90
|
+
|
91
|
+
res = Fawry.payment_status(params)
|
92
|
+
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
93
|
+
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
94
|
+
# @expiration_time=1573297736167, @status_code=200,
|
95
|
+
# @status_description="Operation done successfully", @payment_amount=20,
|
96
|
+
# @payment_method="PAYATFAWRY", @payment_status="UNPAID">
|
97
|
+
|
98
|
+
res.success? # => true
|
99
|
+
res.payment_status # => UNPAID
|
100
|
+
```
|
101
|
+
|
102
|
+
### عرض رموز الكروت
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
params = { "merchant_code": 'merchant_code',
|
106
|
+
"customer_profile_id": 'customer_profile_id',
|
107
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
108
|
+
|
109
|
+
res = Fawry.list_tokens(params)
|
110
|
+
|
111
|
+
#<Fawry::FawryResponse:0x0000556cb3a31798 @fawry_api_response={"type"=>"CustomerTokensResponse", "cards"=>[{"token"=>"b5sshhdsl98df96200f254c19b2718bfc825a0678888216c28962b3e66a393084ee9aed6", "creationDate"=>1599487402318, "lastFourDigits"=>"4242", "brand"=>"Visa Card"}, {"token"=>"fb98dslsksmkdds7857ed7042ce30a2a5b777e1f1ac6ac58da1c8c0199f61df7a8bc098e96", "creationDate"=>1599489158457, "lastFourDigits"=>"0001", "brand"=>"Visa Card"}, {"token"=>"cc03fwqaacbd94e468a1b756ac1cbb285a41a2428df9f1a727457b41f9447d0058c7c", "creationDate"=>1599584834346, "lastFourDigits"=>"2346", "brand"=>"MasterCard"}, {"token"=>"f04a8bc9c973f900515f4b58e52c9ff03070baf3f534bdfdad0e97679534f60ddkjk13", "creationDate"=>1600260415739, "lastFourDigits"=>"8769", "brand"=>"Visa Card"}], "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CustomerTokensResponse", @cards=[{"token"=>"b5sshhdsl98df96200f254c19b2718bfc825a0678888216c28962b3e66a393084ee9aed6", "creationDate"=>1599487402318, "lastFourDigits"=>"4242", "brand"=>"Visa Card"}, {"token"=>"fb98dslsksmkdds7857ed7042ce30a2a5b777e1f1ac6ac58da1c8c0199f61df7a8bc098e96", "creationDate"=>1599489158457, "lastFourDigits"=>"0001", "brand"=>"Visa Card"}, {"token"=>"cc03fwqaacbd94e468a1b756ac1cbb285a41a2428df9f1a727457b41f9447d0058c7c", "creationDate"=>1599584834346, "lastFourDigits"=>"2346", "brand"=>"MasterCard"}, {"token"=>"f04a8bc9c973f900515f4b58e52c9ff03070baf3f534bdfdad0e97679534f60ddkjk13", "creationDate"=>1600260415739, "lastFourDigits"=>"8769", "brand"=>"Visa Card"}], @status_code=200, @status_description="Operation done successfully">
|
112
|
+
|
113
|
+
res.success? # => true
|
114
|
+
res.cards # => cards
|
115
|
+
```
|
116
|
+
|
117
|
+
### إضافة رمز كارت
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
params = { "merchant_code" : "merchant_code",
|
121
|
+
"customer_profile_id" : "customer_profile_id",
|
122
|
+
"customer_mobile" : "customer_mobile",
|
123
|
+
"customer_email" : "customer_email",
|
124
|
+
"card_number" : "card_number",
|
125
|
+
"expiry_year" : "expiry_year",
|
126
|
+
"expiry_month" : "expiry_month",
|
127
|
+
"cvv" : "cvv" }
|
128
|
+
|
129
|
+
res = Fawry.create_card_token(params)
|
130
|
+
#<Fawry::FawryResponse:0x0000556cb3eb0080 @fawry_api_response={"type"=>"CardTokenResponse", "card"=>{"token"=>"b598f96200f254c19b2718bfc825a063278888216c28962b3e66a393084ee9aed6", "creationDate"=>1607011562353, "lastFourDigits"=>"4242"}, "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CardTokenResponse", @status_code=200, @status_description="Operation done successfully", @card={"token"=>"b598f96200f254c19b2718bfc825a063278888216c28962b3e66a393084ee9aed6", "creationDate"=>1607011562353, "lastFourDigits"=>"4242"}>
|
131
|
+
|
132
|
+
res.success?
|
133
|
+
res.card
|
134
|
+
```
|
135
|
+
|
136
|
+
### حذف رمز كارت
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
params = { "merchant_code": 'merchant_code',
|
140
|
+
"customer_profile_id": 'customer_profile_id',
|
141
|
+
"card_token": 'card_token' }
|
142
|
+
|
143
|
+
res = Fawry.delete_token(params)
|
144
|
+
#<Fawry::FawryResponse:0x0000556cb57c2460 @fawry_api_response={"type"=>"CardTokenResponse", "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CardTokenResponse", @status_code=200, @status_description="Operation done successfully">
|
145
|
+
res.success?
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
### رد اتصال خدمة تحليل فوري v2
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
# تم إرسال المعلمات من خادم فوري
|
153
|
+
callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNumber": '970177',
|
154
|
+
"merchantRefNumber": '9708f1cea8b5426cb57922df51b7f790',
|
155
|
+
"customerMobile": '01004545545', "customerMail": 'fawry@fawry.com',
|
156
|
+
"paymentAmount": 152.00, "orderAmount": 150.00, "fawryFees": 2.00,
|
157
|
+
"shippingFees": '', "orderStatus": 'NEW', "paymentMethod": 'PAYATFAWRY',
|
158
|
+
"messageSignature": 'b0175565323e464b01dc9407160368af5568196997fb6e379374a4f4fbbcf587',
|
159
|
+
"orderExpiryDate": 1_533_554_719_314,
|
160
|
+
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
161
|
+
|
162
|
+
fawry_callback = Fawry.parse_callback(callback_params)
|
163
|
+
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
164
|
+
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
165
|
+
# @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
|
166
|
+
|
167
|
+
fawry_callback.fawry_ref_number # => 970177
|
168
|
+
fawry_callback.order_status # => NEW
|
169
|
+
```
|
170
|
+
|
171
|
+
## الخطوات القادمة المطلوب تنفيذها:
|
172
|
+
|
173
|
+
- إضافة خيار لرفع الاستثناء عند فشل الطلب
|
174
|
+
|
175
|
+
## تطوير المكتبة
|
176
|
+
|
177
|
+
بعد التحقق من الريبو ، قم بتشغيل `bin/setup` لتثبيت التبعيات.
|
178
|
+
ثم نفذ الأمر `rake spec` لإجراء الاختبارات. يمكنك أيضا الجري `bin/console` للمطالبة التفاعلية التي تسمح لك بالتجربة.
|
179
|
+
|
180
|
+
لتثبيت هذه المكتبة على جهازك ، قم بتشغيل `bundle exec rake install`. لإصدار إصدار جديد ، قم بتحديث رقم الإصدار بتنسيق `version.rb`, ثم نفذ الأمر `bundle exec rake release`, الذي سينشئ علامة git للإصدار ، ويدفع التزامات git والعلامات ، ويدفع ملف `.gem` يا صديق [rubygems.org](https://rubygems.org).
|
181
|
+
|
182
|
+
## المساهمة
|
183
|
+
|
184
|
+
يتم الترحيب بتقارير الأخطاء وطلبات السحب على GitHub في https://github.com/amrrbakry/fawry. يهدف هذا المشروع إلى أن يكون مساحة آمنة ومرحبة للتعاون ، ومن المتوقع أن يلتزم المساهمون بـ [Contributor Covenant](http://contributor-covenant.org) القواعد السلوكية.
|
data/README.md
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
# Fawry
|
4
4
|
|
5
|
-
|
5
|
+
[README - متوفر باللغة العربية](https://github.com/fawry-api/fawry/blob/master/README-ar.md)
|
6
|
+
|
7
|
+
**Disclaimer:** we are _not officially affilated_ with the _Fawry_ company.
|
6
8
|
|
7
|
-
-
|
8
|
-
- [Refund customers](https://github.com/fawry-api/fawry#refund-customers)
|
9
|
-
- [Get payment status](https://github.com/fawry-api/fawry#get-payment-status)
|
10
|
-
- [Parse Fawry's service callback V2](https://github.com/fawry-api/fawry#parse-fawry-service-callback-v2)
|
11
|
-
- [Configuration keys as environment variables](https://github.com/fawry-api/fawry#configuration-keys-as-environment-variables)
|
9
|
+
A plug-and-play library that makes interfacing with Fawry's payment gateway API a breeze:
|
12
10
|
|
13
11
|
_Fawry's production and sandbox environments are supported._
|
14
12
|
|
13
|
+
_This library is tested on Ruby v2.6, 2.7, 3.0_
|
14
|
+
|
15
15
|
## Installation
|
16
16
|
|
17
17
|
Add this line to your application's Gemfile:
|
@@ -28,6 +28,20 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
$ gem install fawry
|
30
30
|
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
Add an initializer `fawry.rb` in your application to configure the library:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Fawry.configure do |config|
|
37
|
+
config.sandbox = Rails.env.staging?
|
38
|
+
config.fawry_secure_key = 'fawry_secure_key'
|
39
|
+
config.fawry_merchant_code = 'fawry_merchant_code'
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Alternatively, you could use the environment variables: `FAWRY_SANDBOX`, `FAWRY_SECURE_KEY`, and `FAWRY_MERCHANT_CODE`.
|
44
|
+
|
31
45
|
## Usage
|
32
46
|
|
33
47
|
### Charge customers
|
@@ -40,13 +54,13 @@ params = { "merchant_code": 'merchant_code',
|
|
40
54
|
"payment_method": 'PAYATFAWRY',
|
41
55
|
"currency_code": 'EGP',
|
42
56
|
"amount": 20,
|
57
|
+
"language": "ar-eg",
|
43
58
|
"fawry_secure_key": 'fawry_secure_key',
|
44
59
|
"description": 'the charge request description',
|
45
60
|
"charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
|
46
61
|
"description": 'desc', "price": 20, "quantity": 1 }] }
|
47
62
|
|
48
|
-
|
49
|
-
res = Fawry.charge(params, sandbox: true)
|
63
|
+
res = Fawry.charge(params)
|
50
64
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
|
51
65
|
# @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
|
52
66
|
# @expiration_time=1573153206979, @status_code=200,
|
@@ -56,7 +70,7 @@ res.success? # => true
|
|
56
70
|
res.reference_number # => 931600239
|
57
71
|
```
|
58
72
|
|
59
|
-
###
|
73
|
+
### Refund Customers
|
60
74
|
|
61
75
|
```ruby
|
62
76
|
params = { "merchant_code": 'merchant_code',
|
@@ -64,21 +78,21 @@ params = { "merchant_code": 'merchant_code',
|
|
64
78
|
"refund_amount": 20,
|
65
79
|
"fawry_secure_key": 'fawry_secure_key' }
|
66
80
|
|
67
|
-
res = Fawry.refund(params
|
81
|
+
res = Fawry.refund(params)
|
68
82
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
|
69
83
|
# @status_description="Operation done successfully">
|
70
84
|
|
71
85
|
res.success? # => true
|
72
86
|
```
|
73
87
|
|
74
|
-
###
|
88
|
+
### Get Payment Status
|
75
89
|
|
76
90
|
```ruby
|
77
91
|
params = { "merchant_code": 'merchant_code',
|
78
92
|
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
79
93
|
"fawry_secure_key": 'fawry_secure_key' }
|
80
94
|
|
81
|
-
res = Fawry.payment_status(params
|
95
|
+
res = Fawry.payment_status(params)
|
82
96
|
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
83
97
|
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
84
98
|
# @expiration_time=1573297736167, @status_code=200,
|
@@ -89,7 +103,54 @@ res.success? # => true
|
|
89
103
|
res.payment_status # => UNPAID
|
90
104
|
```
|
91
105
|
|
92
|
-
###
|
106
|
+
### List Card Tokens
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
params = { "merchant_code": 'merchant_code',
|
110
|
+
"customer_profile_id": 'customer_profile_id',
|
111
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
112
|
+
|
113
|
+
res = Fawry.list_tokens(params)
|
114
|
+
#<Fawry::FawryResponse:0x0000556cb3a31798 @fawry_api_response={"type"=>"CustomerTokensResponse", "cards"=>[{"token"=>"b5sshhdsl98df96200f254c19b2718bfc825a0678888216c28962b3e66a393084ee9aed6", "creationDate"=>1599487402318, "lastFourDigits"=>"4242", "brand"=>"Visa Card"}, {"token"=>"fb98dslsksmkdds7857ed7042ce30a2a5b777e1f1ac6ac58da1c8c0199f61df7a8bc098e96", "creationDate"=>1599489158457, "lastFourDigits"=>"0001", "brand"=>"Visa Card"}, {"token"=>"cc03fwqaacbd94e468a1b756ac1cbb285a41a2428df9f1a727457b41f9447d0058c7c", "creationDate"=>1599584834346, "lastFourDigits"=>"2346", "brand"=>"MasterCard"}, {"token"=>"f04a8bc9c973f900515f4b58e52c9ff03070baf3f534bdfdad0e97679534f60ddkjk13", "creationDate"=>1600260415739, "lastFourDigits"=>"8769", "brand"=>"Visa Card"}], "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CustomerTokensResponse", @cards=[{"token"=>"b5sshhdsl98df96200f254c19b2718bfc825a0678888216c28962b3e66a393084ee9aed6", "creationDate"=>1599487402318, "lastFourDigits"=>"4242", "brand"=>"Visa Card"}, {"token"=>"fb98dslsksmkdds7857ed7042ce30a2a5b777e1f1ac6ac58da1c8c0199f61df7a8bc098e96", "creationDate"=>1599489158457, "lastFourDigits"=>"0001", "brand"=>"Visa Card"}, {"token"=>"cc03fwqaacbd94e468a1b756ac1cbb285a41a2428df9f1a727457b41f9447d0058c7c", "creationDate"=>1599584834346, "lastFourDigits"=>"2346", "brand"=>"MasterCard"}, {"token"=>"f04a8bc9c973f900515f4b58e52c9ff03070baf3f534bdfdad0e97679534f60ddkjk13", "creationDate"=>1600260415739, "lastFourDigits"=>"8769", "brand"=>"Visa Card"}], @status_code=200, @status_description="Operation done successfully">
|
115
|
+
|
116
|
+
res.success? # => true
|
117
|
+
res.cards # => cards
|
118
|
+
```
|
119
|
+
|
120
|
+
### Create Card Token
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
params = { "merchant_code" : "merchant_code",
|
124
|
+
"customer_profile_id" : "customer_profile_id",
|
125
|
+
"customer_mobile" : "customer_mobile",
|
126
|
+
"customer_email" : "customer_email",
|
127
|
+
"card_number" : "card_number",
|
128
|
+
"expiry_year" : "expiry_year",
|
129
|
+
"expiry_month" : "expiry_month",
|
130
|
+
"cvv" : "cvv" }
|
131
|
+
res = Fawry.create_card_token(params)
|
132
|
+
#<Fawry::FawryResponse:0x0000556cb3eb0080 @fawry_api_response={"type"=>"CardTokenResponse", "card"=>{"token"=>"b598f96200f254c19b2718bfc825a063278888216c28962b3e66a393084ee9aed6", "creationDate"=>1607011562353, "lastFourDigits"=>"4242"}, "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CardTokenResponse", @status_code=200, @status_description="Operation done successfully", @card={"token"=>"b598f96200f254c19b2718bfc825a063278888216c28962b3e66a393084ee9aed6", "creationDate"=>1607011562353, "lastFourDigits"=>"4242"}>
|
133
|
+
|
134
|
+
res.success?
|
135
|
+
res.card
|
136
|
+
```
|
137
|
+
|
138
|
+
### Delete Card Token
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
params = { "merchant_code": "merchant_code",
|
142
|
+
"customer_profile_id": "customer_profile_id",
|
143
|
+
"card_token": "card_token",
|
144
|
+
"fawry_secure_key": "fawry_secure_key" }
|
145
|
+
|
146
|
+
res = Fawry.delete_token(params)
|
147
|
+
#<Fawry::FawryResponse:0x0000556cb57c2460 @fawry_api_response={"type"=>"CardTokenResponse", "statusCode"=>200, "statusDescription"=>"Operation done successfully"}, @type="CardTokenResponse", @status_code=200, @status_description="Operation done successfully">
|
148
|
+
|
149
|
+
res.success?
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
### Parse Fawry service callback v2
|
93
154
|
|
94
155
|
```ruby
|
95
156
|
# params sent from fawry server
|
@@ -102,8 +163,7 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
|
|
102
163
|
"orderExpiryDate": 1_533_554_719_314,
|
103
164
|
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
104
165
|
|
105
|
-
|
106
|
-
fawry_callback = Fawry.parse_callback(callback_params, {})
|
166
|
+
fawry_callback = Fawry.parse_callback(callback_params)
|
107
167
|
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
108
168
|
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
109
169
|
# @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
|
@@ -112,15 +172,8 @@ fawry_callback.fawry_ref_number # => 970177
|
|
112
172
|
fawry_callback.order_status # => NEW
|
113
173
|
```
|
114
174
|
|
115
|
-
### Configuration keys as environment variables
|
116
|
-
|
117
|
-
Fawry configuration keys such as merchant code and secure key can be sent with the params (`merchant_code`, `fawry_secure_key` ) to the **charge**, **refund**, **payment_status** methods, _or_ they can be set as environment variables: (`FAWRY_MERCHANT_CODE`, `FAWRY_SECURE_KEY`).
|
118
|
-
|
119
|
-
To **parse** fawry callback, you _must_ set the env var `FAWRY_SECURE_KEY`.
|
120
|
-
|
121
175
|
## TODO:
|
122
176
|
|
123
|
-
- Add public API documentation to README
|
124
177
|
- Add option to raise exception on request failure
|
125
178
|
|
126
179
|
## Development
|