fawry 1.2.1 → 1.3.0

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: de7321464f0d145904cb1b356fc8b0659f7258e5693c4c3a32e6ae3276198a5e
4
- data.tar.gz: c7bc36bbe23c12fbe7b7ea0b5397cfbf9a5bf696440806a1a7200e61fd10e4c1
3
+ metadata.gz: 5015952a24c3ab03377aae7d4d17abccbb7800c00c5ed6a02b4becabe5aa42a6
4
+ data.tar.gz: 337289fe3666ac8fd7f7ff9886d5a6d5e33ebc542000c624771f338278160634
5
5
  SHA512:
6
- metadata.gz: 9ff0c0665c07f5b0abd0b68ece79e6ab934c8c91e2387571986ad652af08e31cae9e8e0a3674aa180b9badbbb7833df24a6e64c8da5f9383ab97299454de4090
7
- data.tar.gz: c1a8cdeef0c8fe57010ef68491e95ba88d99c5f990a123829afe03e78c7704a4184c101cd72ed145747d71972e085cf1ace26617feff0b42d781eb4af56d3ff6
6
+ metadata.gz: 53a9057c10dda83db87042cce4dae0d7d76155c3bcffaeb5369403517d33613b10fb3d7a057db7cd39f368a2f4b3988ca06277db9de1e6ac9ab5c7d636ae026c
7
+ data.tar.gz: 8fb2747e2050270ea3514b6c7967e60d41268f2469bf6060188c532d4a2688387edcbaea741d567321b107ebb876adac7f7c79ec3375eeca91c9c007e6c6127a
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
  TargetRubyVersion: 2.6
4
- Metrics/LineLength:
4
+ Layout/LineLength:
5
5
  Max: 120
6
6
  Metrics/BlockLength:
7
7
  IgnoredMethods: ['describe', 'context']
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Fawry Changelog
2
+
3
+ ## [v1.2.1](https://github.com/fawry-api/fawry/releases/tag/v1.2.1) (14.03.2021)
4
+ - Update gem and dependencies to support Ruby 3.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fawry (1.2.1)
4
+ fawry (1.3.0)
5
5
  dry-validation (~> 1.3, >= 1.3.1)
6
6
  faraday (~> 0.17.0)
7
7
 
@@ -11,43 +11,39 @@ GEM
11
11
  addressable (2.7.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
13
  ast (2.4.2)
14
- byebug (11.0.1)
15
- concurrent-ruby (1.1.7)
14
+ byebug (11.1.3)
15
+ concurrent-ruby (1.1.8)
16
16
  crack (0.4.5)
17
17
  rexml
18
- diff-lcs (1.3)
19
- dry-configurable (0.11.6)
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)
22
- dry-equalizer (~> 0.2)
21
+ dry-core (~> 0.5, >= 0.5.0)
23
22
  dry-container (0.7.2)
24
23
  concurrent-ruby (~> 1.0)
25
24
  dry-configurable (~> 0.1, >= 0.1.3)
26
- dry-core (0.4.9)
25
+ dry-core (0.5.0)
27
26
  concurrent-ruby (~> 1.0)
28
27
  dry-equalizer (0.3.0)
29
28
  dry-inflector (0.2.0)
30
29
  dry-initializer (3.0.4)
31
- dry-logic (1.0.8)
30
+ dry-logic (1.2.0)
32
31
  concurrent-ruby (~> 1.0)
33
- dry-core (~> 0.2)
34
- dry-equalizer (~> 0.2)
35
- dry-schema (1.5.5)
32
+ dry-core (~> 0.5, >= 0.5)
33
+ dry-schema (1.6.2)
36
34
  concurrent-ruby (~> 1.0)
37
35
  dry-configurable (~> 0.8, >= 0.8.3)
38
- dry-core (~> 0.4)
39
- dry-equalizer (~> 0.2)
36
+ dry-core (~> 0.5, >= 0.5)
40
37
  dry-initializer (~> 3.0)
41
38
  dry-logic (~> 1.0)
42
- dry-types (~> 1.4)
43
- dry-types (1.4.0)
39
+ dry-types (~> 1.5)
40
+ dry-types (1.5.1)
44
41
  concurrent-ruby (~> 1.0)
45
42
  dry-container (~> 0.3)
46
- dry-core (~> 0.4, >= 0.4.4)
47
- dry-equalizer (~> 0.3)
43
+ dry-core (~> 0.5, >= 0.5)
48
44
  dry-inflector (~> 0.1, >= 0.1.2)
49
45
  dry-logic (~> 1.0, >= 1.0.2)
50
- dry-validation (1.5.6)
46
+ dry-validation (1.6.0)
51
47
  concurrent-ruby (~> 1.0)
52
48
  dry-container (~> 0.7, >= 0.7.1)
53
49
  dry-core (~> 0.4)
@@ -59,29 +55,29 @@ GEM
59
55
  hashdiff (1.0.1)
60
56
  multipart-post (2.1.1)
61
57
  parallel (1.20.1)
62
- parser (3.0.0.0)
58
+ parser (3.0.1.1)
63
59
  ast (~> 2.4.1)
64
60
  public_suffix (4.0.6)
65
61
  rainbow (3.0.0)
66
- rake (13.0.1)
62
+ rake (13.0.3)
67
63
  regexp_parser (2.1.1)
68
- rexml (3.2.4)
69
- rspec (3.9.0)
70
- rspec-core (~> 3.9.0)
71
- rspec-expectations (~> 3.9.0)
72
- rspec-mocks (~> 3.9.0)
73
- rspec-core (3.9.0)
74
- rspec-support (~> 3.9.0)
75
- rspec-expectations (3.9.0)
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)
76
72
  diff-lcs (>= 1.2.0, < 2.0)
77
- rspec-support (~> 3.9.0)
78
- rspec-mocks (3.9.0)
73
+ rspec-support (~> 3.10.0)
74
+ rspec-mocks (3.10.2)
79
75
  diff-lcs (>= 1.2.0, < 2.0)
80
- rspec-support (~> 3.9.0)
81
- rspec-support (3.9.0)
76
+ rspec-support (~> 3.10.0)
77
+ rspec-support (3.10.2)
82
78
  rspec_junit_formatter (0.4.1)
83
79
  rspec-core (>= 2, < 4, != 2.12.0)
84
- rubocop (1.11.0)
80
+ rubocop (1.13.0)
85
81
  parallel (~> 1.10)
86
82
  parser (>= 3.0.0.0)
87
83
  rainbow (>= 2.2.2, < 4.0)
@@ -90,11 +86,11 @@ GEM
90
86
  rubocop-ast (>= 1.2.0, < 2.0)
91
87
  ruby-progressbar (~> 1.7)
92
88
  unicode-display_width (>= 1.4.0, < 3.0)
93
- rubocop-ast (1.4.1)
94
- parser (>= 2.7.1.5)
89
+ rubocop-ast (1.5.0)
90
+ parser (>= 3.0.1.1)
95
91
  ruby-progressbar (1.11.0)
96
92
  unicode-display_width (2.0.0)
97
- webmock (3.12.1)
93
+ webmock (3.12.2)
98
94
  addressable (>= 2.3.6)
99
95
  crack (>= 0.3.2)
100
96
  hashdiff (>= 0.4.0, < 2.0.0)
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,18 @@ gem 'fawry'
33
24
 
34
25
  $ gem install fawry
35
26
 
27
+ ## تهيئة فوري للاستخدام
28
+
29
+ لبرنامجك لتهيئة المكتبة `fawry.rb` أضف مهيئ
30
+ ```ruby
31
+ Fawry.configure do |config|
32
+ config.sandbox = Rails.env.staging? ? true : false
33
+ config.fawry_secure_key = 'fawry_secure_key'
34
+ config.fawry_merchant_code = 'fawry_merchant_code'
35
+ end
36
+ ```
37
+ `FAWRY_SANDBOX`, `FAWRY_SECURE_KEY`, `FAWRY_MERCHANT_CODE` _(environment variables)_ او يمكنك بدلا من ذلك، استخدام المتغيرات البيئية
38
+
36
39
  ## طريقة الإستعمال
37
40
 
38
41
  ### لإجراء عملية دفع
@@ -50,9 +53,7 @@ params = { "merchant_code": 'merchant_code',
50
53
  "charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
51
54
  "description": 'desc', "price": 20, "quantity": 1 }] }
52
55
 
53
- # استخدم خيار النظام التجريبي للاتصال بالنظام التجريبي الخاص بفوري
54
- # sandbox: true
55
- res = Fawry.charge(params, sandbox: true)
56
+ res = Fawry.charge(params)
56
57
  # => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
57
58
  # @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
58
59
  # @expiration_time=1573153206979, @status_code=200,
@@ -70,7 +71,7 @@ params = { "merchant_code": 'merchant_code',
70
71
  "refund_amount": 20,
71
72
  "fawry_secure_key": 'fawry_secure_key' }
72
73
 
73
- res = Fawry.refund(params, sandbox: true)
74
+ res = Fawry.refund(params)
74
75
  # => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
75
76
  # @status_description="Operation done successfully">
76
77
 
@@ -84,7 +85,7 @@ params = { "merchant_code": 'merchant_code',
84
85
  "merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
85
86
  "fawry_secure_key": 'fawry_secure_key' }
86
87
 
87
- res = Fawry.payment_status(params, sandbox: true)
88
+ res = Fawry.payment_status(params)
88
89
  # => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
89
90
  # @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
90
91
  # @expiration_time=1573297736167, @status_code=200,
@@ -102,7 +103,7 @@ params = { "merchant_code": 'merchant_code',
102
103
  "customer_profile_id": 'customer_profile_id',
103
104
  "fawry_secure_key": 'fawry_secure_key' }
104
105
 
105
- res = Fawry.list_tokens(params, sandbox: true)
106
+ res = Fawry.list_tokens(params)
106
107
 
107
108
  #<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
 
@@ -121,7 +122,8 @@ params = { "merchant_code" : "merchant_code",
121
122
  "expiry_year" : "expiry_year",
122
123
  "expiry_month" : "expiry_month",
123
124
  "cvv" : "cvv" }
124
- res = Fawry.create_card_token(params, sandbox: true)
125
+
126
+ res = Fawry.create_card_token(params)
125
127
  #<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
128
 
127
129
  res.success?
@@ -135,7 +137,7 @@ params = { "merchant_code": 'merchant_code',
135
137
  "customer_profile_id": 'customer_profile_id',
136
138
  "card_token": 'card_token' }
137
139
 
138
- res = Fawry.delete_token(params, sandbox: true)
140
+ res = Fawry.delete_token(params)
139
141
  #<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
142
  res.success?
141
143
 
@@ -154,8 +156,7 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
154
156
  "orderExpiryDate": 1_533_554_719_314,
155
157
  "orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
156
158
 
157
- # FAWRY_SECURE_KEY يجب تعيين متغير البيئة
158
- fawry_callback = Fawry.parse_callback(callback_params, {})
159
+ fawry_callback = Fawry.parse_callback(callback_params)
159
160
  # <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
160
161
  # @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
161
162
  # @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
@@ -164,12 +165,6 @@ fawry_callback.fawry_ref_number # => 970177
164
165
  fawry_callback.order_status # => NEW
165
166
  ```
166
167
 
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
168
  ## الخطوات القادمة المطلوب تنفيذها:
174
169
 
175
170
  - إضافة خيار لرفع الاستثناء عند فشل الطلب
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:
@@ -34,6 +27,18 @@ And then execute:
34
27
  Or install it yourself as:
35
28
 
36
29
  $ gem install fawry
30
+
31
+ ## Configuration
32
+
33
+ Add an initializer `fawry.rb` in your application to configure the library:
34
+ ```ruby
35
+ Fawry.configure do |config|
36
+ config.sandbox = Rails.env.staging? ? true : false
37
+ config.fawry_secure_key = 'fawry_secure_key'
38
+ config.fawry_merchant_code = 'fawry_merchant_code'
39
+ end
40
+ ```
41
+ Alternatively, you could use the environment variables: `FAWRY_SANDBOX`, `FAWRY_SECURE_KEY`, and `FAWRY_MERCHANT_CODE`.
37
42
 
38
43
  ## Usage
39
44
 
@@ -52,8 +57,7 @@ params = { "merchant_code": 'merchant_code',
52
57
  "charge_items": [{ "item_id": 'fk3fn9flk8et9a5t9w3c5h3oc684ivho',
53
58
  "description": 'desc', "price": 20, "quantity": 1 }] }
54
59
 
55
- # use sandbox option to call Fawry's sandbox env
56
- res = Fawry.charge(params, sandbox: true)
60
+ res = Fawry.charge(params)
57
61
  # => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ChargeResponse", @reference_number="931600239",
58
62
  # @merchant_ref_number="io5jxf3jp27kfh8m719arcqgw7izo7db",
59
63
  # @expiration_time=1573153206979, @status_code=200,
@@ -71,7 +75,7 @@ params = { "merchant_code": 'merchant_code',
71
75
  "refund_amount": 20,
72
76
  "fawry_secure_key": 'fawry_secure_key' }
73
77
 
74
- res = Fawry.refund(params, sandbox: true)
78
+ res = Fawry.refund(params)
75
79
  # => #<Fawry::FawryResponse:0x0000564257d0ea90 @type="ResponseDataModel", @status_code=200,
76
80
  # @status_description="Operation done successfully">
77
81
 
@@ -85,7 +89,7 @@ params = { "merchant_code": 'merchant_code',
85
89
  "merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
86
90
  "fawry_secure_key": 'fawry_secure_key' }
87
91
 
88
- res = Fawry.payment_status(params, sandbox: true)
92
+ res = Fawry.payment_status(params)
89
93
  # => #<Fawry::FawryResponse:0x0000559974056898 @type="PaymentStatusResponse", @reference_number="931922417",
90
94
  # @merchant_ref_number="ssshxb98phmyvm434es62kage3nsm2cj",
91
95
  # @expiration_time=1573297736167, @status_code=200,
@@ -103,7 +107,7 @@ params = { "merchant_code": 'merchant_code',
103
107
  "customer_profile_id": 'customer_profile_id',
104
108
  "fawry_secure_key": 'fawry_secure_key' }
105
109
 
106
- res = Fawry.list_tokens(params, sandbox: true)
110
+ res = Fawry.list_tokens(params)
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
 
109
113
  res.success? # => true
@@ -121,7 +125,7 @@ params = { "merchant_code" : "merchant_code",
121
125
  "expiry_year" : "expiry_year",
122
126
  "expiry_month" : "expiry_month",
123
127
  "cvv" : "cvv" }
124
- res = Fawry.create_card_token(params, sandbox: true)
128
+ res = Fawry.create_card_token(params)
125
129
  #<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
130
 
127
131
  res.success?
@@ -136,7 +140,7 @@ params = { "merchant_code": "merchant_code",
136
140
  "card_token": "card_token",
137
141
  "fawry_secure_key": "fawry_secure_key" }
138
142
 
139
- res = Fawry.delete_token(params, sandbox: true)
143
+ res = Fawry.delete_token(params)
140
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">
141
145
 
142
146
  res.success?
@@ -156,7 +160,6 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
156
160
  "orderExpiryDate": 1_533_554_719_314,
157
161
  "orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
158
162
 
159
- # FAWRY_SECURE_KEY env var must be set
160
163
  fawry_callback = Fawry.parse_callback(callback_params)
161
164
  # <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
162
165
  # @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
@@ -166,15 +169,8 @@ fawry_callback.fawry_ref_number # => 970177
166
169
  fawry_callback.order_status # => NEW
167
170
  ```
168
171
 
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
172
  ## TODO:
176
173
 
177
- - Add public API documentation to README
178
174
  - Add option to raise exception on request failure
179
175
 
180
176
  ## Development
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
@@ -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
@@ -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
- conn = options[:sandbox] ? sandbox_connection : connection
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
- conn = options[:sandbox] ? sandbox_connection : connection
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
- conn = options[:sandbox] ? sandbox_connection : connection
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
@@ -39,14 +39,16 @@ module Fawry
39
39
  end
40
40
 
41
41
  rule(:fawry_secure_key) do
42
- if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
43
- key(:fawry_secure_key).failure('fawry secure key is required as a param or an env var')
42
+ if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
43
+ key(:fawry_secure_key).failure('fawry secure key is required in either Fawry.configuration or'\
44
+ 'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
44
45
  end
45
46
  end
46
47
 
47
48
  rule(:merchant_code) do
48
- if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
49
- key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
49
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
50
+ key(:merchant_code).failure('fawry merchant code is required in either Fawry.configuration or'\
51
+ 'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
50
52
  end
51
53
  end
52
54
  end
@@ -23,8 +23,9 @@ 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).failure('fawry merchant code is required as a param or an env var')
26
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
27
+ key(:merchant_code).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')
28
29
  end
29
30
  end
30
31
  end
@@ -13,14 +13,16 @@ 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).failure('fawry secure key is required as a param or an env var')
16
+ if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
17
+ key(:fawry_secure_key).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')
18
19
  end
19
20
  end
20
21
 
21
22
  rule(:merchant_code) do
22
- if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
23
- key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
23
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
24
+ key(:merchant_code).failure('fawry merchant code is required in either Fawry.configuration or'\
25
+ 'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
24
26
  end
25
27
  end
26
28
  end
@@ -12,14 +12,16 @@ 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).failure('fawry secure key is required as a param or an env var')
15
+ if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
16
+ key(:fawry_secure_key).failure('fawry secure key is required in either Fawry.configuration or'\
17
+ 'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
17
18
  end
18
19
  end
19
20
 
20
21
  rule(:merchant_code) do
21
- if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
22
- key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
22
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
23
+ key(:merchant_code).failure('fawry merchant code is required in either Fawry.configuration or'\
24
+ 'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
23
25
  end
24
26
  end
25
27
  end
@@ -12,14 +12,16 @@ 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).failure('fawry secure key is required as a param or an env var')
15
+ if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
16
+ key(:fawry_secure_key).failure('fawry secure key is required in either Fawry.configuration or'\
17
+ 'as an environment variable (FAWRY_SECURE_KEY), or as an argument to this method')
17
18
  end
18
19
  end
19
20
 
20
21
  rule(:merchant_code) do
21
- if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
22
- key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
22
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
23
+ key(:merchant_code).failure('fawry merchant code is required in either Fawry.configuration or'\
24
+ 'as an environment variable (FAWRY_MERCHANT_CODE), or as an argument to this method')
23
25
  end
24
26
  end
25
27
  end
@@ -14,14 +14,16 @@ 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).failure('fawry secure key is required as a param or an env var')
17
+ if Fawry.configuration.fawry_secure_key.nil? && ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
18
+ key(:fawry_secure_key).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')
19
20
  end
20
21
  end
21
22
 
22
23
  rule(:merchant_code) do
23
- if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
24
- key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
24
+ if Fawry.configuration.fawry_merchant_code.nil? && ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
25
+ key(:merchant_code).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')
25
27
  end
26
28
  end
27
29
  end
@@ -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
 
@@ -52,11 +52,11 @@ module Fawry
52
52
  # rubocop:enable Metrics/AbcSize
53
53
 
54
54
  def fawry_merchant_code
55
- ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
55
+ Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
56
56
  end
57
57
 
58
58
  def fawry_secure_key
59
- ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
59
+ Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
60
60
  end
61
61
 
62
62
  def validate_charge_params!
@@ -41,11 +41,11 @@ module Fawry
41
41
  end
42
42
 
43
43
  def fawry_merchant_code
44
- ENV.fetch('FAWRY_MERCHANT_CODE') { create_card_token_request[:merchant_code] }
44
+ Fawry.configuration.fawry_merchant_code || ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
45
45
  end
46
46
 
47
47
  def fawry_secure_key
48
- ENV.fetch('FAWRY_SECURE_KEY') { create_card_token_request[:fawry_secure_key] }
48
+ Fawry.configuration.fawry_secure_key || ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
49
49
  end
50
50
 
51
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
data/lib/fawry/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fawry
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
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.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amr El Bakry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-13 00:00:00.000000000 Z
11
+ date: 2021-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation
@@ -154,6 +154,7 @@ files:
154
154
  - ".gitignore"
155
155
  - ".rspec"
156
156
  - ".rubocop.yml"
157
+ - CHANGELOG.md
157
158
  - CODE_OF_CONDUCT.md
158
159
  - Gemfile
159
160
  - Gemfile.lock
@@ -165,6 +166,7 @@ files:
165
166
  - bin/setup
166
167
  - fawry.gemspec
167
168
  - lib/fawry.rb
169
+ - lib/fawry/config.rb
168
170
  - lib/fawry/connection.rb
169
171
  - lib/fawry/contracts/charge_request_contract.rb
170
172
  - lib/fawry/contracts/create_card_token_request_contract.rb
@@ -205,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
207
  - !ruby/object:Gem::Version
206
208
  version: '0'
207
209
  requirements: []
208
- rubygems_version: 3.0.9
210
+ rubygems_version: 3.1.4
209
211
  signing_key:
210
212
  specification_version: 4
211
213
  summary: A library to interface with Fawry's payment gateway API (charge, refund,