nexio 0.1.0 → 0.2.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: 6f2411545550be2a2cf60a4ab7f8eb701a230e69a47b2351e00be776d27c6c56
4
- data.tar.gz: bceb8db2b0a04f7fe44b9d215ba844762eb69c4bae73e8e33c1584971cfc1a03
3
+ metadata.gz: 3ab9be3e918229d1d712c9ba5899fe049bfc044d39988dc782e97dc606bd7f83
4
+ data.tar.gz: '099f6f223415c4b43b51078278e3078fe03d120fbcca827c2bffdfe9db815fe6'
5
5
  SHA512:
6
- metadata.gz: 346f80c80b6e89bac3aefb1b480334f652f1405321b8de018fb356a881e04cb945b3745aefdb9636f78e5bc7668ddc3f25256175e09c70b6454b7ddb52cb748b
7
- data.tar.gz: 4b1a95b0f7d72dba3a20cced1f0770949df3681a4e00c37f251824db2cf7232a952376df30ad718bb7769e07d021408464e292224ad54a44218f00724096504a
6
+ metadata.gz: 48eec7f321486b66348bfc18578db90f7501485566dca0e3d77be32a1460a80e59ad8019bb2c31a663acf5094bf4dbddf605a9d02fbefafe07cb4075ff39d415
7
+ data.tar.gz: c003d29fe611abb05bbfe014d644067f10224f62c8219385763074001f4f08059939544d7c9050238e2658d44b1b454859c1d419949cbd56fb64cf0a245099ed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2024-06-03
4
+
5
+ - Lots of updates :]
6
+
3
7
  ## [0.1.0] - 2024-02-27
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -1,20 +1,14 @@
1
1
  # Nexio
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nexio`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
3
  ## Installation
8
4
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
5
  Install the gem and add to the application's Gemfile by executing:
12
6
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
7
+ $ bundle add nexio
14
8
 
15
9
  If bundler is not being used to manage dependencies, install the gem by executing:
16
10
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
11
+ $ gem install nexio
18
12
 
19
13
  ## Usage
20
14
 
@@ -47,13 +41,32 @@ Setting `config.environment` to `development` will use sandbox, otherwise it wil
47
41
  }})["token"]
48
42
  ```
49
43
 
44
+ **Saving a credit card**
45
+ ```
46
+ @card = Nexio::PaymentGateway.save_card(
47
+ {
48
+ "card" => {
49
+ "cardHolderName" => "Abdul Barek",
50
+ "expirationMonth" => "10",
51
+ "expirationYear" => "#{Date.today.year + 10}",
52
+ "encryptedNumber" => "JQ2DIwFqQOCypsOE+3n0Mx6W6das1LrFAQVFR1lBD9KySCbVQXvJoweQ7R3wCv34oK6d8QlYQgsAWpmcROiwe4LowQI3pLfADmGRg4arowdaW8UBcR3gm26tT7KUdG13Y+0aiTKSleSJiRUSm3yU/VrNMe1tblYG+SsmtC8c3PEZkQxkJ216RYCzBkFRku2O7TRvx/GtxGd4VQItIF567VanRmZ8tIUaZGg9ZN6PKzUifRfCCt+2XGY7I1+Z7EOEAX1gQZT86+2vzcdk8MiZtMS4KYs+4kngSxR2EhyJa+3wRQBmkApRt03qCoWJEPIbNYxgwdjapy2oWeI/DrZu6A=="
53
+ },
54
+ "data" => {
55
+ "currency" => "USD"
56
+ },
57
+ "shouldUpdateCard" => true,
58
+ "token" => <ONE_TIME_TOKEN>
59
+ }
60
+ )
61
+ ```
62
+
50
63
  **Update a card**
51
64
  ```
52
65
  data = {
53
66
  "shouldUpdateCard" => true,
54
67
  "card" => {
55
68
  "expirationYear" => 2036,
56
- "cardHolderName" => Abdul Barek,
69
+ "cardHolderName" => "Abdul Barek",
57
70
  "expirationMonth" => 3
58
71
  },
59
72
  "data" => {
@@ -80,40 +93,96 @@ Nexio::PaymentGateway.delete_card([card_token1, card_token2])
80
93
  Nexio::PaymentGateway.card_token(card_token)
81
94
  ```
82
95
 
83
- **Saving a credit card**
96
+ **Charging a card through it's token**
97
+
98
+ It is highly recommended to pass order number and customer reference on charging a credit card. Also it is
99
+ mandatory to pass paymentType. For one time payment pass one of the following based on your scenario:
100
+ 1. merchant initiated using new card: `initialMoto`
101
+ 2. client initiated using new card: `initialUnscheduled`
102
+ 3. merchant initiated using saved card: `unscheduledMit`
103
+ 4. client initiated using saved card: `unscheduledCit`
104
+
105
+ Please check this for more information https://docs.nexiopay.com/docs/constant-transaction-values#payment-type-paymenttype
106
+
84
107
  ```
85
- @card = Nexio::PaymentGateway.save_card(
86
- {
87
- "card" => {
88
- "cardHolderName" => "Abdul Barek",
89
- "expirationMonth" => "10",
90
- "expirationYear" => "#{Date.today.year + 10}",
91
- "encryptedNumber" => "JQ2DIwFqQOCypsOE+3n0Mx6W6das1LrFAQVFR1lBD9KySCbVQXvJoweQ7R3wCv34oK6d8QlYQgsAWpmcROiwe4LowQI3pLfADmGRg4arowdaW8UBcR3gm26tT7KUdG13Y+0aiTKSleSJiRUSm3yU/VrNMe1tblYG+SsmtC8c3PEZkQxkJ216RYCzBkFRku2O7TRvx/GtxGd4VQItIF567VanRmZ8tIUaZGg9ZN6PKzUifRfCCt+2XGY7I1+Z7EOEAX1gQZT86+2vzcdk8MiZtMS4KYs+4kngSxR2EhyJa+3wRQBmkApRt03qCoWJEPIbNYxgwdjapy2oWeI/DrZu6A=="
92
- },
93
- "data" => {
94
- "currency" => "USD"
95
- },
96
- "shouldUpdateCard" => true,
97
- "token" => <ONE_TIME_TOKEN>
98
- }
99
- )
108
+ customer = {
109
+ "orderNumber" => 4848,
110
+ "customerRef" => 123
111
+ }
112
+ processingOptions = {
113
+ "paymentType" => 'initialMoto'
114
+ }
115
+ amount_in_usd = 20.25
116
+ Nexio::PaymentGateway.charge(amount_in_usd,card_token, customer, processingOptions)
100
117
  ```
101
118
 
102
- **Charging a card through it's token**
119
+ **How to refund**
103
120
  ```
104
- amount_in_usd = 20.25
105
- Nexio::PaymentGateway.charge(amount_in_usd,card_token)
121
+ @refund = Nexio::PaymentGateway.refund(@nexio_payment_id,1.20)
122
+ ```
123
+ You can use card `5105105105105100` to charge and refund for testing purpose as it settles payment immediately.
124
+
125
+ **Get Payment Status**
126
+ Before refunding, it is needed to know the payment status Settled. Please visit
127
+ https://docs.nexiopay.com/docs/constant-transaction-values#transaction-status-transactionstatus
128
+ to know the different payment status
129
+ ```
130
+ @payment_status = Nexio::PaymentGateway.payment_status(@nexio_payment_id)
131
+ ```
132
+
133
+ **How to void a payment**
134
+ ```
135
+ @payment_status = Nexio::PaymentGateway.void_payment(@nexio_payment_id)
106
136
  ```
107
137
 
108
138
  **Handling error**
109
139
  ```
110
140
  begin
111
- Nexio::PaymentGateway.charge(10.60,'invalid_card_token')
141
+ Nexio::PaymentGateway.charge(10.60,'invalid_card_token',customer,processingOptions)
112
142
  rescue Nexio::NexioError => e
113
143
  puts e.to_hash
114
144
  end
115
145
  ```
116
146
 
147
+ **Getting http request details including body parameters and header information**
148
+ ```
149
+ begin
150
+ Nexio::PaymentGateway.charge(10.60,'invalid_card_token',customer,processingOptions)
151
+ rescue Nexio::NexioError => e
152
+ puts e.request_details_in_hash
153
+ end
154
+ ```
155
+
156
+ **How to use custom css**
157
+
158
+ This is very easy to style payment form by passing css file in `uiOptions` as below:
159
+ ```
160
+ @nexio_one_time_token = Nexio::PaymentGateway.create_one_time_token(
161
+ {
162
+ "card" => {},
163
+ "uiOptions" => {
164
+ "css" => ActionController::Base.helpers.asset_path('your_custom.css', host: Rails.application.secrets.asset_host ? Rails.application.secrets.asset_host : request.base_url)
165
+ },
166
+ "data" => {
167
+ "currency" => "USD",
168
+ "customer" => {}
169
+ }})["token"]
170
+ ```
171
+ Sample CSS: Nexio payment form has a wrapper with `#paymentForm` element, so you can apply more
172
+ css considering it as parent. Just inspect the Nexio payment form to get their DOM structure in order
173
+ to apply styles. SCSS Example:
174
+ ```
175
+ #paymentForm{
176
+ width: 500px;
177
+ margin-left: 180px;
178
+ #cardHolderName{}
179
+ #securityCode{}
180
+ }
181
+ ```
182
+
183
+ ## Testing
184
+ `bundle exec rake test`
185
+
117
186
  ## Development
118
187
 
119
188
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -16,7 +16,9 @@ module Nexio
16
16
  end
17
17
 
18
18
  def api_key!
19
- api_key || raise(NexioError, "No api key specified.")
19
+ raise MissingApiKey if api_key.nil? || api_key.empty?
20
+
21
+ api_key
20
22
  end
21
23
 
22
24
  def api_server_url
@@ -117,23 +117,29 @@ module Nexio
117
117
  end
118
118
 
119
119
  # Makes a charge of a given card using the associated card token
120
- def self.charge(amount=0, card_token)
120
+ def self.charge(amount=0, card_token, customer, processingOptions)
121
+ processingOptions = {} if !defined?(processingOptions) || processingOptions.nil? || processingOptions.empty?
121
122
  url = URI("#{Nexio.configuration.api_server_url}/pay/v3/process")
122
123
  @request = Net::HTTP::Post.new(url)
123
124
  http, request = configure_https_request(url, @request)
124
125
  request.body = {
125
126
  "data" => {
126
- "currency" => "USD", "amount" => amount
127
+ "currency" => "USD", "amount" => amount,
128
+ "customer" => {
129
+ "customerRef" => customer["customerRef"],
130
+ "orderNumber" => customer["orderNumber"],
131
+ },
127
132
  },
128
133
  "tokenex" => {"token" => card_token},
129
134
  "processingOptions" =>
130
135
  {
136
+ "paymentType" => processingOptions["paymentType"],
131
137
  "retryOnSoftDecline" => false,
132
138
  "checkFraud" => true,
133
139
  "shouldUseFingerprint" => true,
134
140
  "check3ds" => false,
135
141
  "verboseResponse" => false
136
- },
142
+ }.merge(processingOptions),
137
143
  "shouldUpdateCard" => true,
138
144
  "isAuthOnly" => false,
139
145
  "paymentMethod" => "card"
@@ -142,6 +148,40 @@ module Nexio
142
148
  response_or_raise_error(response)
143
149
  end
144
150
 
151
+ # Amount is in USD
152
+ def self.refund(nexio_payment_id, amount)
153
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/refund")
154
+ @request = Net::HTTP::Post.new(url)
155
+ http, request = configure_https_request(url, @request)
156
+ request.body = {
157
+ "id" => nexio_payment_id,
158
+ "data" => {
159
+ "currency" => "USD", "amount" => amount
160
+ },
161
+ }.to_json
162
+ response = http.request(request)
163
+ response_or_raise_error(response)
164
+ end
165
+
166
+ def self.payment_status(nexio_payment_id)
167
+ url = URI("#{Nexio.configuration.api_server_url}/transaction/v3/paymentId/#{nexio_payment_id}")
168
+ @request = Net::HTTP::Get.new(url)
169
+ http, request = configure_https_request(url, @request)
170
+ response = http.request(request)
171
+ response_or_raise_error(response)
172
+ end
173
+
174
+ def self.void_payment(nexio_payment_id)
175
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/void")
176
+ @request = Net::HTTP::Post.new(url)
177
+ http, request = configure_https_request(url, @request)
178
+ request.body = {
179
+ "id" => nexio_payment_id
180
+ }.to_json
181
+ response = http.request(request)
182
+ response_or_raise_error(response)
183
+ end
184
+
145
185
  # https configuration using base64 basic auth code
146
186
  def self.configure_https_request(url, request)
147
187
  http = Net::HTTP.new(url.host, url.port)
data/lib/nexio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexio
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/nexio.rb CHANGED
@@ -23,6 +23,13 @@ module Nexio
23
23
  end
24
24
  end
25
25
 
26
+ class MissingApiKey < StandardError
27
+ def initialize(msg = "No api key configured", exception_type = "missing_api_key")
28
+ @exception_type = exception_type
29
+ super(msg)
30
+ end
31
+ end
32
+
26
33
  def self.configuration
27
34
  @configuration ||= Configuration.new
28
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TherapyMate
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-03-21 00:00:00.000000000 Z
13
+ date: 2024-06-04 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
- rubygems_version: 3.4.19
58
+ rubygems_version: 3.3.26
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: Nexio integration with Ruby on Rails