fawry 1.0.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbda1f1ab11ae04767a26c8989237f7ce246a3de49aaa4032ec43504b8e5779c
4
- data.tar.gz: cf4891b451a00c47d74254c1e065512572f4e5f19c94db7956b2e94dc210d538
3
+ metadata.gz: 67bf2df195ce85382e7bd0d9f6d6b2111e5204d59fbc4091a5d9b31b7dde9a5f
4
+ data.tar.gz: 8a1ebb82a2b6a4937358193ae8c843f7dfcab971ed82c757171a1387c711d9d8
5
5
  SHA512:
6
- metadata.gz: 2f0571abf34444cb9343f603e0b195ccb6ce683f2d5d4d5e82515a8058e361095aa4af21df17cd15db1ed0fe16195b354d1d708a9855e9c11d9e8eea151cfaca
7
- data.tar.gz: 3414b7912f9eab50220ae66ac0d5010b2ecb9b6d359d25929ed7effe671128030d19928a7d1c57107f6ed467dfc315b95b79ad0199ac8f033f4a3e817538e83c
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
- Metrics/LineLength:
4
+ Layout/LineLength:
4
5
  Max: 120
5
6
  Metrics/BlockLength:
6
- ExcludedMethods: ['describe', 'context']
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.0.0)
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.7.0)
11
+ addressable (2.8.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.0)
14
- byebug (11.0.1)
15
- concurrent-ruby (1.1.5)
16
- crack (0.4.3)
17
- safe_yaml (~> 1.0.0)
18
- diff-lcs (1.3)
19
- dry-configurable (0.9.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.4, >= 0.4.7)
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.4.9)
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.2)
30
- dry-logic (1.0.5)
29
+ dry-initializer (3.0.4)
30
+ dry-logic (1.2.0)
31
31
  concurrent-ruby (~> 1.0)
32
- dry-core (~> 0.2)
33
- dry-equalizer (~> 0.2)
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.4)
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.2)
42
- dry-types (1.2.2)
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.4, >= 0.4.4)
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.4.0)
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.0, >= 1.3.1)
56
- faraday (0.17.1)
52
+ dry-schema (~> 1.5, >= 1.5.2)
53
+ faraday (0.17.4)
57
54
  multipart-post (>= 1.2, < 3)
58
- hashdiff (1.0.0)
59
- jaro_winkler (1.5.4)
55
+ hashdiff (1.0.1)
60
56
  multipart-post (2.1.1)
61
- parallel (1.18.0)
62
- parser (2.6.5.0)
63
- ast (~> 2.4.0)
64
- public_suffix (4.0.1)
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 (10.5.0)
67
- rspec (3.9.0)
68
- rspec-core (~> 3.9.0)
69
- rspec-expectations (~> 3.9.0)
70
- rspec-mocks (~> 3.9.0)
71
- rspec-core (3.9.0)
72
- rspec-support (~> 3.9.0)
73
- rspec-expectations (3.9.0)
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.9.0)
76
- rspec-mocks (3.9.0)
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.9.0)
79
- rspec-support (3.9.0)
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 (0.76.0)
83
- jaro_winkler (~> 1.5.1)
80
+ rubocop (1.13.0)
84
81
  parallel (~> 1.10)
85
- parser (>= 2.6)
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, < 1.7)
89
- ruby-progressbar (1.10.1)
90
- safe_yaml (1.0.5)
91
- unicode-display_width (1.6.0)
92
- webmock (3.7.6)
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, >= 11.0.1)
103
+ byebug (~> 11.0)
103
104
  fawry!
104
- rake (~> 10.0)
105
+ rake (~> 13.0)
105
106
  rspec (~> 3.0)
106
107
  rspec_junit_formatter
107
- rubocop (~> 0.76.0)
108
- webmock (~> 3.7, >= 3.7.6)
108
+ rubocop (~> 1.11)
109
+ webmock (~> 3.12)
109
110
 
110
111
  BUNDLED WITH
111
- 2.0.2
112
+ 2.2.3
data/README-ar.md ADDED
@@ -0,0 +1,184 @@
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
+ _المكتبة تدعم النظام التجريبي لفوري ايضا_
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
- A plug-and-play library that makes interfacing with Fawry's payment gateway API a breeze:
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
- - [Charge customers](https://github.com/fawry-api/fawry#charge-customers)
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
- # use sandbox option to call Fawry's sandbox env
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
- ### Refund Customers
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, sandbox: true)
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
- ### Get Payment Status
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, sandbox: true)
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
- ### Parse Fawry service callback v2
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
- # FAWRY_SECURE_KEY env var must be set
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