HyperPay 0.1.0 → 0.1.1

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: cb8d58ae8360368a30935be12cc4e3dc0d2c5a234b6d1d31cad4959428864b3e
4
- data.tar.gz: dfa14a6b30908707bc19eff2e4165b86bb42cc349ec50e32e659ec4fdeb2a5ed
3
+ metadata.gz: 3d0bf2a05890ebbdd9fbd9e516c679e69cc0a6a8555af7c4210ef0c866a49f8b
4
+ data.tar.gz: f706cde04cc238345f4f850c154445dee05daf1cd335df8478bd9d46123367ca
5
5
  SHA512:
6
- metadata.gz: dd532c6e1f74bbd756f0f544871edf1b3096a2395a50c62781848cfce90fdd62f3bac08ff1d95d0f310889f3432a434140b9337e2e419f1d8589f5e527478626
7
- data.tar.gz: 279b7866cf4eae7488f5f574366621bc274e3f60aaef460512a6f8ff299433725e1a8a19fd6295f9be26dcce1ae922f2369bdea755822fb5e5ea4fbede1e111c
6
+ metadata.gz: 4a22241cdf4ee982fb4d62e971756412c6f9b8e491493a4685673af74c42d8c334b67f4b2f53b745cd3cde05f6136146743961a3c1650c07d9a7a9d6732f045b
7
+ data.tar.gz: b32871687e2a251d90535e3325c06c877b9360a9cf661aafdc20ffa75bdf3767444f9e68ec004754aa7bcc8e75dcb5bcf0696a8291d85f49b6ddad76c09b199e
data/README.md CHANGED
@@ -16,6 +16,8 @@ gem 'HyperPay'
16
16
 
17
17
  `config/initializers/hyperpay.rb`
18
18
  ```ruby
19
+ require 'hyper_pay'
20
+
19
21
  HyperPay.configure do |config|
20
22
  config.authorization = "HYPER_PAY_AUTH_TOKEN"
21
23
  config.environment = :sandbox
@@ -26,12 +28,6 @@ end
26
28
 
27
29
  ### Generate Checkout ID
28
30
  ```ruby
29
- # Generate HyperPay Checkout ID
30
- #
31
- # Parameters:
32
- # @entity_id Entity ID that was used to generate the Checkout ID
33
- # @return [Hash] {"result"=>{"code"=>"000.200.100", "description"=>"successfully created checkout"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:22+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03", "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
34
-
35
31
  checkout = HyperPay::CopyAndPay.new.create_checkout_id do |params|
36
32
  params.add "entityId", "HYPER_PAY_ENTITY_ID"
37
33
  params.add "customer.email", "john@doe.com"
@@ -58,37 +54,139 @@ end
58
54
 
59
55
  ### Response
60
56
  ```ruby
61
- {"result"=>{"code"=>"000.200.100", "description"=>"successfully created checkout"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:22+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03", "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
57
+ {
58
+ "result"=>{
59
+ "code"=>"000.200.100",
60
+ "description"=>"successfully created checkout"
61
+ },
62
+ "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000",
63
+ "timestamp"=>"2024-03-05 13:50:22+0000",
64
+ "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03",
65
+ "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"
66
+ }
62
67
  ```
63
68
 
69
+ -----
64
70
  ### Get Payment Status for Checkout ID
65
71
  ```ruby
66
- # Get HyperPay payment status for a given checkout
67
- #
68
- # Parameters:
69
- # @entity_id Entity ID that was used to generate the Checkout ID
70
- # @checkout_id HyperPay Checkout ID
71
- # @return [Hash] {"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
72
- def get_status(entity_id:, checkout_id:)
73
- get("/v1/checkouts/#{checkout_id}/payment"+"?entityId=#{entity_id}")
74
- end
75
-
76
72
  checkout = HyperPay::CopyAndPay.new.get_status(entity_id: "", checkout_id: "")
77
73
  p checkout['id']
78
74
  p checkout['result']['code']
79
75
  p checkout['result']['description']
80
76
  ```
81
77
 
82
- ### Response
78
+ ### Pending Response
79
+ ```ruby
80
+ {
81
+ "result"=>{
82
+ "code"=>"000.200.000",
83
+ "description"=>"transaction pending"
84
+ },
85
+ "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000",
86
+ "timestamp"=>"2024-03-05 13:50:29+0000",
87
+ "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"
88
+ }
89
+ ```
90
+
91
+ ### Success Response
83
92
  ```ruby
84
- {"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
93
+ {
94
+ "id"=>"8ac7a4a08e10b158018e1486506e0397",
95
+ "paymentType"=>"DB",
96
+ "paymentBrand"=>"VISA",
97
+ "amount"=>"600.00",
98
+ "currency"=>"SAR",
99
+ "descriptor"=>"0000.0000.0000 Company Name",
100
+ "merchantTransactionId"=>"139895288",
101
+ "result"=>{
102
+ "code"=>"000.000.000",
103
+ "description"=>"Transaction succeeded"
104
+ },
105
+ "resultDetails"=>{
106
+ "ExtendedDescription"=>"Successfully processed",
107
+ "ProcStatus"=>"0",
108
+ "clearingInstituteName"=>"NCB BANK",
109
+ "AuthCode"=>"f2e7a815c3",
110
+ "ConnectorTxID1"=>"8ac7a4a08e10b158018e1486506e0397",
111
+ "ConnectorTxID3"=>"10b158018e1486506e0397",
112
+ "ConnectorTxID2"=>"8ac7a4a0",
113
+ "AcquirerResponse"=>"00",
114
+ "EXTERNAL_SYSTEM_LINK"=>"https://csi-test.retaildecisions.com/RS60/TransDetail.aspx?oid=000194001101S2E20110926045038668&support=Link+to+Risk+Details",
115
+ "TermID"=>"71F00820",
116
+ "OrderID"=>"8316384413"
117
+ },
118
+ "card"=>{
119
+ "bin"=>"411111",
120
+ "binCountry"=>"PL",
121
+ "last4Digits"=>"1111",
122
+ "holder"=>"DFGY",
123
+ "expiryMonth"=>"05",
124
+ "expiryYear"=>"2025",
125
+ "issuer"=>{
126
+ "bank"=>"CONOTOXIA SP. Z O.O"
127
+ },
128
+ "type"=>"DEBIT",
129
+ "level"=>"CLASSIC",
130
+ "country"=>"PL",
131
+ "maxPanLength"=>"16",
132
+ "binType"=>"PERSONAL",
133
+ "regulatedFlag"=>"N"
134
+ },
135
+ "customer"=>{
136
+ "givenName"=>"Mohamad",
137
+ "surname"=>"Kaakati",
138
+ "mobile"=>"966540000000",
139
+ "email"=>"john@doe.com",
140
+ "ip"=>"0.0.0.0",
141
+ "ipCountry"=>"SA"
142
+ },
143
+ "billing"=>{
144
+ "street1"=>"Saudi Arabia",
145
+ "city"=>"Jeddah",
146
+ "country"=>"SA"
147
+ },
148
+ "threeDSecure"=>{
149
+ "eci"=>"05",
150
+ "xid"=>"CAACCVVUlwCXUyhQNlSXAAAAAAA=",
151
+ "authenticationStatus"=>"Y"
152
+ },
153
+ "customParameters"=>{
154
+ "SHOPPER_MSDKIntegrationType"=>"Checkout UI",
155
+ "SHOPPER_device"=>"Apple iPhone 15 Pro",
156
+ "CTPE_DESCRIPTOR_TEMPLATE"=>"",
157
+ "SHOPPER_OS"=>"iOS 17.4",
158
+ "SHOPPER_MSDKVersion"=>"4.12.0",
159
+ "3DS2_enrolled"=>"true"
160
+ },
161
+ "risk"=>{
162
+ "score"=>"100"
163
+ },
164
+ "buildNumber"=>"e41989c9076807bb305850f77ce20740230863b9@2024-03-05 14:10:27 +0000",
165
+ "timestamp"=>"2024-03-06 16:08:56+0000",
166
+ "ndc"=>"67F1CF7891ADB9400CD013BC77A4CE5C.uat01-vm-tx03"
167
+ }
85
168
  ```
86
169
 
87
- ## Backoffce Operations
170
+ ## Response Code Interpretation
171
+
172
+ ----
173
+
174
+ Now, anywhere in your application where you have a response code from HyperPay that you want to interpret, you can easily get its meaning:
175
+
176
+ ```ruby
177
+ base = HyperPay::Base.new
178
+ result = base.interpret_response_code("000.100.1")
179
+ puts result # :transaction_succeeded
180
+
181
+ ```
182
+
183
+ ## BackOffice Operations
184
+
185
+ -----
88
186
 
89
187
  ### Capture Payment
90
188
  ```ruby
91
- HyperPay::CopyAndPay.new.capture_payment(entity_id:, checkout_id:, amount:, currency:)
189
+ HyperPay::CopyAndPay.new.capture_payment(entity_id: "", checkout_id: "", amount: "", currency: "")
92
190
  ```
93
191
 
94
192
  ### Refund Payment
data/lib/HyperPay/base.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "httparty"
4
4
  require "HyperPay/configuration"
5
+ require "HyperPay/response_code_interpreter"
5
6
 
6
7
  module HyperPay
7
8
  class Base
@@ -11,6 +12,10 @@ module HyperPay
11
12
  self.class.base_uri base_url
12
13
  end
13
14
 
15
+ def interpret_response_code(code)
16
+ ResponseCodeInterpreter.interpret(code)
17
+ end
18
+
14
19
  private
15
20
 
16
21
  def get(path)
@@ -48,8 +53,6 @@ module HyperPay
48
53
  HyperPay.configuration.environment == :sandbox ? "https://eu-test.oppwa.com" : "https://eu-prod.oppwa.com"
49
54
  end
50
55
 
51
- private
52
-
53
56
  def prepare_headers(options)
54
57
  content_type = options.dig(:headers, "Content-Type") == "application/x-www-form-urlencoded" ?
55
58
  "application/x-www-form-urlencoded" : "application/json"
@@ -23,6 +23,14 @@ module HyperPay
23
23
  # @entity_id Entity ID that was used to generate the Checkout ID
24
24
  # @checkout_id HyperPay Checkout ID
25
25
  # @return [Hash] {"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
26
+ # @return [Hash] {"id"=>"8ac7a4a08e10b158018e1486506e0397",
27
+ # "paymentType"=>"DB", "paymentBrand"=>"VISA", "amount"=>"600.00", "currency"=>"SAR", "descriptor"=>"9539.3104.2548 Group",
28
+ # "merchantTransactionId"=>"139895288", "result"=>{"code"=>"000.000.000", "description"=>"Transaction succeeded"},
29
+ # "resultDetails"=>{"ExtendedDescription"=>"Successfully processed", "ProcStatus"=>"0", "clearingInstituteName"=>"NCB BANK", "AuthCode"=>"f2e7a815c3",
30
+ # "ConnectorTxID1"=>"8ac7a4a08e10b158018e1486506e0397", "ConnectorTxID3"=>"10b158018e1486506e0397", "ConnectorTxID2"=>"8ac7a4a0", "AcquirerResponse"=>"00",
31
+ # "EXTERNAL_SYSTEM_LINK"=>"https://csi-test.retaildecisions.com/RS60/TransDetail.aspx?oid=000194001101S2E20110926045038668&support=Link+to+Risk+Details", "TermID"=>"71F00820",
32
+ # "OrderID"=>"8316384413"},
33
+ # "card"=>{"bin"=>"411111", "binCountry"=>"PL", "last4Digits"=>"1111", "holder"=>"DFGY", "expiryMonth"=>"05", "expiryYear"=>"2025", "issuer"=>{"bank"=>"CONOTOXIA SP. Z O.O"}, "type"=>"DEBIT", "level"=>"CLASSIC", "country"=>"PL", "maxPanLength"=>"16", "binType"=>"PERSONAL", "regulatedFlag"=>"N"}, "customer"=>{"givenName"=>"mohammad", "surname"=>"kassab", "mobile"=>"966544299944", "email"=>"mohammad.a.kassab@gmail.com", "ip"=>"213.204.77.158", "ipCountry"=>"LB"}, "billing"=>{"street1"=>"Saudi Arabia", "city"=>"Jeddah", "country"=>"SA"}, "threeDSecure"=>{"eci"=>"05", "xid"=>"CAACCVVUlwCXUyhQNlSXAAAAAAA=", "authenticationStatus"=>"Y"}, "customParameters"=>{"SHOPPER_MSDKIntegrationType"=>"Checkout UI", "SHOPPER_device"=>"samsung samsung SM-S918B", "CTPE_DESCRIPTOR_TEMPLATE"=>"", "SHOPPER_OS"=>"Android 14", "SHOPPER_MSDKVersion"=>"4.12.0", "3DS2_enrolled"=>"true"}, "risk"=>{"score"=>"100"}, "buildNumber"=>"e41989c9076807bb305850f77ce20740230863b9@2024-03-05 14:10:27 +0000", "timestamp"=>"2024-03-06 16:08:56+0000", "ndc"=>"67F1CF7891ADB9400CD013BC77A4CE5C.uat01-vm-tx03"}
26
34
  def get_status(entity_id:, checkout_id:)
27
35
  get("/v1/checkouts/#{checkout_id}/payment"+"?entityId=#{entity_id}")
28
36
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ResponseCodeInterpreter
4
+ CONSTANTS = {
5
+ transaction_succeeded: /^(000.000.|000.100.1|000.[36]|000.400.1[12]0)/,
6
+ transaction_succeeded_review: /^(000.400.0[^3]|000.400.100)/,
7
+ transaction_pending: /^(000\.200)/,
8
+ transaction_declined: /^(800\.[17]00|800\.800\.[123])/,
9
+ rejected_communication_error: /^(900\.[1234]00|000\.400\.030)/,
10
+ rejected_system_error: /^(800\.[56]|999\.|600\.1|800\.800\.[84])/,
11
+ rejected_for_risk: /^(100\.400\.[0-3]|100\.380\.100|100\.380\.11|100\.380\.4|100\.380\.5)/,
12
+ reject_blacklist: /^(800\.[32])/,
13
+ reject_risk_validation: /^(800\.1[123456]0)/,
14
+ reject_due_validation: /^(600\.[23]|500\.[12]|800\.121)/
15
+ }.freeze
16
+
17
+ def self.interpret(code)
18
+ CONSTANTS.find { |_status, regex| code.match?(regex) }&.first || :unknown_code
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HyperPay
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HyperPay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohamad Kaakati
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-06 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -47,6 +47,7 @@ files:
47
47
  - lib/HyperPay/configuration.rb
48
48
  - lib/HyperPay/copy_and_pay.rb
49
49
  - lib/HyperPay/payment_parameter_builder.rb
50
+ - lib/HyperPay/response_code_interpreter.rb
50
51
  - lib/HyperPay/version.rb
51
52
  - lib/hyper_pay.rb
52
53
  - sig/HyperPay.rbs