fawry 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b36b534916d6923f8bc715652eac726e83e4d5bac78dc5ae3aabb2af08a28d7
4
- data.tar.gz: 4cb3e3db3f83c80b130e2de91a43f85f4e489876b90a7f2dbedcf7417b53bbb2
3
+ metadata.gz: fbda1f1ab11ae04767a26c8989237f7ce246a3de49aaa4032ec43504b8e5779c
4
+ data.tar.gz: cf4891b451a00c47d74254c1e065512572f4e5f19c94db7956b2e94dc210d538
5
5
  SHA512:
6
- metadata.gz: e049a63ce51c39786f674160e66b044ff0d72dd1c3e52fe4f0abb7aa829c99b16238f329f9a83e2ae3840609799d80160227b74874b610dd27bba6d9eaad4c84
7
- data.tar.gz: 8dc4bd0949b640b3ab99a141938677351ec7c03ccf8c0b8b9297acfdb54b5ade84a97185accc39eb289667789df4fcbd4bcc04f3da34c01acc2466384292d84c
6
+ metadata.gz: 2f0571abf34444cb9343f603e0b195ccb6ce683f2d5d4d5e82515a8058e361095aa4af21df17cd15db1ed0fe16195b354d1d708a9855e9c11d9e8eea151cfaca
7
+ data.tar.gz: 3414b7912f9eab50220ae66ac0d5010b2ecb9b6d359d25929ed7effe671128030d19928a7d1c57107f6ed467dfc315b95b79ad0199ac8f033f4a3e817538e83c
@@ -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,13 @@
1
+ name: Greetings
2
+
3
+ on: [pull_request, issues]
4
+
5
+ jobs:
6
+ greeting:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/first-interaction@v1
10
+ with:
11
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
12
+ issue-message: "Hello, thanks for taking the time to open this issue. We'll get to it as soon as possible."
13
+ pr-message: "Hello, thanks for taking the time to open this PR. We'll get to it as soon as possible."
@@ -1,3 +1,5 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
1
3
  Metrics/LineLength:
2
4
  Max: 120
3
5
  Metrics/BlockLength:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fawry (0.3.0)
4
+ fawry (1.0.0)
5
5
  dry-validation (~> 1.3, >= 1.3.1)
6
6
  faraday (~> 0.17.0)
7
7
 
@@ -10,12 +10,13 @@ GEM
10
10
  specs:
11
11
  addressable (2.7.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.0)
13
14
  byebug (11.0.1)
14
15
  concurrent-ruby (1.1.5)
15
16
  crack (0.4.3)
16
17
  safe_yaml (~> 1.0.0)
17
18
  diff-lcs (1.3)
18
- dry-configurable (0.8.3)
19
+ dry-configurable (0.9.0)
19
20
  concurrent-ruby (~> 1.0)
20
21
  dry-core (~> 0.4, >= 0.4.7)
21
22
  dry-container (0.7.2)
@@ -23,14 +24,14 @@ GEM
23
24
  dry-configurable (~> 0.1, >= 0.1.3)
24
25
  dry-core (0.4.9)
25
26
  concurrent-ruby (~> 1.0)
26
- dry-equalizer (0.2.2)
27
+ dry-equalizer (0.3.0)
27
28
  dry-inflector (0.2.0)
28
- dry-initializer (3.0.1)
29
- dry-logic (1.0.3)
29
+ dry-initializer (3.0.2)
30
+ dry-logic (1.0.5)
30
31
  concurrent-ruby (~> 1.0)
31
32
  dry-core (~> 0.2)
32
33
  dry-equalizer (~> 0.2)
33
- dry-schema (1.4.1)
34
+ dry-schema (1.4.2)
34
35
  concurrent-ruby (~> 1.0)
35
36
  dry-configurable (~> 0.8, >= 0.8.3)
36
37
  dry-core (~> 0.4)
@@ -38,25 +39,30 @@ GEM
38
39
  dry-initializer (~> 3.0)
39
40
  dry-logic (~> 1.0)
40
41
  dry-types (~> 1.2)
41
- dry-types (1.2.0)
42
+ dry-types (1.2.2)
42
43
  concurrent-ruby (~> 1.0)
43
44
  dry-container (~> 0.3)
44
45
  dry-core (~> 0.4, >= 0.4.4)
45
- dry-equalizer (~> 0.2, >= 0.2.2)
46
+ dry-equalizer (~> 0.3)
46
47
  dry-inflector (~> 0.1, >= 0.1.2)
47
48
  dry-logic (~> 1.0, >= 1.0.2)
48
- dry-validation (1.3.1)
49
+ dry-validation (1.4.0)
49
50
  concurrent-ruby (~> 1.0)
50
51
  dry-container (~> 0.7, >= 0.7.1)
51
52
  dry-core (~> 0.4)
52
53
  dry-equalizer (~> 0.2)
53
54
  dry-initializer (~> 3.0)
54
55
  dry-schema (~> 1.0, >= 1.3.1)
55
- faraday (0.17.0)
56
+ faraday (0.17.1)
56
57
  multipart-post (>= 1.2, < 3)
57
58
  hashdiff (1.0.0)
59
+ jaro_winkler (1.5.4)
58
60
  multipart-post (2.1.1)
61
+ parallel (1.18.0)
62
+ parser (2.6.5.0)
63
+ ast (~> 2.4.0)
59
64
  public_suffix (4.0.1)
65
+ rainbow (3.0.0)
60
66
  rake (10.5.0)
61
67
  rspec (3.9.0)
62
68
  rspec-core (~> 3.9.0)
@@ -71,7 +77,18 @@ GEM
71
77
  diff-lcs (>= 1.2.0, < 2.0)
72
78
  rspec-support (~> 3.9.0)
73
79
  rspec-support (3.9.0)
80
+ rspec_junit_formatter (0.4.1)
81
+ rspec-core (>= 2, < 4, != 2.12.0)
82
+ rubocop (0.76.0)
83
+ jaro_winkler (~> 1.5.1)
84
+ parallel (~> 1.10)
85
+ parser (>= 2.6)
86
+ rainbow (>= 2.2.2, < 4.0)
87
+ ruby-progressbar (~> 1.7)
88
+ unicode-display_width (>= 1.4.0, < 1.7)
89
+ ruby-progressbar (1.10.1)
74
90
  safe_yaml (1.0.5)
91
+ unicode-display_width (1.6.0)
75
92
  webmock (3.7.6)
76
93
  addressable (>= 2.3.6)
77
94
  crack (>= 0.3.2)
@@ -86,6 +103,8 @@ DEPENDENCIES
86
103
  fawry!
87
104
  rake (~> 10.0)
88
105
  rspec (~> 3.0)
106
+ rspec_junit_formatter
107
+ rubocop (~> 0.76.0)
89
108
  webmock (~> 3.7, >= 3.7.6)
90
109
 
91
110
  BUNDLED WITH
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
+ [![CircleCI](https://circleci.com/gh/fawry-api/fawry.svg?style=svg)](https://circleci.com/gh/fawry-api/fawry)
2
+
1
3
  # Fawry
4
+
2
5
  A plug-and-play library that makes interfacing with Fawry's payment gateway API a breeze:
6
+
3
7
  - [Charge customers](https://github.com/fawry-api/fawry#charge-customers)
4
8
  - [Refund customers](https://github.com/fawry-api/fawry#refund-customers)
5
9
  - [Get payment status](https://github.com/fawry-api/fawry#get-payment-status)
6
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)
7
12
 
8
13
  _Fawry's production and sandbox environments are supported._
9
14
 
@@ -24,7 +29,9 @@ Or install it yourself as:
24
29
  $ gem install fawry
25
30
 
26
31
  ## Usage
32
+
27
33
  ### Charge customers
34
+
28
35
  ```ruby
29
36
  params = { "merchant_code": 'merchant_code',
30
37
  "merchant_ref_num": 'io5jxf3jp27kfh8m719arcqgw7izo7db',
@@ -48,7 +55,9 @@ res = Fawry.charge(params, sandbox: true)
48
55
  res.success? # => true
49
56
  res.reference_number # => 931600239
50
57
  ```
58
+
51
59
  ### Refund Customers
60
+
52
61
  ```ruby
53
62
  params = { "merchant_code": 'merchant_code',
54
63
  "reference_number": '931337410',
@@ -63,6 +72,7 @@ res.success? # => true
63
72
  ```
64
73
 
65
74
  ### Get Payment Status
75
+
66
76
  ```ruby
67
77
  params = { "merchant_code": 'merchant_code',
68
78
  "merchant_ref_number": 'ssshxb98phmyvm434es62kage3nsm2cj',
@@ -80,7 +90,9 @@ res.payment_status # => UNPAID
80
90
  ```
81
91
 
82
92
  ### Parse Fawry service callback v2
93
+
83
94
  ```ruby
95
+ # params sent from fawry server
84
96
  callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNumber": '970177',
85
97
  "merchantRefNumber": '9708f1cea8b5426cb57922df51b7f790',
86
98
  "customerMobile": '01004545545', "customerMail": 'fawry@fawry.com',
@@ -90,7 +102,8 @@ callback_params = { "requestId": 'c72827d084ea4b88949d91dd2db4996e', "fawryRefNu
90
102
  "orderExpiryDate": 1_533_554_719_314,
91
103
  "orderItems": [{ "itemCode": 'e6aacbd5a498487ab1a10ae71061535d', "price": 150.0, "quantity": 1 }] }
92
104
 
93
- fawry_callback = Fawry.parse_callback(callback_params, 'fawry_secure_key')
105
+ # FAWRY_SECURE_KEY env var must be set
106
+ fawry_callback = Fawry.parse_callback(callback_params, {})
94
107
  # <Fawry::FawryCallback:0x000056339ac43730 @request_id="c72827d084ea4b88949d91dd2db4996e", @fawry_ref_number="970177",
95
108
  # @merchant_ref_number="9708f1cea8b5426cb57922df51b7f790", @customer_mobile="01004545545",
96
109
  # @customer_mail="fawry@fawry.com", @order_status="NEW", @order_amount=150.0, @fawry_fees=2.0, ...>
@@ -98,6 +111,18 @@ fawry_callback = Fawry.parse_callback(callback_params, 'fawry_secure_key')
98
111
  fawry_callback.fawry_ref_number # => 970177
99
112
  fawry_callback.order_status # => NEW
100
113
  ```
114
+
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
+ ## TODO:
122
+
123
+ - Add public API documentation to README
124
+ - Add option to raise exception on request failure
125
+
101
126
  ## Development
102
127
 
103
128
  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.
@@ -107,11 +132,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
107
132
  ## Contributing
108
133
 
109
134
  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.
110
-
111
- ## License
112
-
113
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
114
-
115
- ## Code of Conduct
116
-
117
- 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).
data/Rakefile CHANGED
@@ -6,3 +6,13 @@ require 'rspec/core/rake_task'
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  task default: :spec
9
+
10
+ desc 'Start a console session with Fawry gem loaded'
11
+ task :console do
12
+ require 'irb'
13
+ require 'irb/completion'
14
+ require 'fawry'
15
+
16
+ ARGV.clear
17
+ IRB.start
18
+ end
@@ -35,5 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'byebug', '~> 11.0', '>= 11.0.1'
36
36
  spec.add_development_dependency 'rake', '~> 10.0'
37
37
  spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rspec_junit_formatter'
39
+ spec.add_development_dependency 'rubocop', '~> 0.76.0'
38
40
  spec.add_development_dependency 'webmock', '~> 3.7', '>= 3.7.6'
39
41
  end
@@ -21,19 +21,19 @@ module Fawry
21
21
  # the request signature
22
22
  #
23
23
  # @param params [Hash] list of params to send to fawry
24
- # required(:merchant_code).value(:string)
25
24
  # required(:merchant_ref_num).value(:string)
26
25
  # required(:customer_profile_id).value(:string)
27
26
  # required(:amount).value(:decimal)
28
27
  # required(:description).value(:string)
29
28
  # required(:customer_mobile).value(:string)
30
- # required(:fawry_secure_key).value(:string)
31
29
  # required(:charge_items).array(:hash) do
32
30
  # required(:item_id).value(:string)
33
31
  # required(:description).value(:string)
34
32
  # required(:price).value(:decimal)
35
33
  # required(:quantity).value(:integer)
36
34
  # end
35
+ # optional(:merchant_code).value(:string)
36
+ # optional(:fawry_secure_key).value(:string)
37
37
  # optional(:currency_code).value(:string)
38
38
  # optional(:card_token).value(:string)
39
39
  # optional(:customer_email).value(:string)
@@ -63,10 +63,10 @@ module Fawry
63
63
  # the request signature
64
64
  #
65
65
  # @param params [Hash] list of params to send to fawry
66
- # required(:merchant_code).value(:string)
67
66
  # required(:reference_number).value(:string)
68
67
  # required(:refund_amount).value(:decimal)
69
- # required(:fawry_secure_key).value(:string)
68
+ # optional(:merchant_code).value(:string)
69
+ # optional(:fawry_secure_key).value(:string)
70
70
  # optional(:reason).value(:string)
71
71
  #
72
72
  # @param opts [Hash] list of options to
@@ -91,9 +91,9 @@ module Fawry
91
91
  # the request signature
92
92
  #
93
93
  # @param params [Hash] list of params to send to fawry
94
- # required(:merchant_code).value(:string)
95
94
  # required(:merchant_ref_number).value(:string)
96
- # required(:fawry_secure_key).value(:string)
95
+ # optional(:merchant_code).value(:string)
96
+ # optional(:fawry_secure_key).value(:string)
97
97
  #
98
98
  # @param opts [Hash] list of options to
99
99
  # configure the request
@@ -128,8 +128,8 @@ module Fawry
128
128
  #
129
129
  # @return [Fawry::FawryCallback] an object that
130
130
  # has Fawry server callback params' keys as instance methods
131
- def parse_callback(params, fawry_secure_key, opts = {})
132
- FawryCallback.new(params, fawry_secure_key, opts).parse
131
+ def parse_callback(params, opts = {})
132
+ FawryCallback.new(params, opts).parse
133
133
  end
134
134
  end
135
135
  end
@@ -6,19 +6,19 @@ module Fawry
6
6
  module Contracts
7
7
  class ChargeRequestContract < Dry::Validation::Contract
8
8
  params do
9
- required(:merchant_code).value(:string)
10
9
  required(:merchant_ref_num).value(:string)
11
10
  required(:customer_profile_id).value(:string)
12
11
  required(:amount).value(:decimal)
13
12
  required(:description).value(:string)
14
13
  required(:customer_mobile).value(:string)
15
- required(:fawry_secure_key).value(:string)
16
14
  required(:charge_items).array(:hash) do
17
15
  required(:item_id).value(:string)
18
16
  required(:description).value(:string)
19
17
  required(:price).value(:decimal)
20
18
  required(:quantity).value(:integer)
21
19
  end
20
+ optional(:merchant_code).value(:string)
21
+ optional(:fawry_secure_key).value(:string)
22
22
  optional(:currency_code).value(:string)
23
23
  optional(:card_token).value(:string)
24
24
  optional(:customer_email).value(:string)
@@ -37,6 +37,18 @@ module Fawry
37
37
  key.failure('card_token is required when payment_method is CARD')
38
38
  end
39
39
  end
40
+
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')
44
+ end
45
+ end
46
+
47
+ 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')
50
+ end
51
+ end
40
52
  end
41
53
  end
42
54
  end
@@ -6,9 +6,21 @@ module Fawry
6
6
  module Contracts
7
7
  class PaymentStatusRequestContract < Dry::Validation::Contract
8
8
  params do
9
- required(:merchant_code).value(:string)
10
9
  required(:merchant_ref_number).value(:string)
11
- required(:fawry_secure_key).value(:string)
10
+ optional(:merchant_code).value(:string)
11
+ optional(:fawry_secure_key).value(:string)
12
+ end
13
+
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')
17
+ end
18
+ end
19
+
20
+ 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')
23
+ end
12
24
  end
13
25
  end
14
26
  end
@@ -6,12 +6,24 @@ module Fawry
6
6
  module Contracts
7
7
  class RefundRequestContract < Dry::Validation::Contract
8
8
  params do
9
- required(:merchant_code).value(:string)
10
9
  required(:reference_number).value(:string)
11
10
  required(:refund_amount).value(:decimal)
12
- required(:fawry_secure_key).value(:string)
11
+ optional(:merchant_code).value(:string)
12
+ optional(:fawry_secure_key).value(:string)
13
13
  optional(:reason).value(:string)
14
14
  end
15
+
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')
19
+ end
20
+ end
21
+
22
+ 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')
25
+ end
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -6,9 +6,9 @@ module Fawry
6
6
 
7
7
  attr_reader :callback_params, :fawry_secure_key, :options
8
8
 
9
- def initialize(callback_params, fawry_secure_key, opts)
9
+ def initialize(callback_params, opts)
10
10
  @callback_params = callback_params
11
- @fawry_secure_key = fawry_secure_key
11
+ @fawry_secure_key = ENV.fetch('FAWRY_SECURE_KEY')
12
12
  @options = opts
13
13
  end
14
14
 
@@ -33,7 +33,7 @@ module Fawry
33
33
  # rubocop:disable Metrics/MethodLength
34
34
  def charge_request_transformed_params
35
35
  {
36
- merchantCode: request_params[:merchant_code],
36
+ merchantCode: fawry_merchant_code,
37
37
  merchantRefNum: request_params[:merchant_ref_num],
38
38
  customerProfileId: request_params[:customer_profile_id],
39
39
  cardToken: request_params[:card_token],
@@ -51,6 +51,14 @@ module Fawry
51
51
  # rubocop:enable Metrics/MethodLength
52
52
  # rubocop:enable Metrics/AbcSize
53
53
 
54
+ def fawry_merchant_code
55
+ ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
56
+ end
57
+
58
+ def fawry_secure_key
59
+ ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
60
+ end
61
+
54
62
  def validate_charge_params!
55
63
  contract = Contracts::ChargeRequestContract.new.call(request_params)
56
64
  raise InvalidFawryRequestError, contract.errors.to_h if contract.failure?
@@ -60,14 +68,12 @@ module Fawry
60
68
  request_params[:charge_items].each { |hash| hash[:itemId] = hash.delete(:item_id) }
61
69
  end
62
70
 
63
- # rubocop:disable Metrics/AbcSize
64
71
  def charge_request_signature
65
- Digest::SHA256.hexdigest("#{request_params[:merchant_code]}#{request_params[:merchant_ref_num]}"\
72
+ Digest::SHA256.hexdigest("#{fawry_merchant_code}#{request_params[:merchant_ref_num]}"\
66
73
  "#{request_params[:customer_profile_id]}#{request_params[:payment_method]}"\
67
74
  "#{format('%<amount>.2f', amount: request_params[:amount])}"\
68
- "#{request_params[:card_token]}#{request_params[:fawry_secure_key]}")
75
+ "#{request_params[:card_token]}#{fawry_secure_key}")
69
76
  end
70
- # rubocop:enable Metrics/AbcSize
71
77
  end
72
78
  end
73
79
  end
@@ -29,20 +29,28 @@ module Fawry
29
29
 
30
30
  def payment_status_request_transformed_params
31
31
  {
32
- merchantCode: request_params[:merchant_code],
32
+ merchantCode: fawry_merchant_code,
33
33
  merchantRefNumber: request_params[:merchant_ref_number],
34
34
  signature: payment_status_request_signature
35
35
  }.compact
36
36
  end
37
37
 
38
+ def fawry_merchant_code
39
+ ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
40
+ end
41
+
42
+ def fawry_secure_key
43
+ ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
44
+ end
45
+
38
46
  def validate_payment_status_params!
39
47
  contract = Contracts::PaymentStatusRequestContract.new.call(request_params)
40
48
  raise InvalidFawryRequestError, contract.errors.to_h if contract.failure?
41
49
  end
42
50
 
43
51
  def payment_status_request_signature
44
- Digest::SHA256.hexdigest("#{request_params[:merchant_code]}#{request_params[:merchant_ref_number]}"\
45
- "#{request_params[:fawry_secure_key]}")
52
+ Digest::SHA256.hexdigest("#{fawry_merchant_code}#{request_params[:merchant_ref_number]}"\
53
+ "#{fawry_secure_key}")
46
54
  end
47
55
  end
48
56
  end
@@ -29,7 +29,7 @@ module Fawry
29
29
 
30
30
  def refund_request_transformed_params
31
31
  {
32
- merchantCode: request_params[:merchant_code],
32
+ merchantCode: fawry_merchant_code,
33
33
  referenceNumber: request_params[:reference_number],
34
34
  refundAmount: request_params[:refund_amount],
35
35
  reason: request_params[:reason],
@@ -37,15 +37,23 @@ module Fawry
37
37
  }.compact
38
38
  end
39
39
 
40
+ def fawry_merchant_code
41
+ ENV.fetch('FAWRY_MERCHANT_CODE') { request_params[:merchant_code] }
42
+ end
43
+
44
+ def fawry_secure_key
45
+ ENV.fetch('FAWRY_SECURE_KEY') { request_params[:fawry_secure_key] }
46
+ end
47
+
40
48
  def validate_refund_params!
41
49
  contract = Contracts::RefundRequestContract.new.call(request_params)
42
50
  raise InvalidFawryRequestError, contract.errors.to_h if contract.failure?
43
51
  end
44
52
 
45
53
  def refund_request_signature
46
- Digest::SHA256.hexdigest("#{request_params[:merchant_code]}#{request_params[:reference_number]}"\
54
+ Digest::SHA256.hexdigest("#{fawry_merchant_code}#{request_params[:reference_number]}"\
47
55
  "#{format('%<refund_amount>.2f', refund_amount: request_params[:refund_amount])}"\
48
- "#{request_params[:reason]}#{request_params[:fawry_secure_key]}")
56
+ "#{request_params[:reason]}#{fawry_secure_key}")
49
57
  end
50
58
  end
51
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fawry
4
- VERSION = '0.3.0'
4
+ VERSION = '1.0.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: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amr Bakry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation
@@ -106,6 +106,34 @@ dependencies:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
108
  version: '3.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rspec_junit_formatter
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.76.0
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.76.0
109
137
  - !ruby/object:Gem::Dependency
110
138
  name: webmock
111
139
  requirement: !ruby/object:Gem::Requirement
@@ -133,10 +161,11 @@ executables: []
133
161
  extensions: []
134
162
  extra_rdoc_files: []
135
163
  files:
164
+ - ".circleci/config.yml"
165
+ - ".github/workflows/greetings.yml"
136
166
  - ".gitignore"
137
167
  - ".rspec"
138
168
  - ".rubocop.yml"
139
- - ".travis.yml"
140
169
  - CODE_OF_CONDUCT.md
141
170
  - Gemfile
142
171
  - Gemfile.lock
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.0
7
- before_install: gem install bundler -v 2.0.2