nicepay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/nicepay-console +14 -0
- data/bin/setup +8 -0
- data/lib/nicepay/api.rb +329 -0
- data/lib/nicepay/version.rb +3 -0
- data/lib/nicepay.rb +163 -0
- data/nicepay.gemspec +47 -0
- data/test-cancel.rb +84 -0
- data/test-card.rb +117 -0
- data/test-status.rb +91 -0
- data/test-va.rb +139 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 523c0fbbf79fb587f23d7fd811595ca45863e5ef
|
4
|
+
data.tar.gz: 45af56df8059dd57815a3919ad528add3dcc0232
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 358ea5671127a1f87b8ff2850fab3c9245f60273f618c65fca9d197af382fc42ec8b233fefa27a8ae89c3f2bad1487d4a8355c0b55eacaeb9eee86ea0a3c7e48
|
7
|
+
data.tar.gz: 765494c8fef163824ac822fefc212f4628046a848733440d1e092809f85b7738063291f01c04b6dfaa5250818662e919c48fcd669dec90be50bea7d3581e7e74
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 arif
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# NICEPay Ruby Binding
|
2
|
+
|
3
|
+
## Ruby SDK API Operation Test
|
4
|
+
|
5
|
+
### Virtual Account
|
6
|
+
|
7
|
+
```
|
8
|
+
$ ruby test-va.rb
|
9
|
+
```
|
10
|
+
|
11
|
+
```
|
12
|
+
----------------------------------------------------------------------
|
13
|
+
Virtual Account Number : 7001400000000631
|
14
|
+
Description : Payment of Invoice-7834
|
15
|
+
Reference No : Invoice-7834
|
16
|
+
Transaction ID : VACCTCLOSE02201606061649584906
|
17
|
+
----------------------------------------------------------------------
|
18
|
+
```
|
19
|
+
|
20
|
+
### Card Checkout
|
21
|
+
|
22
|
+
```
|
23
|
+
$ ruby test-card.rb
|
24
|
+
```
|
25
|
+
|
26
|
+
```
|
27
|
+
-----------------------------------------------------------------------------------------------------
|
28
|
+
Redirect Customer to : https://www.nicepay.co.id/nicepay/api/orderInquiry.do?tXid=IONPAYTEST01201606061651114907
|
29
|
+
tXid : IONPAYTEST01201606061651114907
|
30
|
+
-----------------------------------------------------------------------------------------------------
|
31
|
+
```
|
32
|
+
|
33
|
+
### Check Transaction Status
|
34
|
+
|
35
|
+
```
|
36
|
+
$ ruby test-status.rb
|
37
|
+
```
|
38
|
+
|
39
|
+
```
|
40
|
+
----------------------------------------------------------------------
|
41
|
+
Transaction Status : 3
|
42
|
+
Amount : 3000
|
43
|
+
Reference No : Invoice-7834
|
44
|
+
Transaction ID : VACCTCLOSE02201606061354204825
|
45
|
+
----------------------------------------------------------------------
|
46
|
+
```
|
47
|
+
|
48
|
+
## Ruby on Rails
|
49
|
+
|
50
|
+
1. Install NICEPay Gem
|
51
|
+
|
52
|
+
```
|
53
|
+
$ gem install nicepay
|
54
|
+
```
|
55
|
+
or build from source
|
56
|
+
```
|
57
|
+
$ gem build nicepay.gemspec
|
58
|
+
```
|
59
|
+
2. Create checkout controller
|
60
|
+
```
|
61
|
+
$ rails g controller checkout
|
62
|
+
```
|
63
|
+
3. Add action to controller
|
64
|
+
```
|
65
|
+
def new
|
66
|
+
end
|
67
|
+
|
68
|
+
def create
|
69
|
+
# Amount in cents
|
70
|
+
@amount = 500
|
71
|
+
|
72
|
+
requestVa= Nicepay::Api::RequestVa.new(Nicepay.requestParam)
|
73
|
+
chargeCard= Nicepay::Api::ChargeCard.new(Nicepay.requestParam)
|
74
|
+
checkStatus=Nicepay::Api::CheckStatus.new(Nicepay.requestParam)
|
75
|
+
|
76
|
+
end
|
77
|
+
```
|
78
|
+
4. Define Route
|
79
|
+
```
|
80
|
+
resources :checkout
|
81
|
+
```
|
82
|
+
5. Configure application
|
83
|
+
```
|
84
|
+
Rails.configuration.nicepay = {
|
85
|
+
:iMid=> ENV['I_MID'],
|
86
|
+
:merchantKey=> ENV['MERCHANT_KEY']
|
87
|
+
}
|
88
|
+
|
89
|
+
Nicepay.merchantKey= Rails.configuration.nicepay[:merchantKey]
|
90
|
+
Nicepay.iMid= Rails.configuration.nicepay[:iMid]
|
91
|
+
```
|
92
|
+
|
93
|
+
6. Create view
|
94
|
+
|
95
|
+
Create a checkout.html.erb layout under app/views/layouts:
|
96
|
+
```
|
97
|
+
<!DOCTYPE html>
|
98
|
+
<html>
|
99
|
+
<head>
|
100
|
+
</head>
|
101
|
+
<body>
|
102
|
+
<%= yield %>
|
103
|
+
</body>
|
104
|
+
</html>
|
105
|
+
```
|
106
|
+
|
107
|
+
and so on...
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nicepay"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/nicepay-console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'irb'
|
4
|
+
require 'irb/completion'
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/../lib/nicepay"
|
7
|
+
|
8
|
+
# Config IRB to enable --simple-prompt and auto indent
|
9
|
+
IRB.conf[:PROMPT_MODE] = :SIMPLE
|
10
|
+
IRB.conf[:AUTO_INDENT] = true
|
11
|
+
|
12
|
+
puts "Loaded gem 'nicepay'"
|
13
|
+
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/nicepay/api.rb
ADDED
@@ -0,0 +1,329 @@
|
|
1
|
+
module Nicepay
|
2
|
+
module Api
|
3
|
+
|
4
|
+
class RequestVa
|
5
|
+
|
6
|
+
def initialize(parameters)
|
7
|
+
@parameters = parameters
|
8
|
+
@parametersToCheck = Array[
|
9
|
+
'iMid',
|
10
|
+
'payMethod',
|
11
|
+
'bankCd',
|
12
|
+
'goodsNm',
|
13
|
+
'description',
|
14
|
+
'referenceNo',
|
15
|
+
'cartData',
|
16
|
+
'amt',
|
17
|
+
'currency',
|
18
|
+
'billingNm',
|
19
|
+
'billingPhone',
|
20
|
+
'billingEmail',
|
21
|
+
'billingAddr',
|
22
|
+
'billingCity',
|
23
|
+
'billingState',
|
24
|
+
'billingPostCd',
|
25
|
+
'billingCountry',
|
26
|
+
'userIP',
|
27
|
+
'dbProcessUrl',
|
28
|
+
'callBackUrl',
|
29
|
+
'vat',
|
30
|
+
'fee',
|
31
|
+
'notaxAmt',
|
32
|
+
'merchantToken'
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
def parameters
|
37
|
+
@parameters
|
38
|
+
end
|
39
|
+
|
40
|
+
def parametersToCheck
|
41
|
+
@parametersToCheck
|
42
|
+
end
|
43
|
+
|
44
|
+
def errorMsg
|
45
|
+
@errorMsg = errorMsg
|
46
|
+
end
|
47
|
+
|
48
|
+
def checkParameters
|
49
|
+
@parametersToCheck.each do |param|
|
50
|
+
if @parameters[param] == nil
|
51
|
+
@errorMsg = "\nUndefined mandatory parameter `" + \
|
52
|
+
param + \
|
53
|
+
'` please set param using Nicepay.setRequestParam(\'' + \
|
54
|
+
param + \
|
55
|
+
'\', \''+ param +' value\')'
|
56
|
+
@checkParameters = false
|
57
|
+
break
|
58
|
+
else
|
59
|
+
@checkParameters = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
@checkParameters
|
63
|
+
end
|
64
|
+
|
65
|
+
def dumpParameters
|
66
|
+
@dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n"
|
67
|
+
@parameters.each do |key, value|
|
68
|
+
@dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n"
|
69
|
+
end
|
70
|
+
@dumpedParameters
|
71
|
+
end
|
72
|
+
|
73
|
+
def response
|
74
|
+
if self.checkParameters == true
|
75
|
+
with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do
|
76
|
+
@response = RestClient::Request.execute(
|
77
|
+
:method => :post,
|
78
|
+
:url => Nicepay::REQ_VA_URL,
|
79
|
+
:payload => @parameters,
|
80
|
+
:timeout => Nicepay.read_timeout,
|
81
|
+
:open_timeout => Nicepay.connection_timeout
|
82
|
+
)
|
83
|
+
end
|
84
|
+
@result = JSON.parse(@response)
|
85
|
+
else
|
86
|
+
puts @errorMsg
|
87
|
+
puts self.dumpParameters
|
88
|
+
abort('Exit')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class ChargeCard
|
94
|
+
def initialize(parameters)
|
95
|
+
@parameters = parameters
|
96
|
+
@parametersToCheck = Array[
|
97
|
+
'iMid',
|
98
|
+
'payMethod',
|
99
|
+
'instmntType',
|
100
|
+
'instmntMon',
|
101
|
+
'goodsNm',
|
102
|
+
'description',
|
103
|
+
'referenceNo',
|
104
|
+
'cartData',
|
105
|
+
'amt',
|
106
|
+
'currency',
|
107
|
+
'billingNm',
|
108
|
+
'billingPhone',
|
109
|
+
'billingEmail',
|
110
|
+
'billingAddr',
|
111
|
+
'billingCity',
|
112
|
+
'billingState',
|
113
|
+
'billingPostCd',
|
114
|
+
'billingCountry',
|
115
|
+
'userIP',
|
116
|
+
'dbProcessUrl',
|
117
|
+
'callBackUrl',
|
118
|
+
'vat',
|
119
|
+
'fee',
|
120
|
+
'notaxAmt',
|
121
|
+
'merchantToken'
|
122
|
+
]
|
123
|
+
end
|
124
|
+
|
125
|
+
def parameters
|
126
|
+
@parameters
|
127
|
+
end
|
128
|
+
|
129
|
+
def parametersToCheck
|
130
|
+
@parametersToCheck
|
131
|
+
end
|
132
|
+
|
133
|
+
def errorMsg
|
134
|
+
@errorMsg = errorMsg
|
135
|
+
end
|
136
|
+
|
137
|
+
def checkParameters
|
138
|
+
@parametersToCheck.each do |param|
|
139
|
+
if @parameters[param] == nil
|
140
|
+
@errorMsg = "\nUndefined mandatory parameter `" + \
|
141
|
+
param + \
|
142
|
+
'` please set param using Nicepay.setRequestParam(\'' + \
|
143
|
+
param + \
|
144
|
+
'\', \''+ param +' value\')'
|
145
|
+
@checkParameters = false
|
146
|
+
break
|
147
|
+
else
|
148
|
+
@checkParameters = true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
@checkParameters
|
152
|
+
end
|
153
|
+
|
154
|
+
def dumpParameters
|
155
|
+
@dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n"
|
156
|
+
@parameters.each do |key, value|
|
157
|
+
@dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n"
|
158
|
+
end
|
159
|
+
@dumpedParameters
|
160
|
+
end
|
161
|
+
|
162
|
+
def response
|
163
|
+
if self.checkParameters == true
|
164
|
+
with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do
|
165
|
+
@response = RestClient::Request.execute(
|
166
|
+
:method => :post,
|
167
|
+
:url => Nicepay::REQ_CC_URL,
|
168
|
+
:payload => @parameters,
|
169
|
+
:timeout => Nicepay.read_timeout,
|
170
|
+
:open_timeout => Nicepay.connection_timeout
|
171
|
+
)
|
172
|
+
end
|
173
|
+
@response[0..3]=''
|
174
|
+
@response = JSON.parse(@response)
|
175
|
+
@result = @response["data"]
|
176
|
+
else
|
177
|
+
puts @errorMsg
|
178
|
+
puts self.dumpParameters
|
179
|
+
abort('Exit')
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
class CheckStatus
|
187
|
+
def initialize(parameters)
|
188
|
+
@parameters = parameters
|
189
|
+
@parametersToCheck = Array[
|
190
|
+
'iMid',
|
191
|
+
'referenceNo',
|
192
|
+
'amt',
|
193
|
+
'tXid',
|
194
|
+
'merchantToken'
|
195
|
+
]
|
196
|
+
end
|
197
|
+
|
198
|
+
def parameters
|
199
|
+
@parameters
|
200
|
+
end
|
201
|
+
|
202
|
+
def parametersToCheck
|
203
|
+
@parametersToCheck
|
204
|
+
end
|
205
|
+
|
206
|
+
def errorMsg
|
207
|
+
@errorMsg = errorMsg
|
208
|
+
end
|
209
|
+
|
210
|
+
def checkParameters
|
211
|
+
@parametersToCheck.each do |param|
|
212
|
+
if @parameters[param] == nil
|
213
|
+
@errorMsg = "\nUndefined mandatory parameter `" + \
|
214
|
+
param + \
|
215
|
+
'` please set param using Nicepay.setRequestParam(\'' + \
|
216
|
+
param + \
|
217
|
+
'\', \''+ param +' value\')'
|
218
|
+
@checkParameters = false
|
219
|
+
break
|
220
|
+
else
|
221
|
+
@checkParameters = true
|
222
|
+
end
|
223
|
+
end
|
224
|
+
@checkParameters
|
225
|
+
end
|
226
|
+
|
227
|
+
def dumpParameters
|
228
|
+
@dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n"
|
229
|
+
@parameters.each do |key, value|
|
230
|
+
@dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n"
|
231
|
+
end
|
232
|
+
@dumpedParameters
|
233
|
+
end
|
234
|
+
|
235
|
+
def response
|
236
|
+
if self.checkParameters == true
|
237
|
+
with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do
|
238
|
+
@response = RestClient::Request.execute(
|
239
|
+
:method => :post,
|
240
|
+
:url => Nicepay::CHECK_STATUS_URL,
|
241
|
+
:payload => @parameters,
|
242
|
+
:timeout => Nicepay.read_timeout,
|
243
|
+
:open_timeout => Nicepay.connection_timeout
|
244
|
+
)
|
245
|
+
end
|
246
|
+
@response = JSON.parse(@response)
|
247
|
+
@result = @response
|
248
|
+
else
|
249
|
+
puts @errorMsg
|
250
|
+
puts self.dumpParameters
|
251
|
+
abort('Exit')
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
class CancelVa
|
257
|
+
def initialize(parameters)
|
258
|
+
@parameters = parameters
|
259
|
+
@parametersToCheck = Array[
|
260
|
+
'iMid',
|
261
|
+
'payMethod',
|
262
|
+
# 'referenceNo',
|
263
|
+
'amt',
|
264
|
+
'tXid',
|
265
|
+
'merchantToken',
|
266
|
+
'cancelType'
|
267
|
+
]
|
268
|
+
end
|
269
|
+
|
270
|
+
def parameters
|
271
|
+
@parameters
|
272
|
+
end
|
273
|
+
|
274
|
+
def parametersToCheck
|
275
|
+
@parametersToCheck
|
276
|
+
end
|
277
|
+
|
278
|
+
def errorMsg
|
279
|
+
@errorMsg = errorMsg
|
280
|
+
end
|
281
|
+
|
282
|
+
def checkParameters
|
283
|
+
@parametersToCheck.each do |param|
|
284
|
+
if @parameters[param] == nil
|
285
|
+
@errorMsg = "\nUndefined mandatory parameter `" + \
|
286
|
+
param + \
|
287
|
+
'` please set param using Nicepay.setRequestParam(\'' + \
|
288
|
+
param + \
|
289
|
+
'\', \''+ param +' value\')'
|
290
|
+
@checkParameters = false
|
291
|
+
break
|
292
|
+
else
|
293
|
+
@checkParameters = true
|
294
|
+
end
|
295
|
+
end
|
296
|
+
@checkParameters
|
297
|
+
end
|
298
|
+
|
299
|
+
def dumpParameters
|
300
|
+
@dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n"
|
301
|
+
@parameters.each do |key, value|
|
302
|
+
@dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n"
|
303
|
+
end
|
304
|
+
@dumpedParameters
|
305
|
+
end
|
306
|
+
|
307
|
+
def response
|
308
|
+
if self.checkParameters == true
|
309
|
+
with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do
|
310
|
+
@response = RestClient::Request.execute(
|
311
|
+
:method => :post,
|
312
|
+
:url => Nicepay::CANCEL_VA_URL,
|
313
|
+
:payload => @parameters,
|
314
|
+
:timeout => Nicepay.read_timeout,
|
315
|
+
:open_timeout => Nicepay.connection_timeout
|
316
|
+
)
|
317
|
+
end
|
318
|
+
@response = JSON.parse(@response)
|
319
|
+
@result = @response
|
320
|
+
else
|
321
|
+
puts @errorMsg
|
322
|
+
puts self.dumpParameters
|
323
|
+
abort('Exit')
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
end
|
data/lib/nicepay.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
=begin
|
2
|
+
Nicepay Ruby Bindings
|
3
|
+
Have a Nicepay!
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
7
|
+
require 'rest-client'
|
8
|
+
require 'json'
|
9
|
+
require 'digest'
|
10
|
+
require "retries"
|
11
|
+
require 'nicepay/api'
|
12
|
+
require 'nicepay/version'
|
13
|
+
|
14
|
+
module Nicepay
|
15
|
+
|
16
|
+
@i_mid = 'IONPAYTEST'
|
17
|
+
@merchant_key = '33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A=='
|
18
|
+
@callback_url = 'http://httpresponder.com/nicepay'
|
19
|
+
@db_process_url = 'http://httpresponder.com/nicepay'
|
20
|
+
@requestParam = Hash.new()
|
21
|
+
@cart = Hash.new {|h,k| h[k]=[]}
|
22
|
+
@item = Array.new()
|
23
|
+
@max_retry = 10
|
24
|
+
@connection_timeout = 20
|
25
|
+
@read_timeout = 20
|
26
|
+
|
27
|
+
#Static
|
28
|
+
REQ_VA_URL = 'https://www.nicepay.co.id/nicepay/api/onePass.do'
|
29
|
+
REQ_CC_URL = 'https://www.nicepay.co.id/nicepay/api/orderRegist.do'
|
30
|
+
CANCEL_VA_URL = 'https://www.nicepay.co.id/nicepay/api/onePassAllCancel.do'
|
31
|
+
CHECK_STATUS_URL = 'https://www.nicepay.co.id/nicepay/api/onePassStatus.do'
|
32
|
+
|
33
|
+
def self.callBackUrl
|
34
|
+
@callback_url
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.dbProcessUrl
|
38
|
+
@db_process_url
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.merchantKey
|
42
|
+
@merchant_key
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.iMid
|
46
|
+
@i_mid
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.max_retry
|
50
|
+
@max_retry
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.connection_timeout
|
54
|
+
@connection_timeout
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.read_timeout
|
58
|
+
@read_timeout
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.callBackUrl=(callback_url)
|
62
|
+
@callback_url = callback_url
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.dbProcessUrl=(db_process_url)
|
67
|
+
@db_process_url = db_process_url
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.merchantKey=(merchant_key)
|
72
|
+
@merchant_key = merchant_key
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.iMid=(i_mid)
|
77
|
+
@i_mid = i_mid
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.setRequestParam(paramName, paramValue)
|
82
|
+
self.requestParam[paramName] = paramValue
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.param(name)
|
87
|
+
self.requestParam[name]
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.requestParam
|
91
|
+
@requestParam
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.merchantToken
|
95
|
+
sha256 = Digest::SHA256.new
|
96
|
+
@merchantToken = sha256.hexdigest (self.iMid.to_s + \
|
97
|
+
self.param('referenceNo').to_s + \
|
98
|
+
self.param('amt').to_s + \
|
99
|
+
self.merchantKey.to_s)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.merchantTokenC
|
103
|
+
sha256 = Digest::SHA256.new
|
104
|
+
@merchantToken = sha256.hexdigest (self.iMid.to_s + \
|
105
|
+
self.param('tXid').to_s + \
|
106
|
+
self.param('amt').to_s + \
|
107
|
+
self.merchantKey.to_s)
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.addCart(image, name, detail, amt)
|
111
|
+
self.cart['item'] << { img_url: image , goods_name: name, goods_detail: detail, goods_amt: amt}
|
112
|
+
self.cart['count'] = self.cart['item'].count
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.cart
|
116
|
+
@cart
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.cartData
|
120
|
+
@cartData = self.cart.to_json
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.oneLiner(string)
|
124
|
+
@oneLiner= string.gsub(/\s+/, "")
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.flushParam
|
128
|
+
@requestParam = nil
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.dumpParameters
|
132
|
+
@dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n"
|
133
|
+
@requestParam.each do |key, value|
|
134
|
+
@dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n"
|
135
|
+
end
|
136
|
+
@dumpedParameters
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.autoCountTotal
|
140
|
+
items = self.cart['item']
|
141
|
+
total = 0
|
142
|
+
items.each do |key, value|
|
143
|
+
total += key[:goods_amt].to_i
|
144
|
+
end
|
145
|
+
@autoCountTotal = total
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.vaExpiryDate(day)
|
149
|
+
d = Date.today
|
150
|
+
@vaExpiryDate = (d + day).strftime("%Y%m%d")
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.vaExpiryTime
|
154
|
+
t = Time.now
|
155
|
+
@vaExpiryTime = t.strftime("%H%M%S")
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.userIp
|
159
|
+
# @userIP = request.remote_ip
|
160
|
+
@userIp = '127.0.0.1'
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
data/nicepay.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
5
|
+
require 'rest-client'
|
6
|
+
require 'json'
|
7
|
+
require 'digest'
|
8
|
+
require "retries"
|
9
|
+
require 'nicepay/api'
|
10
|
+
require 'nicepay/version'
|
11
|
+
|
12
|
+
Gem::Specification.new do |spec|
|
13
|
+
spec.name = "nicepay"
|
14
|
+
spec.version = Nicepay::VERSION
|
15
|
+
spec.authors = ["Arif Budiman"]
|
16
|
+
spec.email = ["arif.budiman@nicepay.co.id"]
|
17
|
+
|
18
|
+
spec.summary = 'Nicepay Ruby Bindings'
|
19
|
+
spec.description = 'Nicepay Indonesia'
|
20
|
+
spec.homepage = "http://nicepay.co.id."
|
21
|
+
spec.license = "MIT"
|
22
|
+
|
23
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
24
|
+
# delete this section to allow pushing this gem to any host.
|
25
|
+
# if spec.respond_to?(:metadata)
|
26
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
27
|
+
# else
|
28
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
29
|
+
# end
|
30
|
+
|
31
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
|
40
|
+
# dependencies
|
41
|
+
spec.add_dependency 'rest-client'
|
42
|
+
spec.add_dependency 'digest'
|
43
|
+
spec.add_dependency 'json'
|
44
|
+
spec.add_dependency 'retries'
|
45
|
+
spec.add_dependency 'rubygems' if RUBY_VERSION < '1.9'
|
46
|
+
|
47
|
+
end
|
data/test-cancel.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
Nicepay Ruby Bindings
|
4
|
+
Virtual Account Sample Code
|
5
|
+
Have a Nicepay!
|
6
|
+
=end
|
7
|
+
require_relative 'lib/nicepay'
|
8
|
+
|
9
|
+
# Configuration
|
10
|
+
# MID
|
11
|
+
Nicepay.iMid=('VACCTCLOSE')
|
12
|
+
# Merchant Key
|
13
|
+
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
|
14
|
+
|
15
|
+
# API Operation
|
16
|
+
cancelVa = Nicepay::Api::CancelVa.new(Nicepay.requestParam)
|
17
|
+
|
18
|
+
# Set Request Parameter for Virtual Account
|
19
|
+
|
20
|
+
# Merchant Id
|
21
|
+
Nicepay.setRequestParam('iMid', Nicepay.iMid)
|
22
|
+
|
23
|
+
# Bank Transfer -> payMethod = 02
|
24
|
+
Nicepay.setRequestParam('payMethod', '02')
|
25
|
+
|
26
|
+
# Total amount
|
27
|
+
Nicepay.setRequestParam('amt', 3000)
|
28
|
+
|
29
|
+
# Transaction id (tXid)
|
30
|
+
Nicepay.setRequestParam('tXid', 'VACCTCLOSE02201606071356095243')
|
31
|
+
|
32
|
+
# Cancelation type -> set 1
|
33
|
+
Nicepay.setRequestParam('cancelType', 1)
|
34
|
+
|
35
|
+
# Cancelation message
|
36
|
+
Nicepay.setRequestParam('cancelMsg', 'Order canceled, release VA number')
|
37
|
+
|
38
|
+
# Merchant Token
|
39
|
+
Nicepay.setRequestParam('merchantToken', Nicepay.merchantTokenC)
|
40
|
+
|
41
|
+
# If you want to dump POST parameters and review it
|
42
|
+
# puts Nicepay.dumpParameters
|
43
|
+
# abort("Exit")
|
44
|
+
|
45
|
+
# Inspect Response
|
46
|
+
# puts requestVa.response.inspect
|
47
|
+
|
48
|
+
response = cancelVa.response
|
49
|
+
|
50
|
+
# Inspect response
|
51
|
+
# puts response.inspect
|
52
|
+
|
53
|
+
# If success, show VA information to customer
|
54
|
+
if response["resultCd"].to_s == "0000"
|
55
|
+
puts "\n"
|
56
|
+
puts "----------------------------------------------------------------------"
|
57
|
+
puts "Transaction have been canceled\n\n"
|
58
|
+
puts "----------------------------------------------------------------------"
|
59
|
+
puts "Description : " + response["description"].to_s
|
60
|
+
puts "Amount : " + response["amount"].to_s
|
61
|
+
puts "Reference No : " + response["referenceNo"].to_s
|
62
|
+
puts "Transaction ID : " + response["tXid"].to_s
|
63
|
+
puts "----------------------------------------------------------------------"
|
64
|
+
|
65
|
+
elsif response["resultCd"].to_s == "9315"
|
66
|
+
puts "\n"
|
67
|
+
puts "----------------------------------------------------------------------"
|
68
|
+
puts "Transaction have been canceled\n\n"
|
69
|
+
puts "----------------------------------------------------------------------"
|
70
|
+
puts "Result Code : " + response["resultCd"]
|
71
|
+
puts "Result Message : " + response["resultMsg"]
|
72
|
+
puts "----------------------------------------------------------------------"
|
73
|
+
|
74
|
+
else
|
75
|
+
# If error, you can redirect back to checkout page
|
76
|
+
# In this sample, we only puts error message
|
77
|
+
puts "\nOops! Virtual Account can't be canceled. \nPlease try again later.\n\n"
|
78
|
+
puts "Result Code : " + response["resultCd"]
|
79
|
+
puts "Result Message : " + response["resultMsg"]
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
# Flush request parameter
|
84
|
+
Nicepay.flushParam
|
data/test-card.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
Nicepay Ruby Bindings
|
4
|
+
Virtual Account Sample Code
|
5
|
+
Have a Nicepay!
|
6
|
+
=end
|
7
|
+
require_relative 'lib/nicepay'
|
8
|
+
|
9
|
+
# Configuration
|
10
|
+
|
11
|
+
Nicepay.iMid=('IONPAYTEST')
|
12
|
+
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
|
13
|
+
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
|
14
|
+
Nicepay.callBackUrl=('http://www.example.com/')
|
15
|
+
|
16
|
+
# API Operation
|
17
|
+
chargeCard = Nicepay::Api::ChargeCard.new(Nicepay.requestParam)
|
18
|
+
|
19
|
+
# Set Request Parameter for Card Payment
|
20
|
+
|
21
|
+
# Merchant Id
|
22
|
+
Nicepay.setRequestParam('iMid', Nicepay.iMid)
|
23
|
+
|
24
|
+
# Card -> payMethod = 01
|
25
|
+
Nicepay.setRequestParam('payMethod', '01')
|
26
|
+
|
27
|
+
# No Installment - Do not use installment feature before get rights from bank
|
28
|
+
Nicepay.setRequestParam('instmntMon', '1')
|
29
|
+
Nicepay.setRequestParam('instmntType', '1')
|
30
|
+
|
31
|
+
# Reference Number / Order Number / Invoice Number, generated by merchant
|
32
|
+
Nicepay.setRequestParam('referenceNo','Invoice-7833')
|
33
|
+
|
34
|
+
# Transaction Description
|
35
|
+
Nicepay.setRequestParam('description','Payment of ' + Nicepay.param('referenceNo')) # Description
|
36
|
+
Nicepay.setRequestParam('goodsNm', Nicepay.param('description')) # goodsNm = Description
|
37
|
+
|
38
|
+
# Add cart information mandatory at least one cart data
|
39
|
+
# Nicepay.addCart('image_location','product_name','product_description', 'sub_total_amount')
|
40
|
+
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 3', 1000)
|
41
|
+
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 1', 2000)
|
42
|
+
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Discount', 'Jumlah: 50%', -1500)
|
43
|
+
# Set cartData as request parameter
|
44
|
+
Nicepay.setRequestParam('cartData', Nicepay.cartData)
|
45
|
+
# Total Amount -> auto count from cartData
|
46
|
+
Nicepay.setRequestParam('amt', Nicepay.autoCountTotal)
|
47
|
+
|
48
|
+
# Currency -> Indonesian Rupiah
|
49
|
+
Nicepay.setRequestParam('currency', 'IDR')
|
50
|
+
|
51
|
+
# Set customer information
|
52
|
+
Nicepay.setRequestParam('billingNm', 'John Doe')
|
53
|
+
Nicepay.setRequestParam('billingPhone', '02112341234')
|
54
|
+
Nicepay.setRequestParam('billingEmail', 'john.doe@example.com')
|
55
|
+
Nicepay.setRequestParam('billingAddr', 'Jl. Jend Sudirman')
|
56
|
+
Nicepay.setRequestParam('billingCity', 'Jakarta Pusat')
|
57
|
+
Nicepay.setRequestParam('billingState', 'DKI Jakarta')
|
58
|
+
Nicepay.setRequestParam('billingPostCd', '10210')
|
59
|
+
Nicepay.setRequestParam('billingCountry', 'Indonesia')
|
60
|
+
|
61
|
+
Nicepay.setRequestParam('deliveryNm', 'John Doe')
|
62
|
+
Nicepay.setRequestParam('deliveryPhone', '02112341234')
|
63
|
+
Nicepay.setRequestParam('deliveryEmail', 'john.doe@example.com')
|
64
|
+
Nicepay.setRequestParam('deliveryAddr', 'Jl. Jend Sudirman')
|
65
|
+
Nicepay.setRequestParam('deliveryCity', 'Jakarta Pusat')
|
66
|
+
Nicepay.setRequestParam('deliveryState', 'DKI Jakarta')
|
67
|
+
Nicepay.setRequestParam('deliveryPostCd', '10210')
|
68
|
+
Nicepay.setRequestParam('deliveryCountry', 'Indonesia')
|
69
|
+
|
70
|
+
# Set User Customer IP
|
71
|
+
Nicepay.setRequestParam('userIP', Nicepay.userIp)
|
72
|
+
|
73
|
+
# Set dbProcessUrl (Notification Handler / Web Hook URL)
|
74
|
+
Nicepay.setRequestParam('dbProcessUrl', Nicepay.dbProcessUrl)
|
75
|
+
|
76
|
+
# Set callbackUrl (Redirection page after payment URL)
|
77
|
+
Nicepay.setRequestParam('callBackUrl', Nicepay.callBackUrl)
|
78
|
+
|
79
|
+
# Set vat, fee & noTaxAmt -> reserved for future feature, only set 0 for now
|
80
|
+
Nicepay.setRequestParam('vat', 0)
|
81
|
+
Nicepay.setRequestParam('fee', 0)
|
82
|
+
Nicepay.setRequestParam('notaxAmt', 0)
|
83
|
+
|
84
|
+
# Merchant Token
|
85
|
+
Nicepay.setRequestParam('merchantToken', Nicepay.merchantToken)
|
86
|
+
|
87
|
+
# If you want to dump POST parameters and review it
|
88
|
+
# puts Nicepay.dumpParameters
|
89
|
+
# abort("Exit")
|
90
|
+
|
91
|
+
# Inspect Response
|
92
|
+
# puts chargeCard.response.inspect
|
93
|
+
|
94
|
+
response = chargeCard.response
|
95
|
+
|
96
|
+
# Inspect response
|
97
|
+
# puts response
|
98
|
+
|
99
|
+
# If success, redirect to payment page
|
100
|
+
if response["resultCd"].to_s == "0000"
|
101
|
+
puts "\n"
|
102
|
+
puts "-----------------------------------------------------------------------------------------------------"
|
103
|
+
puts "Redirect Customer to : " + response["requestURL"].to_s + "?tXid=" + response["tXid"].to_s
|
104
|
+
puts "tXid : " + response["tXid"].to_s # Save tXid in your database
|
105
|
+
puts "-----------------------------------------------------------------------------------------------------"
|
106
|
+
|
107
|
+
else
|
108
|
+
# If error, you can redirect back to checkout page
|
109
|
+
# In this sample, we only puts error message
|
110
|
+
puts "\nOops! Payment Page failed to generate! We have recorded the event. \nPlease try again later.\n\n"
|
111
|
+
puts "Result Code : " + response["resultCd"]
|
112
|
+
puts "Result Message : " + response["resultMsg"]
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
# Flush request parameter
|
117
|
+
Nicepay.flushParam
|
data/test-status.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
Nicepay Ruby Bindings
|
4
|
+
Virtual Account Sample Code
|
5
|
+
Have a Nicepay!
|
6
|
+
=end
|
7
|
+
require_relative 'lib/nicepay'
|
8
|
+
|
9
|
+
# Configuration
|
10
|
+
|
11
|
+
# MID
|
12
|
+
Nicepay.iMid=('VACCTCLOSE')
|
13
|
+
# Merchant Key
|
14
|
+
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
|
15
|
+
# Webhook/Notification Handler URL
|
16
|
+
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
|
17
|
+
# Redirection URL after customer made payment in Nicepay Payment Page
|
18
|
+
Nicepay.callBackUrl=('http://www.example.com/')
|
19
|
+
|
20
|
+
# API Operation
|
21
|
+
checkStatus = Nicepay::Api::CheckStatus.new(Nicepay.requestParam)
|
22
|
+
|
23
|
+
# Set Request Parameter for Check Status
|
24
|
+
|
25
|
+
# Merchant Id
|
26
|
+
Nicepay.setRequestParam('iMid', Nicepay.iMid)
|
27
|
+
|
28
|
+
# Reference Number / Order Number / Invoice Number, generated by merchant
|
29
|
+
Nicepay.setRequestParam('referenceNo','Invoice-7834')
|
30
|
+
|
31
|
+
# Total Amount
|
32
|
+
Nicepay.setRequestParam('amt', '3000')
|
33
|
+
|
34
|
+
# Set VA expiry date -> 2 days from now
|
35
|
+
Nicepay.setRequestParam('tXid', 'VACCTCLOSE02201606061354204825')
|
36
|
+
# You can also set like this
|
37
|
+
|
38
|
+
# Merchant Token
|
39
|
+
Nicepay.setRequestParam('merchantToken', Nicepay.merchantTokenC)
|
40
|
+
|
41
|
+
# If you want to dump POST parameters and review it
|
42
|
+
# puts Nicepay.dumpParameters
|
43
|
+
# abort("Exit")
|
44
|
+
|
45
|
+
# Inspect Response
|
46
|
+
# puts requestVa.response.inspect
|
47
|
+
|
48
|
+
response = checkStatus.response
|
49
|
+
|
50
|
+
# Inspect response
|
51
|
+
# puts response.inspect
|
52
|
+
|
53
|
+
=begin
|
54
|
+
**=========================================================================================================
|
55
|
+
** Credit Card
|
56
|
+
**=========================================================================================================
|
57
|
+
** $paymentStatus->status == 0 // Success
|
58
|
+
** $paymentStatus->status == 1 // Failed
|
59
|
+
** $paymentStatus->status == 2 // Void or Refund
|
60
|
+
** $paymentStatus->status == 9 // Initialization or Unpaid
|
61
|
+
**=========================================================================================================
|
62
|
+
*
|
63
|
+
**=========================================================================================================
|
64
|
+
** Virtual Account
|
65
|
+
**=========================================================================================================
|
66
|
+
** $paymentStatus->status == 0 // Paid
|
67
|
+
** $paymentStatus->status == 3 // Unpaid
|
68
|
+
** $paymentStatus->status == 4 // Expired
|
69
|
+
**=========================================================================================================
|
70
|
+
=end
|
71
|
+
# If success, show VA information to customer
|
72
|
+
if response["resultCd"].to_s == "0000"
|
73
|
+
puts "\n"
|
74
|
+
puts "----------------------------------------------------------------------"
|
75
|
+
puts "Transaction Status : " + response["status"].to_s
|
76
|
+
puts "Amount : " + response["amt"].to_s
|
77
|
+
puts "Reference No : " + response["referenceNo"].to_s
|
78
|
+
puts "Transaction ID : " + response["tXid"].to_s
|
79
|
+
puts "----------------------------------------------------------------------"
|
80
|
+
|
81
|
+
else
|
82
|
+
# If error, you can redirect back to checkout page
|
83
|
+
# In this sample, we only puts error message
|
84
|
+
puts "\nOops! Check Status failed to generate! We have recorded the event. \nPlease try again later.\n\n"
|
85
|
+
puts "Result Code : " + response["resultCd"]
|
86
|
+
puts "Result Message : " + response["resultMsg"]
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Flush request parameter
|
91
|
+
Nicepay.flushParam
|
data/test-va.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
Nicepay Ruby Bindings
|
4
|
+
Virtual Account Sample Code
|
5
|
+
Have a Nicepay!
|
6
|
+
=end
|
7
|
+
require_relative 'lib/nicepay'
|
8
|
+
|
9
|
+
# Configuration
|
10
|
+
|
11
|
+
# MID
|
12
|
+
Nicepay.iMid=('VACCTCLOSE')
|
13
|
+
# Merchant Key
|
14
|
+
Nicepay.merchantKey=('33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==')
|
15
|
+
# Webhook/Notification Handler URL
|
16
|
+
Nicepay.dbProcessUrl=('http://httpresponder.com/nicepay')
|
17
|
+
Nicepay.callBackUrl=('http://www.example.com/')
|
18
|
+
|
19
|
+
# API Operation
|
20
|
+
requestVa = Nicepay::Api::RequestVa.new(Nicepay.requestParam)
|
21
|
+
|
22
|
+
# Set Request Parameter for Virtual Account
|
23
|
+
|
24
|
+
# Merchant Id
|
25
|
+
Nicepay.setRequestParam('iMid', Nicepay.iMid)
|
26
|
+
|
27
|
+
# Bank Transfer -> payMethod = 02
|
28
|
+
Nicepay.setRequestParam('payMethod', '02')
|
29
|
+
|
30
|
+
# Set Bank
|
31
|
+
# BCA -> CENA
|
32
|
+
# BNI -> BNIN
|
33
|
+
# Mandiri -> BMRI
|
34
|
+
# Hana Bank -> HNBN
|
35
|
+
# Maybank -> IBBK
|
36
|
+
# Permata -> BBBA
|
37
|
+
Nicepay.setRequestParam('bankCd', 'CENA')
|
38
|
+
|
39
|
+
# Reference Number / Order Number / Invoice Number, generated by merchant
|
40
|
+
Nicepay.setRequestParam('referenceNo','Invoice-7834')
|
41
|
+
|
42
|
+
# Transaction Description
|
43
|
+
Nicepay.setRequestParam('description','Payment of ' + Nicepay.param('referenceNo')) # Description
|
44
|
+
Nicepay.setRequestParam('goodsNm', Nicepay.param('description')) # goodsNm = Description
|
45
|
+
|
46
|
+
# Add cart information mandatory at least one cart data
|
47
|
+
# Nicepay.addCart('image_location','product_name','product_description', 'sub_total_amount')
|
48
|
+
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 3', 1000)
|
49
|
+
Nicepay.addCart('https://www.nicepay.co.id/nicepay/images/cart.png', 'Glasses', 'Jumlah: 1', 2000)
|
50
|
+
|
51
|
+
# Set cartData as request parameter
|
52
|
+
Nicepay.setRequestParam('cartData', Nicepay.cartData)
|
53
|
+
|
54
|
+
# Amount -> auto count from cartData
|
55
|
+
Nicepay.setRequestParam('amt', Nicepay.autoCountTotal)
|
56
|
+
|
57
|
+
# Currency -> Indonesian Rupiah
|
58
|
+
Nicepay.setRequestParam('currency', 'IRD')
|
59
|
+
|
60
|
+
# Set customer information
|
61
|
+
Nicepay.setRequestParam('billingNm', 'John Doe')
|
62
|
+
Nicepay.setRequestParam('billingPhone', '02112341234')
|
63
|
+
Nicepay.setRequestParam('billingEmail', 'john.doe@example.com')
|
64
|
+
Nicepay.setRequestParam('billingAddr', 'Jl. Jend Sudirman')
|
65
|
+
Nicepay.setRequestParam('billingCity', 'Jakarta Pusat')
|
66
|
+
Nicepay.setRequestParam('billingState', 'DKI Jakarta')
|
67
|
+
Nicepay.setRequestParam('billingPostCd', '10210')
|
68
|
+
Nicepay.setRequestParam('billingCountry', 'Indonesia')
|
69
|
+
|
70
|
+
Nicepay.setRequestParam('deliveryNm', 'John Doe')
|
71
|
+
Nicepay.setRequestParam('deliveryPhone', '02112341234')
|
72
|
+
Nicepay.setRequestParam('deliveryEmail', 'john.doe@example.com')
|
73
|
+
Nicepay.setRequestParam('deliveryAddr', 'Jl. Jend Sudirman')
|
74
|
+
Nicepay.setRequestParam('deliveryCity', 'Jakarta Pusat')
|
75
|
+
Nicepay.setRequestParam('deliveryState', 'DKI Jakarta')
|
76
|
+
Nicepay.setRequestParam('deliveryPostCd', '10210')
|
77
|
+
Nicepay.setRequestParam('deliveryCountry', 'Indonesia')
|
78
|
+
|
79
|
+
# Set User Customer IP
|
80
|
+
Nicepay.setRequestParam('userIP', Nicepay.userIp)
|
81
|
+
|
82
|
+
# Set dbProcessUrl (Notification Handler / Web Hook URL)
|
83
|
+
Nicepay.setRequestParam('dbProcessUrl', Nicepay.dbProcessUrl)
|
84
|
+
|
85
|
+
# Set callbackUrl (Redirection page after payment URL)
|
86
|
+
Nicepay.setRequestParam('callBackUrl', Nicepay.callBackUrl)
|
87
|
+
|
88
|
+
# Set vat, fee & noTaxAmt -> reserved for future feature, only set 0 for now
|
89
|
+
Nicepay.setRequestParam('vat', 0)
|
90
|
+
Nicepay.setRequestParam('fee', 0)
|
91
|
+
Nicepay.setRequestParam('notaxAmt', 0)
|
92
|
+
|
93
|
+
# Set VA expiry date -> 2 days from now
|
94
|
+
Nicepay.setRequestParam('vacctValidDt', Nicepay.vaExpiryDate(2)) # format: %Y%m%d
|
95
|
+
# You can also set like this
|
96
|
+
# Nicepay.setRequestParam('vacctValidDt', '20160608') # format: %Y%m%d
|
97
|
+
|
98
|
+
# Set VA expiry time -> time as now
|
99
|
+
Nicepay.setRequestParam('vacctValidTm', Nicepay.vaExpiryTime) # format: %H%M%S
|
100
|
+
# You can also set like this
|
101
|
+
# Nicepay.setRequestParam('vacctValidTm', '095519') # format: %H%M%S
|
102
|
+
|
103
|
+
# Merchant Token
|
104
|
+
Nicepay.setRequestParam('merchantToken', Nicepay.merchantToken)
|
105
|
+
|
106
|
+
# If you want to dump POST parameters and review it
|
107
|
+
# puts Nicepay.dumpParameters
|
108
|
+
# abort("Exit")
|
109
|
+
|
110
|
+
# Inspect Response
|
111
|
+
# puts requestVa.response.inspect
|
112
|
+
|
113
|
+
response = requestVa.response
|
114
|
+
|
115
|
+
# Inspect response
|
116
|
+
# puts response.inspect
|
117
|
+
|
118
|
+
# If success, show and email VA information including customer journey to customer
|
119
|
+
|
120
|
+
if response["resultCd"].to_s == "0000"
|
121
|
+
puts "\n"
|
122
|
+
puts "----------------------------------------------------------------------"
|
123
|
+
puts "Virtual Account Number : " + response["bankVacctNo"].to_s
|
124
|
+
puts "Description : " + response["description"].to_s
|
125
|
+
puts "Reference No : " + response["referenceNo"].to_s
|
126
|
+
puts "Transaction ID : " + response["tXid"].to_s # Save tXid in your database
|
127
|
+
puts "----------------------------------------------------------------------"
|
128
|
+
|
129
|
+
else response["resultCd"].to_s
|
130
|
+
# If error, you can redirect back to checkout page
|
131
|
+
# In this sample, we only puts error message
|
132
|
+
puts "\nOops! Virtual Account failed to generate! We have recorded the event. \nPlease try again later.\n\n"
|
133
|
+
puts "Result Code : " + response["resultCd"]
|
134
|
+
puts "Result Message : " + response["resultMsg"]
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Flush request parameter
|
139
|
+
Nicepay.flushParam
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nicepay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arif Budiman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: digest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: retries
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Nicepay Indonesia
|
112
|
+
email:
|
113
|
+
- arif.budiman@nicepay.co.id
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/nicepay-console
|
127
|
+
- bin/setup
|
128
|
+
- lib/nicepay.rb
|
129
|
+
- lib/nicepay/api.rb
|
130
|
+
- lib/nicepay/version.rb
|
131
|
+
- nicepay.gemspec
|
132
|
+
- test-cancel.rb
|
133
|
+
- test-card.rb
|
134
|
+
- test-status.rb
|
135
|
+
- test-va.rb
|
136
|
+
homepage: http://nicepay.co.id.
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.5.1
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Nicepay Ruby Bindings
|
160
|
+
test_files: []
|