fawry 1.1.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.rubocop.yml +4 -3
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +81 -65
- data/README-ar.md +23 -25
- data/README.md +23 -24
- data/Rakefile +8 -1
- data/fawry.gemspec +9 -8
- data/lib/fawry/config.rb +17 -0
- data/lib/fawry/connection.rb +11 -6
- data/lib/fawry/contracts/charge_request_contract.rb +9 -4
- data/lib/fawry/contracts/create_card_token_request_contract.rb +4 -2
- data/lib/fawry/contracts/delete_token_request_contract.rb +8 -4
- data/lib/fawry/contracts/list_tokens_request_contract.rb +8 -4
- data/lib/fawry/contracts/payment_status_request_contract.rb +8 -4
- data/lib/fawry/contracts/refund_request_contract.rb +8 -4
- data/lib/fawry/errors.rb +1 -0
- data/lib/fawry/fawry_callback.rb +1 -1
- data/lib/fawry/fawry_request.rb +0 -2
- data/lib/fawry/requests/charge_request.rb +4 -3
- data/lib/fawry/requests/create_card_token_request.rb +2 -5
- data/lib/fawry/requests/delete_token_request.rb +2 -2
- data/lib/fawry/requests/list_tokens_request.rb +2 -2
- data/lib/fawry/requests/payment_status_request.rb +2 -2
- data/lib/fawry/requests/refund_request.rb +2 -2
- data/lib/fawry/utils.rb +3 -1
- data/lib/fawry/version.rb +1 -1
- data/lib/fawry.rb +8 -1
- metadata +18 -33
- data/.circleci/config.yml +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47e5eac31f75494992bedc65eae9f99ea3a4fe369f8194be3e0b7f1abe445a69
|
4
|
+
data.tar.gz: 2f803d4ec113061428dab757363f3c93a6d10c25d2dcb7674be591ab98edfbd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af7bf3f371239ca3a3f9918b88725b990a169b64aba1bb38c43bc7224eb9ef42d8d06cde4426bdb8ac9b3a9e4dc7d07476ea2720780621709d174cca15da2040
|
7
|
+
data.tar.gz: ae244b3ab8ad17adfb279f0f6c2f8b15d237b178eb21503d632143b03d751e2ee792ce1278dbdbf8d71b5f542732fbd706bbb5f82015e8791c74ed33716c9fed
|
@@ -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: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
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,10 @@
|
|
1
|
+
# Fawry Changelog
|
2
|
+
|
3
|
+
## [v1.4.0](https://github.com/fawry-api/fawry/releases/tag/v1.4.0) (24.12.2021)
|
4
|
+
- Update dependencies
|
5
|
+
|
6
|
+
## [v1.3.1](https://github.com/fawry-api/fawry/releases/tag/v1.3.1) (15.08.2021)
|
7
|
+
- Add language param to charge request params
|
8
|
+
|
9
|
+
## [v1.2.1](https://github.com/fawry-api/fawry/releases/tag/v1.2.1) (14.03.2021)
|
10
|
+
- Update gem and dependencies to support Ruby 3.0
|
data/Gemfile.lock
CHANGED
@@ -1,97 +1,113 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fawry (1.
|
5
|
-
dry-validation (~> 1.
|
6
|
-
faraday (~>
|
4
|
+
fawry (1.4.0)
|
5
|
+
dry-validation (~> 1.7)
|
6
|
+
faraday (~> 1.8)
|
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.9)
|
16
|
+
crack (0.4.5)
|
17
|
+
rexml
|
18
|
+
diff-lcs (1.5.0)
|
19
|
+
dry-configurable (0.13.0)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
|
-
dry-core (~> 0.
|
22
|
-
|
23
|
-
dry-container (0.7.2)
|
21
|
+
dry-core (~> 0.6)
|
22
|
+
dry-container (0.9.0)
|
24
23
|
concurrent-ruby (~> 1.0)
|
25
|
-
dry-configurable (~> 0.
|
26
|
-
dry-core (0.
|
24
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
25
|
+
dry-core (0.7.1)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
|
-
dry-
|
29
|
-
dry-inflector (0.2.0)
|
27
|
+
dry-inflector (0.2.1)
|
30
28
|
dry-initializer (3.0.4)
|
31
|
-
dry-logic (1.0
|
29
|
+
dry-logic (1.2.0)
|
32
30
|
concurrent-ruby (~> 1.0)
|
33
|
-
dry-core (~> 0.
|
34
|
-
|
35
|
-
dry-schema (1.5.5)
|
31
|
+
dry-core (~> 0.5, >= 0.5)
|
32
|
+
dry-schema (1.8.0)
|
36
33
|
concurrent-ruby (~> 1.0)
|
37
|
-
dry-configurable (~> 0.
|
38
|
-
dry-core (~> 0.
|
39
|
-
dry-equalizer (~> 0.2)
|
34
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
35
|
+
dry-core (~> 0.5, >= 0.5)
|
40
36
|
dry-initializer (~> 3.0)
|
41
37
|
dry-logic (~> 1.0)
|
42
|
-
dry-types (~> 1.
|
43
|
-
dry-types (1.
|
38
|
+
dry-types (~> 1.5)
|
39
|
+
dry-types (1.5.1)
|
44
40
|
concurrent-ruby (~> 1.0)
|
45
41
|
dry-container (~> 0.3)
|
46
|
-
dry-core (~> 0.
|
47
|
-
dry-equalizer (~> 0.3)
|
42
|
+
dry-core (~> 0.5, >= 0.5)
|
48
43
|
dry-inflector (~> 0.1, >= 0.1.2)
|
49
44
|
dry-logic (~> 1.0, >= 1.0.2)
|
50
|
-
dry-validation (1.
|
45
|
+
dry-validation (1.7.0)
|
51
46
|
concurrent-ruby (~> 1.0)
|
52
47
|
dry-container (~> 0.7, >= 0.7.1)
|
53
|
-
dry-core (~> 0.
|
54
|
-
dry-equalizer (~> 0.2)
|
48
|
+
dry-core (~> 0.5, >= 0.5)
|
55
49
|
dry-initializer (~> 3.0)
|
56
|
-
dry-schema (~> 1.
|
57
|
-
faraday (
|
50
|
+
dry-schema (~> 1.8, >= 1.8.0)
|
51
|
+
faraday (1.8.0)
|
52
|
+
faraday-em_http (~> 1.0)
|
53
|
+
faraday-em_synchrony (~> 1.0)
|
54
|
+
faraday-excon (~> 1.1)
|
55
|
+
faraday-httpclient (~> 1.0.1)
|
56
|
+
faraday-net_http (~> 1.0)
|
57
|
+
faraday-net_http_persistent (~> 1.1)
|
58
|
+
faraday-patron (~> 1.0)
|
59
|
+
faraday-rack (~> 1.0)
|
58
60
|
multipart-post (>= 1.2, < 3)
|
59
|
-
|
60
|
-
|
61
|
+
ruby2_keywords (>= 0.0.4)
|
62
|
+
faraday-em_http (1.0.0)
|
63
|
+
faraday-em_synchrony (1.0.0)
|
64
|
+
faraday-excon (1.1.0)
|
65
|
+
faraday-httpclient (1.0.1)
|
66
|
+
faraday-net_http (1.0.1)
|
67
|
+
faraday-net_http_persistent (1.2.0)
|
68
|
+
faraday-patron (1.0.0)
|
69
|
+
faraday-rack (1.0.0)
|
70
|
+
hashdiff (1.0.1)
|
61
71
|
multipart-post (2.1.1)
|
62
|
-
parallel (1.
|
63
|
-
parser (
|
64
|
-
ast (~> 2.4.
|
65
|
-
public_suffix (4.0.
|
72
|
+
parallel (1.21.0)
|
73
|
+
parser (3.0.3.2)
|
74
|
+
ast (~> 2.4.1)
|
75
|
+
public_suffix (4.0.6)
|
66
76
|
rainbow (3.0.0)
|
67
|
-
rake (13.0.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
rspec-
|
72
|
-
|
73
|
-
rspec-
|
74
|
-
rspec-
|
77
|
+
rake (13.0.6)
|
78
|
+
regexp_parser (2.2.0)
|
79
|
+
rexml (3.2.5)
|
80
|
+
rspec (3.10.0)
|
81
|
+
rspec-core (~> 3.10.0)
|
82
|
+
rspec-expectations (~> 3.10.0)
|
83
|
+
rspec-mocks (~> 3.10.0)
|
84
|
+
rspec-core (3.10.1)
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-expectations (3.10.1)
|
75
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
-
rspec-support (~> 3.
|
77
|
-
rspec-mocks (3.
|
88
|
+
rspec-support (~> 3.10.0)
|
89
|
+
rspec-mocks (3.10.2)
|
78
90
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-support (3.
|
91
|
+
rspec-support (~> 3.10.0)
|
92
|
+
rspec-support (3.10.3)
|
81
93
|
rspec_junit_formatter (0.4.1)
|
82
94
|
rspec-core (>= 2, < 4, != 2.12.0)
|
83
|
-
rubocop (
|
84
|
-
jaro_winkler (~> 1.5.1)
|
95
|
+
rubocop (1.24.0)
|
85
96
|
parallel (~> 1.10)
|
86
|
-
parser (>=
|
97
|
+
parser (>= 3.0.0.0)
|
87
98
|
rainbow (>= 2.2.2, < 4.0)
|
99
|
+
regexp_parser (>= 1.8, < 3.0)
|
100
|
+
rexml
|
101
|
+
rubocop-ast (>= 1.15.0, < 2.0)
|
88
102
|
ruby-progressbar (~> 1.7)
|
89
|
-
unicode-display_width (>= 1.4.0, <
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
103
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
104
|
+
rubocop-ast (1.15.0)
|
105
|
+
parser (>= 3.0.1.1)
|
106
|
+
ruby-progressbar (1.11.0)
|
107
|
+
ruby2_keywords (0.0.5)
|
108
|
+
unicode-display_width (2.1.0)
|
109
|
+
webmock (3.14.0)
|
110
|
+
addressable (>= 2.8.0)
|
95
111
|
crack (>= 0.3.2)
|
96
112
|
hashdiff (>= 0.4.0, < 2.0.0)
|
97
113
|
|
@@ -100,13 +116,13 @@ PLATFORMS
|
|
100
116
|
|
101
117
|
DEPENDENCIES
|
102
118
|
bundler (~> 2.0)
|
103
|
-
byebug (~> 11.0
|
119
|
+
byebug (~> 11.0)
|
104
120
|
fawry!
|
105
121
|
rake (~> 13.0)
|
106
122
|
rspec (~> 3.0)
|
107
123
|
rspec_junit_formatter
|
108
|
-
rubocop (~>
|
109
|
-
webmock (~> 3.
|
124
|
+
rubocop (~> 1.11)
|
125
|
+
webmock (~> 3.12)
|
110
126
|
|
111
127
|
BUNDLED WITH
|
112
|
-
2.
|
128
|
+
2.3.3
|
data/README-ar.md
CHANGED
@@ -6,15 +6,6 @@
|
|
6
6
|
|
7
7
|
مكتبة لتسهيل التعامل مع خدمات الدفع الخاصة بشبكة الدفع الإلكتروني فوري:
|
8
8
|
|
9
|
-
- [لإجراء عملية دفع](https://github.com/fawry-api/fawry#charge-customers)
|
10
|
-
- [لإجراء عملية استرداد](https://github.com/fawry-api/fawry#refund-customers)
|
11
|
-
- [حالة الدفع](https://github.com/fawry-api/fawry#get-payment-status)
|
12
|
-
- [عرض رموز الكروت](https://github.com/fawry-api/fawry#list-card-tokens)
|
13
|
-
- [إضافة رمز كارت](https://github.com/fawry-api/fawry#create-card-token)
|
14
|
-
- [حذف رمز كارت](https://github.com/fawry-api/fawry#delete-card-token)
|
15
|
-
- [تحليل رد خدمة فوري V2](https://github.com/fawry-api/fawry#parse-fawry-service-callback-v2)
|
16
|
-
- [طلب البيانات الخاصة بإعدادات الإستخدام](https://github.com/fawry-api/fawry#configuration-keys-as-environment-variables)
|
17
|
-
|
18
9
|
_المكتبة تدعم النظام التجريبي لفوري ايضا_
|
19
10
|
|
20
11
|
## لإضافة وتشغيل المكتبة
|
@@ -33,6 +24,20 @@ gem 'fawry'
|
|
33
24
|
|
34
25
|
$ gem install fawry
|
35
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
|
+
|
36
41
|
## طريقة الإستعمال
|
37
42
|
|
38
43
|
### لإجراء عملية دفع
|
@@ -45,14 +50,13 @@ params = { "merchant_code": 'merchant_code',
|
|
45
50
|
"payment_method": 'PAYATFAWRY',
|
46
51
|
"currency_code": 'EGP',
|
47
52
|
"amount": 20,
|
53
|
+
"language": "ar-eg",
|
48
54
|
"fawry_secure_key": 'fawry_secure_key',
|
49
55
|
"description": 'the charge request description',
|
50
56
|
"charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
|
51
57
|
"description": 'desc', "price": 20, "quantity": 1 }] }
|
52
58
|
|
53
|
-
|
54
|
-
# sandbox: true
|
55
|
-
res = Fawry.charge(params, sandbox: true)
|
59
|
+
res = Fawry.charge(params)
|
56
60
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
|
57
61
|
# @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
|
58
62
|
# @expiration_time=1573153206979, @status_code=200,
|
@@ -70,7 +74,7 @@ params = { "merchant_code": 'merchant_code',
|
|
70
74
|
"refund_amount": 20,
|
71
75
|
"fawry_secure_key": 'fawry_secure_key' }
|
72
76
|
|
73
|
-
res = Fawry.refund(params
|
77
|
+
res = Fawry.refund(params)
|
74
78
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
|
75
79
|
# @status_description="Operation done successfully">
|
76
80
|
|
@@ -84,7 +88,7 @@ params = { "merchant_code": 'merchant_code',
|
|
84
88
|
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
85
89
|
"fawry_secure_key": 'fawry_secure_key' }
|
86
90
|
|
87
|
-
res = Fawry.payment_status(params
|
91
|
+
res = Fawry.payment_status(params)
|
88
92
|
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
89
93
|
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
90
94
|
# @expiration_time=1573297736167, @status_code=200,
|
@@ -102,7 +106,7 @@ params = { "merchant_code": 'merchant_code',
|
|
102
106
|
"customer_profile_id": 'customer_profile_id',
|
103
107
|
"fawry_secure_key": 'fawry_secure_key' }
|
104
108
|
|
105
|
-
res = Fawry.list_tokens(params
|
109
|
+
res = Fawry.list_tokens(params)
|
106
110
|
|
107
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">
|
108
112
|
|
@@ -121,7 +125,8 @@ params = { "merchant_code" : "merchant_code",
|
|
121
125
|
"expiry_year" : "expiry_year",
|
122
126
|
"expiry_month" : "expiry_month",
|
123
127
|
"cvv" : "cvv" }
|
124
|
-
|
128
|
+
|
129
|
+
res = Fawry.create_card_token(params)
|
125
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"}>
|
126
131
|
|
127
132
|
res.success?
|
@@ -135,7 +140,7 @@ params = { "merchant_code": 'merchant_code',
|
|
135
140
|
"customer_profile_id": 'customer_profile_id',
|
136
141
|
"card_token": 'card_token' }
|
137
142
|
|
138
|
-
res = Fawry.delete_token(params
|
143
|
+
res = Fawry.delete_token(params)
|
139
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">
|
140
145
|
res.success?
|
141
146
|
|
@@ -154,8 +159,7 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
|
|
154
159
|
"orderExpiryDate": 1_533_554_719_314,
|
155
160
|
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
156
161
|
|
157
|
-
|
158
|
-
fawry_callback = Fawry.parse_callback(callback_params, {})
|
162
|
+
fawry_callback = Fawry.parse_callback(callback_params)
|
159
163
|
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
160
164
|
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
161
165
|
# @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
|
@@ -164,12 +168,6 @@ fawry_callback.fawry_ref_number # => 970177
|
|
164
168
|
fawry_callback.order_status # => NEW
|
165
169
|
```
|
166
170
|
|
167
|
-
### طلب البيانات الخاصة بإعدادات الإستخدام
|
168
|
-
|
169
|
-
يمكن إرسال بيانات تهيئة فوري مثل رمز التاجر ومفتاح الأمان خلال البيانات المعطاه (`merchant_code`, `fawry_secure_key` ) الى **charge**, **refund**, **payment_status** طرق, _أو_ يمكن تعيينها كمتغيرات لنظام التشغيل: (`FAWRY_MERCHANT_CODE`, `FAWRY_SECURE_KEY`).
|
170
|
-
|
171
|
-
لتحليل fawry معاودة الاتصال ، يجب عليك ضبط متغير البيئة `FAWRY_SECURE_KEY`.
|
172
|
-
|
173
171
|
## الخطوات القادمة المطلوب تنفيذها:
|
174
172
|
|
175
173
|
- إضافة خيار لرفع الاستثناء عند فشل الطلب
|
data/README.md
CHANGED
@@ -8,17 +8,10 @@
|
|
8
8
|
|
9
9
|
A plug-and-play library that makes interfacing with Fawry's payment gateway API a breeze:
|
10
10
|
|
11
|
-
- [Charge customers](https://github.com/fawry-api/fawry#charge-customers)
|
12
|
-
- [Refund customers](https://github.com/fawry-api/fawry#refund-customers)
|
13
|
-
- [Get payment status](https://github.com/fawry-api/fawry#get-payment-status)
|
14
|
-
- [List card tokens](https://github.com/fawry-api/fawry#list-card-tokens)
|
15
|
-
- [Create card token](https://github.com/fawry-api/fawry#create-card-token)
|
16
|
-
- [Delete card token](https://github.com/fawry-api/fawry#delete-card-token)
|
17
|
-
- [Parse Fawry's service callback V2](https://github.com/fawry-api/fawry#parse-fawry-service-callback-v2)
|
18
|
-
- [Configuration keys as environment variables](https://github.com/fawry-api/fawry#configuration-keys-as-environment-variables)
|
19
|
-
|
20
11
|
_Fawry's production and sandbox environments are supported._
|
21
12
|
|
13
|
+
_This library is tested on Ruby v2.6, 2.7, 3.0_
|
14
|
+
|
22
15
|
## Installation
|
23
16
|
|
24
17
|
Add this line to your application's Gemfile:
|
@@ -35,6 +28,20 @@ Or install it yourself as:
|
|
35
28
|
|
36
29
|
$ gem install fawry
|
37
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
|
+
|
38
45
|
## Usage
|
39
46
|
|
40
47
|
### Charge customers
|
@@ -47,13 +54,13 @@ params = { "merchant_code": 'merchant_code',
|
|
47
54
|
"payment_method": 'PAYATFAWRY',
|
48
55
|
"currency_code": 'EGP',
|
49
56
|
"amount": 20,
|
57
|
+
"language": "ar-eg",
|
50
58
|
"fawry_secure_key": 'fawry_secure_key',
|
51
59
|
"description": 'the charge request description',
|
52
60
|
"charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
|
53
61
|
"description": 'desc', "price": 20, "quantity": 1 }] }
|
54
62
|
|
55
|
-
|
56
|
-
res = Fawry.charge(params, sandbox: true)
|
63
|
+
res = Fawry.charge(params)
|
57
64
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
|
58
65
|
# @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
|
59
66
|
# @expiration_time=1573153206979, @status_code=200,
|
@@ -71,7 +78,7 @@ params = { "merchant_code": 'merchant_code',
|
|
71
78
|
"refund_amount": 20,
|
72
79
|
"fawry_secure_key": 'fawry_secure_key' }
|
73
80
|
|
74
|
-
res = Fawry.refund(params
|
81
|
+
res = Fawry.refund(params)
|
75
82
|
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
|
76
83
|
# @status_description="Operation done successfully">
|
77
84
|
|
@@ -85,7 +92,7 @@ params = { "merchant_code": 'merchant_code',
|
|
85
92
|
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
86
93
|
"fawry_secure_key": 'fawry_secure_key' }
|
87
94
|
|
88
|
-
res = Fawry.payment_status(params
|
95
|
+
res = Fawry.payment_status(params)
|
89
96
|
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
90
97
|
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
91
98
|
# @expiration_time=1573297736167, @status_code=200,
|
@@ -103,7 +110,7 @@ params = { "merchant_code": 'merchant_code',
|
|
103
110
|
"customer_profile_id": 'customer_profile_id',
|
104
111
|
"fawry_secure_key": 'fawry_secure_key' }
|
105
112
|
|
106
|
-
res = Fawry.list_tokens(params
|
113
|
+
res = Fawry.list_tokens(params)
|
107
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">
|
108
115
|
|
109
116
|
res.success? # => true
|
@@ -121,7 +128,7 @@ params = { "merchant_code" : "merchant_code",
|
|
121
128
|
"expiry_year" : "expiry_year",
|
122
129
|
"expiry_month" : "expiry_month",
|
123
130
|
"cvv" : "cvv" }
|
124
|
-
res = Fawry.create_card_token(params
|
131
|
+
res = Fawry.create_card_token(params)
|
125
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"}>
|
126
133
|
|
127
134
|
res.success?
|
@@ -136,7 +143,7 @@ params = { "merchant_code": "merchant_code",
|
|
136
143
|
"card_token": "card_token",
|
137
144
|
"fawry_secure_key": "fawry_secure_key" }
|
138
145
|
|
139
|
-
res = Fawry.delete_token(params
|
146
|
+
res = Fawry.delete_token(params)
|
140
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">
|
141
148
|
|
142
149
|
res.success?
|
@@ -156,7 +163,6 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
|
|
156
163
|
"orderExpiryDate": 1_533_554_719_314,
|
157
164
|
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
158
165
|
|
159
|
-
# FAWRY_SECURE_KEY env var must be set
|
160
166
|
fawry_callback = Fawry.parse_callback(callback_params)
|
161
167
|
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
162
168
|
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
@@ -166,15 +172,8 @@ fawry_callback.fawry_ref_number # => 970177
|
|
166
172
|
fawry_callback.order_status # => NEW
|
167
173
|
```
|
168
174
|
|
169
|
-
### Configuration keys as environment variables
|
170
|
-
|
171
|
-
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`).
|
172
|
-
|
173
|
-
To **parse** fawry callback, you _must_ set the env var `FAWRY_SECURE_KEY`.
|
174
|
-
|
175
175
|
## TODO:
|
176
176
|
|
177
|
-
- Add public API documentation to README
|
178
177
|
- Add option to raise exception on request failure
|
179
178
|
|
180
179
|
## Development
|
data/Rakefile
CHANGED
@@ -2,10 +2,17 @@
|
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RuboCop::RakeTask.new(:rubocop)
|
7
9
|
|
8
|
-
task default: :
|
10
|
+
task default: :rspec_rubocop
|
11
|
+
|
12
|
+
task :rspec_rubocop do
|
13
|
+
Rake::Task['rubocop'].invoke
|
14
|
+
Rake::Task['spec'].invoke
|
15
|
+
end
|
9
16
|
|
10
17
|
desc 'Start a console session with Fawry gem loaded'
|
11
18
|
task :console do
|
data/fawry.gemspec
CHANGED
@@ -7,17 +7,18 @@ require 'fawry/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'fawry'
|
9
9
|
spec.version = Fawry::VERSION
|
10
|
-
spec.authors = ['Amr Bakry']
|
11
|
-
spec.email = ['
|
10
|
+
spec.authors = ['Amr El Bakry']
|
11
|
+
spec.email = ['amrr@hey.com']
|
12
12
|
|
13
13
|
spec.summary = "A library to interface with Fawry's payment gateway API (charge, refund, payment status,
|
14
14
|
service callback)."
|
15
15
|
spec.homepage = 'https://github.com/amrrbakry/fawry'
|
16
16
|
spec.license = 'MIT'
|
17
|
-
spec.required_ruby_version = '
|
17
|
+
spec.required_ruby_version = '>= 2.6'
|
18
18
|
|
19
19
|
spec.metadata['homepage_uri'] = 'https://github.com/amrrbakry/fawry'
|
20
20
|
spec.metadata['source_code_uri'] = 'https://github.com/amrrbakry/fawry'
|
21
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
21
22
|
|
22
23
|
# Specify which files should be added to the gem when it is released.
|
23
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -28,14 +29,14 @@ Gem::Specification.new do |spec|
|
|
28
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
30
|
spec.require_paths = ['lib']
|
30
31
|
|
31
|
-
spec.add_dependency 'dry-validation', '~> 1.
|
32
|
-
spec.add_dependency 'faraday', '~>
|
32
|
+
spec.add_dependency 'dry-validation', '~> 1.7'
|
33
|
+
spec.add_dependency 'faraday', '~> 1.8'
|
33
34
|
|
34
35
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
35
|
-
spec.add_development_dependency 'byebug', '~> 11.0'
|
36
|
+
spec.add_development_dependency 'byebug', '~> 11.0'
|
36
37
|
spec.add_development_dependency 'rake', '~> 13.0'
|
37
38
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
39
|
spec.add_development_dependency 'rspec_junit_formatter'
|
39
|
-
spec.add_development_dependency 'rubocop', '~>
|
40
|
-
spec.add_development_dependency 'webmock', '~> 3.
|
40
|
+
spec.add_development_dependency 'rubocop', '~> 1.11'
|
41
|
+
spec.add_development_dependency 'webmock', '~> 3.12'
|
41
42
|
end
|
data/lib/fawry/config.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fawry
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
|
7
|
+
def configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :sandbox, :fawry_secure_key, :fawry_merchant_code
|
16
|
+
end
|
17
|
+
end
|
data/lib/fawry/connection.rb
CHANGED
@@ -10,8 +10,11 @@ module Fawry
|
|
10
10
|
FAWRY_SANDBOX_BASE_URL = 'https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/'
|
11
11
|
|
12
12
|
class << self
|
13
|
+
include Utils
|
14
|
+
|
13
15
|
def post(path, params, body, options)
|
14
|
-
|
16
|
+
sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
|
17
|
+
conn = sandbox ? sandbox_connection : connection
|
15
18
|
|
16
19
|
conn.post(path) do |request|
|
17
20
|
request.params = params
|
@@ -20,7 +23,8 @@ module Fawry
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def get(path, params, body, options)
|
23
|
-
|
26
|
+
sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
|
27
|
+
conn = sandbox ? sandbox_connection : connection
|
24
28
|
|
25
29
|
conn.get(path) do |request|
|
26
30
|
request.params = params
|
@@ -31,7 +35,8 @@ module Fawry
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def delete(path, params, body, options)
|
34
|
-
|
38
|
+
sandbox = Fawry.configuration.sandbox || TRUTH_VALUES.include?(ENV.fetch('FAWRY_SANDBOX', options[:sandbox]))
|
39
|
+
conn = sandbox ? sandbox_connection : connection
|
35
40
|
|
36
41
|
conn.delete(path) do |request|
|
37
42
|
request.params = params
|
@@ -45,12 +50,12 @@ module Fawry
|
|
45
50
|
|
46
51
|
def connection
|
47
52
|
@connection ||= Faraday.new(url: FAWRY_BASE_URL, headers: { 'Content-Type': 'application/json',
|
48
|
-
|
53
|
+
Accept: 'application/json' })
|
49
54
|
end
|
50
55
|
|
51
56
|
def sandbox_connection
|
52
57
|
@sandbox_connection ||= Faraday.new(url: FAWRY_SANDBOX_BASE_URL, headers: { 'Content-Type': 'application/json',
|
53
|
-
|
58
|
+
Accept: 'application/json' })
|
54
59
|
end
|
55
60
|
|
56
61
|
# Fawry does not understand encoded params
|
@@ -64,7 +69,7 @@ module Fawry
|
|
64
69
|
|
65
70
|
def self.decode(string)
|
66
71
|
arr = string.split('&')
|
67
|
-
arr.
|
72
|
+
arr.to_h { |str| str.split('=') }
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
@@ -17,6 +17,7 @@ module Fawry
|
|
17
17
|
required(:price).value(:decimal)
|
18
18
|
required(:quantity).value(:integer)
|
19
19
|
end
|
20
|
+
optional(:language).value(included_in?: %w[ar-eg en-gb])
|
20
21
|
optional(:merchant_code).value(:string)
|
21
22
|
optional(:fawry_secure_key).value(:string)
|
22
23
|
optional(:currency_code).value(:string)
|
@@ -39,14 +40,18 @@ module Fawry
|
|
39
40
|
end
|
40
41
|
|
41
42
|
rule(:fawry_secure_key) do
|
42
|
-
if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
43
|
-
key(:fawry_secure_key)
|
43
|
+
if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
44
|
+
key(:fawry_secure_key)
|
45
|
+
.failure('fawry secure key is required in either Fawry.configuration or'\
|
46
|
+
'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
50
|
rule(:merchant_code) do
|
48
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
49
|
-
key(:merchant_code)
|
51
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
52
|
+
key(:merchant_code)
|
53
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
54
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
@@ -23,8 +23,10 @@ module Fawry
|
|
23
23
|
end
|
24
24
|
|
25
25
|
rule(:merchant_code) do
|
26
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
27
|
-
key(:merchant_code)
|
26
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
27
|
+
key(:merchant_code)
|
28
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
29
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -13,14 +13,18 @@ module Fawry
|
|
13
13
|
end
|
14
14
|
|
15
15
|
rule(:fawry_secure_key) do
|
16
|
-
if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
17
|
-
key(:fawry_secure_key)
|
16
|
+
if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
17
|
+
key(:fawry_secure_key)
|
18
|
+
.failure('fawry secure key is required in either Fawry.configuration or'\
|
19
|
+
'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
rule(:merchant_code) do
|
22
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
23
|
-
key(:merchant_code)
|
24
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
25
|
+
key(:merchant_code)
|
26
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
27
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
@@ -12,14 +12,18 @@ module Fawry
|
|
12
12
|
end
|
13
13
|
|
14
14
|
rule(:fawry_secure_key) do
|
15
|
-
if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
16
|
-
key(:fawry_secure_key)
|
15
|
+
if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
16
|
+
key(:fawry_secure_key)
|
17
|
+
.failure('fawry secure key is required in either Fawry.configuration or'\
|
18
|
+
'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
rule(:merchant_code) do
|
21
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
22
|
-
key(:merchant_code)
|
23
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
24
|
+
key(:merchant_code)
|
25
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
26
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -12,14 +12,18 @@ module Fawry
|
|
12
12
|
end
|
13
13
|
|
14
14
|
rule(:fawry_secure_key) do
|
15
|
-
if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
16
|
-
key(:fawry_secure_key)
|
15
|
+
if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
16
|
+
key(:fawry_secure_key)
|
17
|
+
.failure('fawry secure key is required in either Fawry.configuration or'\
|
18
|
+
'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
rule(:merchant_code) do
|
21
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
22
|
-
key(:merchant_code)
|
23
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
24
|
+
key(:merchant_code)
|
25
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
26
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -14,14 +14,18 @@ module Fawry
|
|
14
14
|
end
|
15
15
|
|
16
16
|
rule(:fawry_secure_key) do
|
17
|
-
if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
18
|
-
key(:fawry_secure_key)
|
17
|
+
if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
|
18
|
+
key(:fawry_secure_key)
|
19
|
+
.failure('fawry secure key is required in either Fawry.configuration or'\
|
20
|
+
'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
rule(:merchant_code) do
|
23
|
-
if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
24
|
-
key(:merchant_code)
|
25
|
+
if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
|
26
|
+
key(:merchant_code)
|
27
|
+
.failure('fawry merchant code is required in either Fawry.configuration or'\
|
28
|
+
'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/lib/fawry/errors.rb
CHANGED
data/lib/fawry/fawry_callback.rb
CHANGED
@@ -8,7 +8,7 @@ module Fawry
|
|
8
8
|
|
9
9
|
def initialize(callback_params, opts)
|
10
10
|
@callback_params = callback_params
|
11
|
-
@fawry_secure_key = ENV.fetch('FAWRY_SECURE_KEY')
|
11
|
+
@fawry_secure_key = Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY')
|
12
12
|
@options = opts
|
13
13
|
end
|
14
14
|
|
data/lib/fawry/fawry_request.rb
CHANGED
@@ -18,7 +18,6 @@ module Fawry
|
|
18
18
|
|
19
19
|
# rubocop:disable Metrics/MethodLength
|
20
20
|
# rubocop:disable Metrics/AbcSize
|
21
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
22
21
|
def build_request
|
23
22
|
case action
|
24
23
|
when 'charge'
|
@@ -46,7 +45,6 @@ module Fawry
|
|
46
45
|
validate_delete_token_params!
|
47
46
|
@request = build_delete_token_request
|
48
47
|
end
|
49
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
50
48
|
# rubocop:enable Metrics/AbcSize
|
51
49
|
# rubocop:enable Metrics/MethodLength
|
52
50
|
end
|
@@ -5,7 +5,7 @@ require 'digest'
|
|
5
5
|
module Fawry
|
6
6
|
module Requests
|
7
7
|
module ChargeRequest
|
8
|
-
DEFAULTS = { payment_method: 'PAYATFAWRY', currency_code: 'EGP' }.freeze
|
8
|
+
DEFAULTS = { payment_method: 'PAYATFAWRY', currency_code: 'EGP', language: 'ar-eg' }.freeze
|
9
9
|
|
10
10
|
def fire_charge_request
|
11
11
|
fawry_api_response = Connection.post(request[:path], request[:params], request[:body], request[:options])
|
@@ -45,6 +45,7 @@ module Fawry
|
|
45
45
|
paymentExpiry: request_params[:payment_expiry],
|
46
46
|
chargeItems: charge_items,
|
47
47
|
currencyCode: request_params[:currency_code],
|
48
|
+
language: request_params[:language],
|
48
49
|
signature: charge_request_signature
|
49
50
|
}.compact
|
50
51
|
end
|
@@ -52,11 +53,11 @@ module Fawry
|
|
52
53
|
# rubocop:enable Metrics/AbcSize
|
53
54
|
|
54
55
|
def fawry_merchant_code
|
55
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
56
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
56
57
|
end
|
57
58
|
|
58
59
|
def fawry_secure_key
|
59
|
-
ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
60
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
60
61
|
end
|
61
62
|
|
62
63
|
def validate_charge_params!
|
@@ -27,7 +27,6 @@ module Fawry
|
|
27
27
|
@create_card_token_request ||= params
|
28
28
|
end
|
29
29
|
|
30
|
-
# rubocop:disable Metrics/AbcSize
|
31
30
|
def create_card_token_request_transformed_params
|
32
31
|
{
|
33
32
|
merchantCode: fawry_merchant_code,
|
@@ -41,14 +40,12 @@ module Fawry
|
|
41
40
|
}.compact
|
42
41
|
end
|
43
42
|
|
44
|
-
# rubocop:enable Metrics/AbcSize
|
45
|
-
|
46
43
|
def fawry_merchant_code
|
47
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') {
|
44
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
48
45
|
end
|
49
46
|
|
50
47
|
def fawry_secure_key
|
51
|
-
ENV.fetch('FAWRY_SECURE_KEY') {
|
48
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
52
49
|
end
|
53
50
|
|
54
51
|
def validate_card_token_params!
|
@@ -37,11 +37,11 @@ module Fawry
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def fawry_merchant_code
|
40
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
40
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
41
41
|
end
|
42
42
|
|
43
43
|
def fawry_secure_key
|
44
|
-
ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
44
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
45
45
|
end
|
46
46
|
|
47
47
|
def card_token
|
@@ -36,11 +36,11 @@ module Fawry
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def fawry_merchant_code
|
39
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
39
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
40
40
|
end
|
41
41
|
|
42
42
|
def fawry_secure_key
|
43
|
-
ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
43
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
44
44
|
end
|
45
45
|
|
46
46
|
def validate_list_tokens_params!
|
@@ -36,11 +36,11 @@ module Fawry
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def fawry_merchant_code
|
39
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
39
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
40
40
|
end
|
41
41
|
|
42
42
|
def fawry_secure_key
|
43
|
-
ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
43
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
44
44
|
end
|
45
45
|
|
46
46
|
def validate_payment_status_params!
|
@@ -38,11 +38,11 @@ module Fawry
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def fawry_merchant_code
|
41
|
-
ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
41
|
+
Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
|
42
42
|
end
|
43
43
|
|
44
44
|
def fawry_secure_key
|
45
|
-
ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
45
|
+
Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
|
46
46
|
end
|
47
47
|
|
48
48
|
def validate_refund_params!
|
data/lib/fawry/utils.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Fawry
|
4
4
|
module Utils
|
5
|
+
TRUTH_VALUES = [true, 'true', '1', 't'].freeze
|
6
|
+
|
5
7
|
# Adds keys from fawry API response as methods
|
6
8
|
# on object instance that return the value
|
7
9
|
# of each key
|
@@ -17,7 +19,7 @@ module Fawry
|
|
17
19
|
# fawry_res.status_code => 200
|
18
20
|
# fawry_res.reference_number => 1234567
|
19
21
|
def enrich_object(fawry_params)
|
20
|
-
fawry_params.
|
22
|
+
fawry_params.each_key do |key|
|
21
23
|
method_name = key.to_s.split(/(?=[A-Z])/).map(&:downcase).join('_') # statusCode => status_code
|
22
24
|
instance_variable_set("@#{method_name}", fawry_params[key])
|
23
25
|
method_body = proc { instance_variable_get("@#{method_name}") }
|
data/lib/fawry/version.rb
CHANGED
data/lib/fawry.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fawry/version'
|
4
|
+
require 'fawry/utils'
|
4
5
|
require 'fawry/connection'
|
6
|
+
require 'fawry/config'
|
5
7
|
require 'fawry/errors'
|
6
|
-
require 'fawry/utils'
|
7
8
|
require 'fawry/fawry_request'
|
8
9
|
require 'fawry/fawry_response'
|
9
10
|
require 'fawry/fawry_callback'
|
@@ -21,6 +22,12 @@ require 'fawry/contracts/list_tokens_request_contract'
|
|
21
22
|
require 'fawry/contracts/delete_token_request_contract'
|
22
23
|
|
23
24
|
module Fawry
|
25
|
+
configure do |config|
|
26
|
+
config.sandbox = false
|
27
|
+
config.fawry_secure_key = nil
|
28
|
+
config.fawry_merchant_code = nil
|
29
|
+
end
|
30
|
+
|
24
31
|
class << self
|
25
32
|
# Sends a charge request to Fawry API
|
26
33
|
# performs param validation and builds
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fawry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Amr Bakry
|
7
|
+
- Amr El Bakry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.3.1
|
19
|
+
version: '1.7'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.3.1
|
26
|
+
version: '1.7'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: faraday
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
33
|
+
version: '1.8'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
version: '1.8'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: bundler
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,9 +59,6 @@ dependencies:
|
|
65
59
|
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '11.0'
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 11.0.1
|
71
62
|
type: :development
|
72
63
|
prerelease: false
|
73
64
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -75,9 +66,6 @@ dependencies:
|
|
75
66
|
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '11.0'
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 11.0.1
|
81
69
|
- !ruby/object:Gem::Dependency
|
82
70
|
name: rake
|
83
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,45 +114,40 @@ dependencies:
|
|
126
114
|
requirements:
|
127
115
|
- - "~>"
|
128
116
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
117
|
+
version: '1.11'
|
130
118
|
type: :development
|
131
119
|
prerelease: false
|
132
120
|
version_requirements: !ruby/object:Gem::Requirement
|
133
121
|
requirements:
|
134
122
|
- - "~>"
|
135
123
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
124
|
+
version: '1.11'
|
137
125
|
- !ruby/object:Gem::Dependency
|
138
126
|
name: webmock
|
139
127
|
requirement: !ruby/object:Gem::Requirement
|
140
128
|
requirements:
|
141
129
|
- - "~>"
|
142
130
|
- !ruby/object:Gem::Version
|
143
|
-
version: '3.
|
144
|
-
- - ">="
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: 3.7.6
|
131
|
+
version: '3.12'
|
147
132
|
type: :development
|
148
133
|
prerelease: false
|
149
134
|
version_requirements: !ruby/object:Gem::Requirement
|
150
135
|
requirements:
|
151
136
|
- - "~>"
|
152
137
|
- !ruby/object:Gem::Version
|
153
|
-
version: '3.
|
154
|
-
- - ">="
|
155
|
-
- !ruby/object:Gem::Version
|
156
|
-
version: 3.7.6
|
138
|
+
version: '3.12'
|
157
139
|
description:
|
158
140
|
email:
|
159
|
-
-
|
141
|
+
- amrr@hey.com
|
160
142
|
executables: []
|
161
143
|
extensions: []
|
162
144
|
extra_rdoc_files: []
|
163
145
|
files:
|
164
|
-
- ".
|
146
|
+
- ".github/workflows/ruby.yml"
|
165
147
|
- ".gitignore"
|
166
148
|
- ".rspec"
|
167
149
|
- ".rubocop.yml"
|
150
|
+
- CHANGELOG.md
|
168
151
|
- CODE_OF_CONDUCT.md
|
169
152
|
- Gemfile
|
170
153
|
- Gemfile.lock
|
@@ -176,6 +159,7 @@ files:
|
|
176
159
|
- bin/setup
|
177
160
|
- fawry.gemspec
|
178
161
|
- lib/fawry.rb
|
162
|
+
- lib/fawry/config.rb
|
179
163
|
- lib/fawry/connection.rb
|
180
164
|
- lib/fawry/contracts/charge_request_contract.rb
|
181
165
|
- lib/fawry/contracts/create_card_token_request_contract.rb
|
@@ -201,13 +185,14 @@ licenses:
|
|
201
185
|
metadata:
|
202
186
|
homepage_uri: https://github.com/amrrbakry/fawry
|
203
187
|
source_code_uri: https://github.com/amrrbakry/fawry
|
188
|
+
rubygems_mfa_required: 'true'
|
204
189
|
post_install_message:
|
205
190
|
rdoc_options: []
|
206
191
|
require_paths:
|
207
192
|
- lib
|
208
193
|
required_ruby_version: !ruby/object:Gem::Requirement
|
209
194
|
requirements:
|
210
|
-
- - "
|
195
|
+
- - ">="
|
211
196
|
- !ruby/object:Gem::Version
|
212
197
|
version: '2.6'
|
213
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -216,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
201
|
- !ruby/object:Gem::Version
|
217
202
|
version: '0'
|
218
203
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
204
|
+
rubygems_version: 3.2.32
|
220
205
|
signing_key:
|
221
206
|
specification_version: 4
|
222
207
|
summary: A library to interface with Fawry's payment gateway API (charge, refund,
|
data/.circleci/config.yml
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.6.0
|
6
|
-
|
7
|
-
working_directory: ~/repo
|
8
|
-
|
9
|
-
steps:
|
10
|
-
- checkout
|
11
|
-
|
12
|
-
# Download and cache dependencies
|
13
|
-
- restore_cache:
|
14
|
-
keys:
|
15
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
16
|
-
# fallback to using the latest cache if no exact match is found
|
17
|
-
- v1-dependencies-
|
18
|
-
|
19
|
-
- run:
|
20
|
-
name: install bundler
|
21
|
-
command: gem install bundler
|
22
|
-
|
23
|
-
- run:
|
24
|
-
name: install dependencies
|
25
|
-
command: |
|
26
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
27
|
-
|
28
|
-
- save_cache:
|
29
|
-
paths:
|
30
|
-
- ./vendor/bundle
|
31
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
32
|
-
|
33
|
-
# run tests!
|
34
|
-
- run:
|
35
|
-
name: run tests
|
36
|
-
command: |
|
37
|
-
mkdir /tmp/test-results
|
38
|
-
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
39
|
-
circleci tests split --split-by=timings)"
|
40
|
-
|
41
|
-
bundle exec rspec \
|
42
|
-
--format progress \
|
43
|
-
--format RspecJunitFormatter \
|
44
|
-
--out /tmp/test-results/rspec.xml \
|
45
|
-
--format progress \
|
46
|
-
$TEST_FILES
|
47
|
-
|
48
|
-
- run:
|
49
|
-
name: run rubocop
|
50
|
-
command: bundle exec rubocop
|
51
|
-
|
52
|
-
# collect reports
|
53
|
-
- store_test_results:
|
54
|
-
path: /tmp/test-results
|
55
|
-
- store_artifacts:
|
56
|
-
path: /tmp/test-results
|
57
|
-
destination: test-results
|