fawry 0.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +57 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.rubocop.yml +5 -2
- data/Gemfile.lock +48 -24
- data/README-ar.md +186 -0
- data/README.md +121 -13
- data/Rakefile +18 -1
- data/fawry.gemspec +8 -5
- data/lib/fawry.rb +150 -8
- data/lib/fawry/connection.rb +41 -4
- data/lib/fawry/contracts/charge_request_contract.rb +14 -2
- data/lib/fawry/contracts/create_card_token_request_contract.rb +32 -0
- data/lib/fawry/contracts/delete_token_request_contract.rb +28 -0
- data/lib/fawry/contracts/list_tokens_request_contract.rb +27 -0
- data/lib/fawry/contracts/payment_status_request_contract.rb +27 -0
- data/lib/fawry/contracts/refund_request_contract.rb +14 -2
- data/lib/fawry/errors.rb +3 -1
- data/lib/fawry/fawry_callback.rb +56 -0
- data/lib/fawry/fawry_request.rb +20 -0
- data/lib/fawry/fawry_response.rb +3 -7
- data/lib/fawry/requests/charge_request.rb +18 -6
- 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 +57 -0
- data/lib/fawry/requests/refund_request.rb +14 -6
- data/lib/fawry/utils.rb +29 -0
- data/lib/fawry/version.rb +1 -1
- metadata +54 -26
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7321464f0d145904cb1b356fc8b0659f7258e5693c4c3a32e6ae3276198a5e
|
4
|
+
data.tar.gz: c7bc36bbe23c12fbe7b7ea0b5397cfbf9a5bf696440806a1a7200e61fd10e4c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff0c0665c07f5b0abd0b68ece79e6ab934c8c91e2387571986ad652af08e31cae9e8e0a3674aa180b9badbbb7833df24a6e64c8da5f9383ab97299454de4090
|
7
|
+
data.tar.gz: c1a8cdeef0c8fe57010ef68491e95ba88d99c5f990a123829afe03e78c7704a4184c101cd72ed145747d71972e085cf1ace26617feff0b42d781eb4af56d3ff6
|
@@ -0,0 +1,57 @@
|
|
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
|
@@ -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
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fawry (
|
4
|
+
fawry (1.2.1)
|
5
5
|
dry-validation (~> 1.3, >= 1.3.1)
|
6
6
|
faraday (~> 0.17.0)
|
7
7
|
|
@@ -10,54 +10,62 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
addressable (2.7.0)
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.2)
|
13
14
|
byebug (11.0.1)
|
14
|
-
concurrent-ruby (1.1.
|
15
|
-
crack (0.4.
|
16
|
-
|
15
|
+
concurrent-ruby (1.1.7)
|
16
|
+
crack (0.4.5)
|
17
|
+
rexml
|
17
18
|
diff-lcs (1.3)
|
18
|
-
dry-configurable (0.
|
19
|
+
dry-configurable (0.11.6)
|
19
20
|
concurrent-ruby (~> 1.0)
|
20
21
|
dry-core (~> 0.4, >= 0.4.7)
|
22
|
+
dry-equalizer (~> 0.2)
|
21
23
|
dry-container (0.7.2)
|
22
24
|
concurrent-ruby (~> 1.0)
|
23
25
|
dry-configurable (~> 0.1, >= 0.1.3)
|
24
26
|
dry-core (0.4.9)
|
25
27
|
concurrent-ruby (~> 1.0)
|
26
|
-
dry-equalizer (0.
|
28
|
+
dry-equalizer (0.3.0)
|
27
29
|
dry-inflector (0.2.0)
|
28
|
-
dry-initializer (3.0.
|
29
|
-
dry-logic (1.0.
|
30
|
+
dry-initializer (3.0.4)
|
31
|
+
dry-logic (1.0.8)
|
30
32
|
concurrent-ruby (~> 1.0)
|
31
33
|
dry-core (~> 0.2)
|
32
34
|
dry-equalizer (~> 0.2)
|
33
|
-
dry-schema (1.
|
35
|
+
dry-schema (1.5.5)
|
34
36
|
concurrent-ruby (~> 1.0)
|
35
37
|
dry-configurable (~> 0.8, >= 0.8.3)
|
36
38
|
dry-core (~> 0.4)
|
37
39
|
dry-equalizer (~> 0.2)
|
38
40
|
dry-initializer (~> 3.0)
|
39
41
|
dry-logic (~> 1.0)
|
40
|
-
dry-types (~> 1.
|
41
|
-
dry-types (1.
|
42
|
+
dry-types (~> 1.4)
|
43
|
+
dry-types (1.4.0)
|
42
44
|
concurrent-ruby (~> 1.0)
|
43
45
|
dry-container (~> 0.3)
|
44
46
|
dry-core (~> 0.4, >= 0.4.4)
|
45
|
-
dry-equalizer (~> 0.
|
47
|
+
dry-equalizer (~> 0.3)
|
46
48
|
dry-inflector (~> 0.1, >= 0.1.2)
|
47
49
|
dry-logic (~> 1.0, >= 1.0.2)
|
48
|
-
dry-validation (1.
|
50
|
+
dry-validation (1.5.6)
|
49
51
|
concurrent-ruby (~> 1.0)
|
50
52
|
dry-container (~> 0.7, >= 0.7.1)
|
51
53
|
dry-core (~> 0.4)
|
52
54
|
dry-equalizer (~> 0.2)
|
53
55
|
dry-initializer (~> 3.0)
|
54
|
-
dry-schema (~> 1.
|
55
|
-
faraday (0.17.
|
56
|
+
dry-schema (~> 1.5, >= 1.5.2)
|
57
|
+
faraday (0.17.4)
|
56
58
|
multipart-post (>= 1.2, < 3)
|
57
|
-
hashdiff (1.0.
|
59
|
+
hashdiff (1.0.1)
|
58
60
|
multipart-post (2.1.1)
|
59
|
-
|
60
|
-
|
61
|
+
parallel (1.20.1)
|
62
|
+
parser (3.0.0.0)
|
63
|
+
ast (~> 2.4.1)
|
64
|
+
public_suffix (4.0.6)
|
65
|
+
rainbow (3.0.0)
|
66
|
+
rake (13.0.1)
|
67
|
+
regexp_parser (2.1.1)
|
68
|
+
rexml (3.2.4)
|
61
69
|
rspec (3.9.0)
|
62
70
|
rspec-core (~> 3.9.0)
|
63
71
|
rspec-expectations (~> 3.9.0)
|
@@ -71,8 +79,22 @@ GEM
|
|
71
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
72
80
|
rspec-support (~> 3.9.0)
|
73
81
|
rspec-support (3.9.0)
|
74
|
-
|
75
|
-
|
82
|
+
rspec_junit_formatter (0.4.1)
|
83
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
84
|
+
rubocop (1.11.0)
|
85
|
+
parallel (~> 1.10)
|
86
|
+
parser (>= 3.0.0.0)
|
87
|
+
rainbow (>= 2.2.2, < 4.0)
|
88
|
+
regexp_parser (>= 1.8, < 3.0)
|
89
|
+
rexml
|
90
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
91
|
+
ruby-progressbar (~> 1.7)
|
92
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
93
|
+
rubocop-ast (1.4.1)
|
94
|
+
parser (>= 2.7.1.5)
|
95
|
+
ruby-progressbar (1.11.0)
|
96
|
+
unicode-display_width (2.0.0)
|
97
|
+
webmock (3.12.1)
|
76
98
|
addressable (>= 2.3.6)
|
77
99
|
crack (>= 0.3.2)
|
78
100
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -82,11 +104,13 @@ PLATFORMS
|
|
82
104
|
|
83
105
|
DEPENDENCIES
|
84
106
|
bundler (~> 2.0)
|
85
|
-
byebug (~> 11.0
|
107
|
+
byebug (~> 11.0)
|
86
108
|
fawry!
|
87
|
-
rake (~>
|
109
|
+
rake (~> 13.0)
|
88
110
|
rspec (~> 3.0)
|
89
|
-
|
111
|
+
rspec_junit_formatter
|
112
|
+
rubocop (~> 1.11)
|
113
|
+
webmock (~> 3.12)
|
90
114
|
|
91
115
|
BUNDLED WITH
|
92
|
-
2.
|
116
|
+
2.2.3
|
data/README-ar.md
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/fawry-api/fawry.svg?style=svg)](https://circleci.com/gh/fawry-api/fawry)
|
2
|
+
|
3
|
+
# Fawry
|
4
|
+
|
5
|
+
**تنويه:** نحن لسنا تابعين رسميًا لشركة فوري.
|
6
|
+
|
7
|
+
مكتبة لتسهيل التعامل مع خدمات الدفع الخاصة بشبكة الدفع الإلكتروني فوري:
|
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
|
+
_المكتبة تدعم النظام التجريبي لفوري ايضا_
|
19
|
+
|
20
|
+
## لإضافة وتشغيل المكتبة
|
21
|
+
|
22
|
+
أضف هذا السطر إلى ملف Gemfile الخاص بتطبيقك:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'fawry'
|
26
|
+
```
|
27
|
+
|
28
|
+
ثم نفذ:
|
29
|
+
|
30
|
+
$ bundle
|
31
|
+
|
32
|
+
أو قم بتثبيته بنفسك على النحو التالي:
|
33
|
+
|
34
|
+
$ gem install fawry
|
35
|
+
|
36
|
+
## طريقة الإستعمال
|
37
|
+
|
38
|
+
### لإجراء عملية دفع
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
params = { "merchant_code": 'merchant_code',
|
42
|
+
"merchant_ref_num": 'io5jxf3jp27kfh8m719arcqgw7izo7db',
|
43
|
+
"customer_profile_id": 'ocvsydvbu2gcp528wvl64i9z5srdalg5',
|
44
|
+
"customer_mobile": '012345678901',
|
45
|
+
"payment_method": 'PAYATFAWRY',
|
46
|
+
"currency_code": 'EGP',
|
47
|
+
"amount": 20,
|
48
|
+
"fawry_secure_key": 'fawry_secure_key',
|
49
|
+
"description": 'the charge request description',
|
50
|
+
"charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
|
51
|
+
"description": 'desc', "price": 20, "quantity": 1 }] }
|
52
|
+
|
53
|
+
# استخدم خيار النظام التجريبي للاتصال بالنظام التجريبي الخاص بفوري
|
54
|
+
# sandbox: true
|
55
|
+
res = Fawry.charge(params, sandbox: true)
|
56
|
+
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
|
57
|
+
# @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
|
58
|
+
# @expiration_time=1573153206979, @status_code=200,
|
59
|
+
# @status_description="Operation done successfully">
|
60
|
+
|
61
|
+
res.success? # => true
|
62
|
+
res.reference_number # => 931600239
|
63
|
+
```
|
64
|
+
|
65
|
+
### لإجراء عملية استرداد
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
params = { "merchant_code": 'merchant_code',
|
69
|
+
"reference_number": '931337410',
|
70
|
+
"refund_amount": 20,
|
71
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
72
|
+
|
73
|
+
res = Fawry.refund(params, sandbox: true)
|
74
|
+
# => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
|
75
|
+
# @status_description="Operation done successfully">
|
76
|
+
|
77
|
+
res.success? # => true
|
78
|
+
```
|
79
|
+
|
80
|
+
### حالة الدفع
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
params = { "merchant_code": 'merchant_code',
|
84
|
+
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
85
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
86
|
+
|
87
|
+
res = Fawry.payment_status(params, sandbox: true)
|
88
|
+
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
89
|
+
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
90
|
+
# @expiration_time=1573297736167, @status_code=200,
|
91
|
+
# @status_description="Operation done successfully", @payment_amount=20,
|
92
|
+
# @payment_method="PAYATFAWRY", @payment_status="UNPAID">
|
93
|
+
|
94
|
+
res.success? # => true
|
95
|
+
res.payment_status # => UNPAID
|
96
|
+
```
|
97
|
+
|
98
|
+
### عرض رموز الكروت
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
params = { "merchant_code": 'merchant_code',
|
102
|
+
"customer_profile_id": 'customer_profile_id',
|
103
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
104
|
+
|
105
|
+
res = Fawry.list_tokens(params, sandbox: true)
|
106
|
+
|
107
|
+
#<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
|
+
|
109
|
+
res.success? # => true
|
110
|
+
res.cards # => cards
|
111
|
+
```
|
112
|
+
|
113
|
+
### إضافة رمز كارت
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
params = { "merchant_code" : "merchant_code",
|
117
|
+
"customer_profile_id" : "customer_profile_id",
|
118
|
+
"customer_mobile" : "customer_mobile",
|
119
|
+
"customer_email" : "customer_email",
|
120
|
+
"card_number" : "card_number",
|
121
|
+
"expiry_year" : "expiry_year",
|
122
|
+
"expiry_month" : "expiry_month",
|
123
|
+
"cvv" : "cvv" }
|
124
|
+
res = Fawry.create_card_token(params, sandbox: true)
|
125
|
+
#<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
|
+
|
127
|
+
res.success?
|
128
|
+
res.card
|
129
|
+
```
|
130
|
+
|
131
|
+
### حذف رمز كارت
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
params = { "merchant_code": 'merchant_code',
|
135
|
+
"customer_profile_id": 'customer_profile_id',
|
136
|
+
"card_token": 'card_token' }
|
137
|
+
|
138
|
+
res = Fawry.delete_token(params, sandbox: true)
|
139
|
+
#<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
|
+
res.success?
|
141
|
+
|
142
|
+
```
|
143
|
+
|
144
|
+
### رد اتصال خدمة تحليل فوري v2
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
# تم إرسال المعلمات من خادم فوري
|
148
|
+
callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNumber": '970177',
|
149
|
+
"merchantRefNumber": '9708f1cea8b5426cb57922df51b7f790',
|
150
|
+
"customerMobile": '01004545545', "customerMail": 'fawry@fawry.com',
|
151
|
+
"paymentAmount": 152.00, "orderAmount": 150.00, "fawryFees": 2.00,
|
152
|
+
"shippingFees": '', "orderStatus": 'NEW', "paymentMethod": 'PAYATFAWRY',
|
153
|
+
"messageSignature": 'b0175565323e464b01dc9407160368af5568196997fb6e379374a4f4fbbcf587',
|
154
|
+
"orderExpiryDate": 1_533_554_719_314,
|
155
|
+
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
156
|
+
|
157
|
+
# FAWRY_SECURE_KEY يجب تعيين متغير البيئة
|
158
|
+
fawry_callback = Fawry.parse_callback(callback_params, {})
|
159
|
+
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
160
|
+
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
161
|
+
# @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
|
162
|
+
|
163
|
+
fawry_callback.fawry_ref_number # => 970177
|
164
|
+
fawry_callback.order_status # => NEW
|
165
|
+
```
|
166
|
+
|
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
|
+
## الخطوات القادمة المطلوب تنفيذها:
|
174
|
+
|
175
|
+
- إضافة خيار لرفع الاستثناء عند فشل الطلب
|
176
|
+
|
177
|
+
## تطوير المكتبة
|
178
|
+
|
179
|
+
بعد التحقق من الريبو ، قم بتشغيل `bin/setup` لتثبيت التبعيات.
|
180
|
+
ثم نفذ الأمر `rake spec` لإجراء الاختبارات. يمكنك أيضا الجري `bin/console` للمطالبة التفاعلية التي تسمح لك بالتجربة.
|
181
|
+
|
182
|
+
لتثبيت هذه المكتبة على جهازك ، قم بتشغيل `bundle exec rake install`. لإصدار إصدار جديد ، قم بتحديث رقم الإصدار بتنسيق `version.rb`, ثم نفذ الأمر `bundle exec rake release`, الذي سينشئ علامة git للإصدار ، ويدفع التزامات git والعلامات ، ويدفع ملف `.gem` يا صديق [rubygems.org](https://rubygems.org).
|
183
|
+
|
184
|
+
## المساهمة
|
185
|
+
|
186
|
+
يتم الترحيب بتقارير الأخطاء وطلبات السحب على GitHub في https://github.com/amrrbakry/fawry. يهدف هذا المشروع إلى أن يكون مساحة آمنة ومرحبة للتعاون ، ومن المتوقع أن يلتزم المساهمون بـ [Contributor Covenant](http://contributor-covenant.org) القواعد السلوكية.
|
data/README.md
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/fawry-api/fawry.svg?style=svg)](https://circleci.com/gh/fawry-api/fawry)
|
2
|
+
|
1
3
|
# Fawry
|
4
|
+
|
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.
|
8
|
+
|
2
9
|
A plug-and-play library that makes interfacing with Fawry's payment gateway API a breeze:
|
3
|
-
|
4
|
-
- [
|
5
|
-
-
|
6
|
-
-
|
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)
|
7
19
|
|
8
20
|
_Fawry's production and sandbox environments are supported._
|
9
21
|
|
@@ -24,7 +36,9 @@ Or install it yourself as:
|
|
24
36
|
$ gem install fawry
|
25
37
|
|
26
38
|
## Usage
|
39
|
+
|
27
40
|
### Charge customers
|
41
|
+
|
28
42
|
```ruby
|
29
43
|
params = { "merchant_code": 'merchant_code',
|
30
44
|
"merchant_ref_num": 'io5jxf3jp27kfh8m719arcqgw7izo7db',
|
@@ -48,7 +62,9 @@ res = Fawry.charge(params, sandbox: true)
|
|
48
62
|
res.success? # => true
|
49
63
|
res.reference_number # => 931600239
|
50
64
|
```
|
51
|
-
|
65
|
+
|
66
|
+
### Refund Customers
|
67
|
+
|
52
68
|
```ruby
|
53
69
|
params = { "merchant_code": 'merchant_code',
|
54
70
|
"reference_number": '931337410',
|
@@ -61,6 +77,106 @@ res = Fawry.refund(params, sandbox: true)
|
|
61
77
|
|
62
78
|
res.success? # => true
|
63
79
|
```
|
80
|
+
|
81
|
+
### Get Payment Status
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
params = { "merchant_code": 'merchant_code',
|
85
|
+
"merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
|
86
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
87
|
+
|
88
|
+
res = Fawry.payment_status(params, sandbox: true)
|
89
|
+
# => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
|
90
|
+
# @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
|
91
|
+
# @expiration_time=1573297736167, @status_code=200,
|
92
|
+
# @status_description="Operation done successfully", @payment_amount=20,
|
93
|
+
# @payment_method="PAYATFAWRY", @payment_status="UNPAID">
|
94
|
+
|
95
|
+
res.success? # => true
|
96
|
+
res.payment_status # => UNPAID
|
97
|
+
```
|
98
|
+
|
99
|
+
### List Card Tokens
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
params = { "merchant_code": 'merchant_code',
|
103
|
+
"customer_profile_id": 'customer_profile_id',
|
104
|
+
"fawry_secure_key": 'fawry_secure_key' }
|
105
|
+
|
106
|
+
res = Fawry.list_tokens(params, sandbox: true)
|
107
|
+
#<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
|
+
|
109
|
+
res.success? # => true
|
110
|
+
res.cards # => cards
|
111
|
+
```
|
112
|
+
|
113
|
+
### Create Card Token
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
params = { "merchant_code" : "merchant_code",
|
117
|
+
"customer_profile_id" : "customer_profile_id",
|
118
|
+
"customer_mobile" : "customer_mobile",
|
119
|
+
"customer_email" : "customer_email",
|
120
|
+
"card_number" : "card_number",
|
121
|
+
"expiry_year" : "expiry_year",
|
122
|
+
"expiry_month" : "expiry_month",
|
123
|
+
"cvv" : "cvv" }
|
124
|
+
res = Fawry.create_card_token(params, sandbox: true)
|
125
|
+
#<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
|
+
|
127
|
+
res.success?
|
128
|
+
res.card
|
129
|
+
```
|
130
|
+
|
131
|
+
### Delete Card Token
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
params = { "merchant_code": "merchant_code",
|
135
|
+
"customer_profile_id": "customer_profile_id",
|
136
|
+
"card_token": "card_token",
|
137
|
+
"fawry_secure_key": "fawry_secure_key" }
|
138
|
+
|
139
|
+
res = Fawry.delete_token(params, sandbox: true)
|
140
|
+
#<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
|
+
|
142
|
+
res.success?
|
143
|
+
|
144
|
+
```
|
145
|
+
|
146
|
+
### Parse Fawry service callback v2
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
# params sent from fawry server
|
150
|
+
callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNumber": '970177',
|
151
|
+
"merchantRefNumber": '9708f1cea8b5426cb57922df51b7f790',
|
152
|
+
"customerMobile": '01004545545', "customerMail": 'fawry@fawry.com',
|
153
|
+
"paymentAmount": 152.00, "orderAmount": 150.00, "fawryFees": 2.00,
|
154
|
+
"shippingFees": '', "orderStatus": 'NEW', "paymentMethod": 'PAYATFAWRY',
|
155
|
+
"messageSignature": 'b0175565323e464b01dc9407160368af5568196997fb6e379374a4f4fbbcf587',
|
156
|
+
"orderExpiryDate": 1_533_554_719_314,
|
157
|
+
"orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
|
158
|
+
|
159
|
+
# FAWRY_SECURE_KEY env var must be set
|
160
|
+
fawry_callback = Fawry.parse_callback(callback_params)
|
161
|
+
# <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
|
162
|
+
# @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
|
163
|
+
# @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
|
164
|
+
|
165
|
+
fawry_callback.fawry_ref_number # => 970177
|
166
|
+
fawry_callback.order_status # => NEW
|
167
|
+
```
|
168
|
+
|
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
|
+
## TODO:
|
176
|
+
|
177
|
+
- Add public API documentation to README
|
178
|
+
- Add option to raise exception on request failure
|
179
|
+
|
64
180
|
## Development
|
65
181
|
|
66
182
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -70,11 +186,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
70
186
|
## Contributing
|
71
187
|
|
72
188
|
Bug reports and pull requests are welcome on GitHub at https://github.com/amrrbakry/fawry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
73
|
-
|
74
|
-
## License
|
75
|
-
|
76
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
77
|
-
|
78
|
-
## Code of Conduct
|
79
|
-
|
80
|
-
Everyone interacting in the Fawry project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/amrrbakry/fawry/blob/master/CODE_OF_CONDUCT.md).
|