paygate-ruby 0.1.8 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,343 +1,327 @@
1
- # paygate-ruby
2
-
3
- `paygate-ruby` is a simple Ruby wrapper for [PayGate payment gateway](http://www.paygate.net/)'s OpenPayAPI.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'paygate-ruby'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install paygate-ruby
20
-
21
- ## Configuration
22
-
23
- You can pass a block to the `configure` method to make changes to the `Paygate` configuration.
24
-
25
- ```ruby
26
- Paygate.configure do |config|
27
- config.mode = :sandbox
28
- end
29
- ```
30
-
31
- Default value for `mode` is `:live`. It uses different API urls in different modes for making payments.
32
-
33
- ## Usage
34
-
35
- To start making the transactions on PayGate, you will need a Member ID and a Secret, for which you can register [here](https://admin.paygate.net/front/regist/registMember.jsp?lang=us).
36
-
37
- After a successful registration, you will have access to the [dashboard](https://admin.paygate.net/front/board/welcome.jsp).
38
-
39
- NOTE: Unless otherwise stated, all the following documentation is for making payments with Korean local credit cards in currency 'WON'.
40
-
41
- Contents:
42
- - [1 Purchase](#1-purchase)
43
- - [2 Verify](#2-verify)
44
- - [3 Refund](#3-refund)
45
- - [4 Profile Pay](#4-profile-pay)
46
- - [5 JavaScript helpers](#5-javascript-helpers)
47
-
48
- ### 1 Purchase
49
-
50
- #### 1.1 Include JavaScript
51
-
52
- Include the _OpenPayAPI.js_ in `<head>` of your payment page.
53
-
54
- ```slim
55
- = javascript_include_tag paygate_open_pay_api_js_url
56
- ```
57
-
58
- #### 1.2 Payment form
59
-
60
- Render the PayGate payment form in your view file.
61
-
62
- ```slim
63
- = paygate_open_pay_api_form
64
- ```
65
-
66
- You will see a form with all the necessary fields for making payment with a credit card. Some of the fields have default values set. You can also set the value and placeholder for almost all the fields while rendering the form. See example below:
67
-
68
- ```slim
69
- / payment.html.slim
70
- = paygate_open_pay_api_form(\
71
- mid: { value: 'testmid', placeholder: 'Merchant ID' },
72
- currency: { value: 'USD' },
73
- amount: { value: 2000 }\
74
- )
75
- ```
76
-
77
- Here is a list of all the form fields which you can set:
78
- - mid
79
- - locale (default: 'US')
80
- - charset (default: 'UTF-8')
81
- - title
82
- - currency (default: 'WON')
83
- - amount
84
- - meta1, meta2, meta3, meta4, meta5
85
- - pay_method (default: 'card')
86
- - customer_name
87
- - customer_email
88
- - card_number
89
- - expiry_year
90
- - expiry_month
91
- - cvv
92
-
93
- The form also contains some fields which are filled after the response is returned by the API. They are:
94
- - card_auth_code
95
- - response_code
96
- - response_message
97
- - tid
98
- - profile_no
99
- - hash_result
100
-
101
- Lets explore some of these fields more.
102
-
103
- **mid**
104
-
105
- You need to set your Member ID in this field.
106
-
107
- If you have setup separate Member IDs for Korean and International cards, you can fill the value of `mid` accordingly. To know whether the credit card number entered by a customer is Korean or not, you can check the first 6 digits of card number to match Korean BIN numbers. Full list is available as `Paygate::KOREA_BIN_NUMBERS`.
108
-
109
- **pay_method**
110
-
111
- Value of `pay_method` for Korean cards should be set to "card" and for international cards, it should be "104".
112
-
113
- **locale**
114
-
115
- Use `Paygate.mapped_locale` to get the locale in correct format for the form input.
116
-
117
- ```ruby
118
- Paygate.mapped_locale(:en)
119
- => 'US'
120
-
121
- Paygate.mapped_locale('ko')
122
- => 'KR'
123
- ```
124
-
125
- Valid inputs are "en", "en-US", "ko", "ko-KR", "ja", "zh-CN" and their symbolized versions. Passing `nil` would return default locale i.e. "US".
126
-
127
- **currency**
128
-
129
- Use `Paygate.mapped_currency` to get the currency in the correct format.
130
-
131
- ```ruby
132
- Paygate.mapped_currency('USD')
133
- => 'USD'
134
-
135
- Paygate.mapped_currency('KRW')
136
- => 'WON'
137
- ```
138
-
139
- Passing `nil` above would return default currency i.e. "WON".
140
-
141
- **amount**
142
-
143
- You need to contact PayGate to know the correct amount for making a successful transaction in test mode.
144
-
145
- Remember, in test mode too, PayGate makes real transactions and you need to `refund` them.
146
-
147
- **meta1, meta2, meta3, meta4, meta5**
148
-
149
- These fields can be used to pass any additional data to PayGate. If server-to-server callbacks are enabled, the gateway then sends all of these back when making a callback request to your server.
150
-
151
- **tid**
152
-
153
- For every transaction a `tid` is created by PayGate JS before making a request to the API.
154
-
155
- **response_code**
156
-
157
- This is filled automatically by PayGate JS when response is returned. A `response_code` of "0000" means successful transaction.
158
-
159
- **response_message**
160
-
161
- In case of failure, you can see the error message returned by the API here.
162
-
163
- **profile_no**
164
-
165
- If Profile Payment Service is enabled on your Member ID, then you will get a subscription ID for customer in this field. You can use this `profile_no` to make payments for the same customer in future.
166
-
167
- #### 1.3 Response screen
168
-
169
- You also need to add a screen at the same HTML level as above form. OpenPayAPI popups for further authentication as well as the response from the API is displayed in this screen.
170
-
171
- ```slim
172
- = paygate_open_pay_api_screen
173
- ```
174
-
175
- #### 1.4 JavaScript callback
176
-
177
- You also need to implement a few callbacks to handle the API response. Add these to your JavaScript.
178
-
179
- ```js
180
- // This is called when a response is returned from PayGate API
181
- function getPGIOresult() {
182
- displayStatus(getPGIOElement('ResultScreen'));
183
- verifyReceived(getPGIOElement('tid'), 'callbacksuccess', 'callbackfail');
184
- }
185
-
186
- // This is called when a response (success/failure) is returned from the API
187
- function callbacksuccess() {
188
- var replycode = getPGIOElement('replycode');
189
-
190
- if (replycode == '0000') {
191
- alert('Payment was successful');
192
- } else {
193
- alert('Payment failed with code: ' + replycode);
194
- }
195
- }
196
-
197
- // This is called when there is a system error
198
- function callbackfail() {
199
- alert('System error. Please try again.');
200
- }
201
- ```
202
-
203
- #### 1.5 Submit the form
204
-
205
- Now finally, lets add an event to make a call to OpenPayAPI on submit of the form. If you are using jQuery, you can do it as follows:
206
-
207
- ```js
208
- $('form[name="PGIOForm"]').on('submit', function(event){
209
- event.preventDefault();
210
- doTransaction(document.PGIOForm);
211
- })
212
- ```
213
-
214
- And, your payment form is all set to make payments.
215
-
216
- ### 2 Verify
217
-
218
- If enabled, PayGate will send a server-to-server callback on every successful transaction to the URL provided by you. The same request is sent every 5 minutes (for 10 days) until your server responds with success.
219
-
220
- This feature can be helpful if your JavaScript failed to receive the message from PayGate after a successful payment due to network issues.
221
-
222
- So, once you receive a successful JavaScript callback (`replycode == '0000'`), to prevent PayGate from sending any callback requests for that transaction (`tid`), you need to make a verification request as follows:
223
-
224
- ```ruby
225
- txn = Paygate::Transaction.new('testmid_123456.654321')
226
- response = txn.verify
227
- => #<Paygate::Response:0x007fd4898f14b0 ... >
228
-
229
- response.transaction_type
230
- => :verify
231
-
232
- response.http_code
233
- => "200"
234
- ```
235
-
236
- Here, _testmid_123456.654321_ is `tid` of the transaction you want to verify.
237
-
238
- ### 3 Refund
239
-
240
- Initialize a `Paygate::Member` instance using the Member ID and Secret you have.
241
-
242
- ```ruby
243
- member = Paygate::Member.new('testmid', 'secret')
244
- => #<Paygate::Member:0x007f96bdb70f38 @mid="testmid", @secret="secret">
245
- ```
246
-
247
- `member` responds to methods `mid`, and `secret`.
248
-
249
- ```ruby
250
- member.mid
251
- => "testmid"
252
-
253
- member.secret
254
- => "secret"
255
- ```
256
-
257
- #### 3.1 Full refund
258
-
259
- ```ruby
260
- response = member.refund_transaction('testmid_123456.654321')
261
- => #<Paygate::Response:0x007fbf3d111940 @transaction_type=:refund, @http_code="200", @message="OK", @body="callback({\"replyCode\":\"0000\",\"replyMessage\":\"Response has been completed\",\"content\":{\"object\":\"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000\"}})", @json={"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}, @raw_info=
262
- #<OpenStruct tid="testmid_123456.654321", tid_enc="AES256XQIdNnkzFwMQmhF7fuJhS3m0\n", request_url="https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F">>
263
- ```
264
-
265
- `response` provides some helpful accessor methods too.
266
-
267
- ```ruby
268
- response.transaction_type
269
- => :refund
270
-
271
- response.http_code
272
- => "200"
273
-
274
- response.json
275
- => {"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}
276
-
277
- response.raw_info
278
- => #<OpenStruct tid="testmid_123456.654321", tid_enc="AES256XQIdNnkzFwMQmhF7fuJhS3m0\n", request_url="https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F">
279
-
280
- response.raw_info.request_url
281
- => "https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F"
282
- ```
283
-
284
- Apart from these it also responds to `message` and `body`.
285
-
286
- #### 3.2 Partial refund
287
-
288
- For partial refunds, you need to pass `amount` as an option to `refund_transaction` method along with other options.
289
-
290
- ```ruby
291
- response = member.refund_transaction('testmid_123456.654321',
292
- amount: 1000,
293
- order_id: 'ord10001')
294
- ```
295
-
296
- ### 4 Profile Pay
297
-
298
- You can use the `profile_no` returned from the OpenPayAPI after first payment by a customer to make future payments for him.
299
-
300
- ```ruby
301
- response = member.profile_pay('profile_1234567890', 'WON', 1000)
302
-
303
- response.transaction_type
304
- => :profile_pay
305
-
306
- response.http_code
307
- => "200"
308
-
309
- response.json
310
- => {"validecode"=>"00", "authcode"=>"12345678", "authdt"=>"20171120165728", "cardname"=>"BC \x00\x00\x00\x00", "cardnumber"=>"411111**********", "cardtype"=>"301310", "cardquota"=>"00", "cardexpiremonth"=>"11", "cardexpireyear"=>"2020", "merchantno"=>"12345678", "m_tid"=>nil, "paymethodname"=>"CARD_BASIC", "ReplyMsg"=>"\xBA\xBA\xBC\xBD\xC1\xC2\xC3\xC4 OK: 12345678", "ReplyCode"=>"0000", "receipttoname"=>"Test name\xC1\xD1\xB1\xB1\xC1\xA1", "receipttoemail"=>"dev@paygate.net", "subtotalprice"=>"1000", "transactionid"=>"testmid_123456.654321", "hashresult"=>"db1fdc6789cc8d088172b79ca680b3af8711e9fb32", "mb_serial_no"=>"\r\n"}
311
- ```
312
-
313
- ### 5 JavaScript helpers
314
-
315
- `paygate-ruby` also provides a JavaScript class `Paygate` with some helper functions that can be used in your JavaScript e.g.
316
-
317
- - _openPayApiForm_ - Returns the payment form
318
- - _openPayApiScreen_ - Returns the screen for paygate API response
319
- - _findInputByName_ - Find an input field in payment form by name. Pass the _camelCased_ form of field names from section 1.2 above as arguments.
320
- - _responseCode_
321
- - _responseMessage_
322
- - _tid_
323
- - _profileNo_
324
- - _fillInput_ - Accepts input name (_camelCased_) and a value to set
325
- - _submitForm_ - Makes a call to PayGate API with the payment form inputs
326
-
327
- ## Development
328
-
329
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
330
-
331
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
332
-
333
- ## Contributing
334
-
335
- Bug reports and pull requests are welcome on GitHub at https://github.com/jagdeepsingh/paygate-ruby. 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.
336
-
337
- ## License
338
-
339
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
340
-
341
- ## Code of Conduct
342
-
343
- Everyone interacting in the Paygate project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jagdeepsingh/paygate-ruby/blob/master/CODE_OF_CONDUCT.md).
1
+ # paygate-ruby
2
+
3
+ `paygate-ruby` is a simple Ruby wrapper for [PayGate Korean payment gateway](http://www.paygate.net/)'s OpenPayAPI.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'paygate-ruby'
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ You can pass a block to the `configure` method to make changes to the `Paygate` configuration.
16
+
17
+ ```ruby
18
+ Paygate.configure do |config|
19
+ config.mode = :sandbox
20
+ end
21
+ ```
22
+
23
+ Default value for `mode` is `:live`. It uses different API urls in different modes for making payments.
24
+
25
+ ## Usage
26
+
27
+ To start making the transactions on PayGate, you will need a Member ID and a Secret,
28
+ for which you can register [here](https://admin.paygate.net/front/regist/registMember.jsp?lang=us).
29
+
30
+ After a successful registration, you will have access to the [dashboard](https://admin.paygate.net/front/board/welcome.jsp).
31
+
32
+ NOTE: Unless otherwise stated, all the following documentation is for making payments
33
+ with Korean local credit cards in currency 'WON'.
34
+
35
+ Contents:
36
+ - [1. Purchase](#1-purchase)
37
+ - [2. Verify](#2-verify)
38
+ - [3. Refund](#3-refund)
39
+ - [4. Profile Pay](#4-profile-pay)
40
+ - [5. JavaScript helpers](#5-javascript-helpers)
41
+
42
+ ### 1. Purchase
43
+
44
+ #### 1.1. Include JavaScript
45
+
46
+ Include the _OpenPayAPI.js_ in `<head>` of your payment page.
47
+
48
+ ```slim
49
+ = javascript_include_tag paygate_open_pay_api_js_url
50
+ ```
51
+
52
+ #### 1.2 Payment form
53
+
54
+ Render the PayGate payment form in your view file.
55
+
56
+ ```slim
57
+ = paygate_open_pay_api_form
58
+ ```
59
+
60
+ You will see a form with all the necessary fields for making payment with a credit card. Some of the fields have default values set. You can also set the value and placeholder for almost all the fields while rendering the form. See example below:
61
+
62
+ ```slim
63
+ / payment.html.slim
64
+ = paygate_open_pay_api_form(\
65
+ mid: { value: 'testmid', placeholder: 'Merchant ID' },
66
+ currency: { value: 'USD' },
67
+ amount: { value: 2000 }\
68
+ )
69
+ ```
70
+
71
+ Here is a list of all the form fields which you can set:
72
+ - mid
73
+ - locale (default: 'US')
74
+ - charset (default: 'UTF-8')
75
+ - title
76
+ - currency (default: 'WON')
77
+ - amount
78
+ - meta1, meta2, meta3, meta4, meta5
79
+ - pay_method (default: 'card')
80
+ - customer_name
81
+ - customer_email
82
+ - card_number
83
+ - expiry_year
84
+ - expiry_month
85
+ - cvv
86
+
87
+ The form also contains some fields which are filled after the response is returned by the API. They are:
88
+ - card_auth_code
89
+ - response_code
90
+ - response_message
91
+ - tid
92
+ - profile_no
93
+ - hash_result
94
+
95
+ Lets explore some of these fields more.
96
+
97
+ **mid**
98
+
99
+ You need to set your Member ID in this field.
100
+
101
+ If you have setup separate Member IDs for Korean and International cards, you can fill the value of `mid` accordingly. To know whether the credit card number entered by a customer is Korean or not, you can check the first 6 digits of card number to match Korean BIN numbers. Full list is available as `Paygate::KOREA_BIN_NUMBERS`.
102
+
103
+ **pay_method**
104
+
105
+ Value of `pay_method` for Korean cards should be set to "card" and for international cards, it should be "104".
106
+
107
+ **locale**
108
+
109
+ Use `Paygate.mapped_locale` to get the locale in correct format for the form input.
110
+
111
+ ```ruby
112
+ Paygate.mapped_locale(:en)
113
+ #=> 'US'
114
+
115
+ Paygate.mapped_locale('ko')
116
+ #=> 'KR'
117
+ ```
118
+
119
+ Valid inputs are "en", "en-US", "ko", "ko-KR", "ja", "zh-CN" and their symbolized versions. Passing `nil` would return default locale i.e. "US".
120
+
121
+ **currency**
122
+
123
+ Use `Paygate.mapped_currency` to get the currency in the correct format.
124
+
125
+ ```ruby
126
+ Paygate.mapped_currency('USD')
127
+ #=> 'USD'
128
+
129
+ Paygate.mapped_currency('KRW')
130
+ #=> 'WON'
131
+ ```
132
+
133
+ Passing `nil` above would return default currency i.e. "WON".
134
+
135
+ **amount**
136
+
137
+ You need to contact PayGate to know the correct amount for making a successful transaction in test mode.
138
+
139
+ Remember, in test mode too, PayGate makes real transactions and you need to `refund` them.
140
+
141
+ **meta1, meta2, meta3, meta4, meta5**
142
+
143
+ These fields can be used to pass any additional data to PayGate. If server-to-server callbacks are enabled, the gateway then sends all of these back when making a callback request to your server.
144
+
145
+ **tid**
146
+
147
+ For every transaction a `tid` is created by PayGate JS before making a request to the API.
148
+
149
+ **response_code**
150
+
151
+ This is filled automatically by PayGate JS when response is returned. A `response_code` of "0000" means successful transaction.
152
+
153
+ **response_message**
154
+
155
+ In case of failure, you can see the error message returned by the API here.
156
+
157
+ **profile_no**
158
+
159
+ If Profile Payment Service is enabled on your Member ID, then you will get a subscription ID for customer in this field. You can use this `profile_no` to make payments for the same customer in future.
160
+
161
+ #### 1.3. Response screen
162
+
163
+ You also need to add a screen at the same HTML level as above form. OpenPayAPI popups for further authentication as well as the response from the API is displayed in this screen.
164
+
165
+ ```slim
166
+ = paygate_open_pay_api_screen
167
+ ```
168
+
169
+ #### 1.4. JavaScript callback
170
+
171
+ You also need to implement a few callbacks to handle the API response. Add these to your JavaScript.
172
+
173
+ ```js
174
+ // This is called when a response is returned from PayGate API
175
+ function getPGIOresult() {
176
+ displayStatus(getPGIOElement('ResultScreen'));
177
+ verifyReceived(getPGIOElement('tid'), 'callbacksuccess', 'callbackfail');
178
+ }
179
+
180
+ // This is called when a response (success/failure) is returned from the API
181
+ function callbacksuccess() {
182
+ var replycode = getPGIOElement('replycode');
183
+
184
+ if (replycode == '0000') {
185
+ alert('Payment was successful');
186
+ } else {
187
+ alert('Payment failed with code: ' + replycode);
188
+ }
189
+ }
190
+
191
+ // This is called when there is a system error
192
+ function callbackfail() {
193
+ alert('System error. Please try again.');
194
+ }
195
+ ```
196
+
197
+ #### 1.5. Submit the form
198
+
199
+ Now finally, lets add an event to make a call to OpenPayAPI on submit of the form. If you are using jQuery, you can do it as follows:
200
+
201
+ ```js
202
+ $('form[name="PGIOForm"]').on('submit', function(event){
203
+ event.preventDefault();
204
+ doTransaction(document.PGIOForm);
205
+ })
206
+ ```
207
+
208
+ And, your payment form is all set to make payments.
209
+
210
+ ### 2. Verify
211
+
212
+ If enabled, PayGate will send a server-to-server callback on every successful transaction to the URL provided by you. The same request is sent every 5 minutes (for 10 days) until your server responds with success.
213
+
214
+ This feature can be helpful if your JavaScript failed to receive the message from PayGate after a successful payment due to network issues.
215
+
216
+ So, once you receive a successful JavaScript callback (`replycode == '0000'`), to prevent PayGate from sending any callback requests for that transaction (`tid`), you need to make a verification request as follows:
217
+
218
+ ```ruby
219
+ txn = Paygate::Transaction.new('testmid_123456.654321')
220
+ response = txn.verify
221
+ #=> #<Paygate::Response:0x007fd4898f14b0 ... >
222
+
223
+ response.transaction_type
224
+ #=> :verify
225
+
226
+ response.http_code
227
+ #=> "200"
228
+ ```
229
+
230
+ Here, _testmid_123456.654321_ is `tid` of the transaction you want to verify.
231
+
232
+ ### 3. Refund
233
+
234
+ Initialize a `Paygate::Member` instance using the Member ID and Secret you have.
235
+
236
+ ```ruby
237
+ member = Paygate::Member.new('testmid', 'secret')
238
+ #=> #<Paygate::Member:0x007f96bdb70f38 @mid="testmid", @secret="secret">
239
+ ```
240
+
241
+ `member` responds to methods `mid`, and `secret`.
242
+
243
+ ```ruby
244
+ member.mid
245
+ #=> "testmid"
246
+
247
+ member.secret
248
+ #=> "secret"
249
+ ```
250
+
251
+ #### 3.1. Full refund
252
+
253
+ ```ruby
254
+ response = member.refund_transaction('testmid_123456.654321')
255
+ #=> #<Paygate::Response:0x007fbf3d111940 @transaction_type=:refund, @http_code="200", @message="OK", @body="callback({\"replyCode\":\"0000\",\"replyMessage\":\"Response has been completed\",\"content\":{\"object\":\"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000\"}})", @json={"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}, @raw_info=
256
+ #<OpenStruct tid="testmid_123456.654321", tid_enc="AES256XQIdNnkzFwMQmhF7fuJhS3m0\n", request_url="https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F">>
257
+ ```
258
+
259
+ `response` provides some helpful accessor methods too.
260
+
261
+ ```ruby
262
+ response.transaction_type
263
+ #=> :refund
264
+
265
+ response.http_code
266
+ #=> "200"
267
+
268
+ response.json
269
+ #=> {"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}
270
+
271
+ response.raw_info
272
+ #=> #<OpenStruct tid="testmid_123456.654321", tid_enc="AES256XQIdNnkzFwMQmhF7fuJhS3m0\n", request_url="https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F">
273
+
274
+ response.raw_info.request_url
275
+ #=> "https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F"
276
+ ```
277
+
278
+ Apart from these it also responds to `message` and `body`.
279
+
280
+ #### 3.2. Partial refund
281
+
282
+ For partial refunds, you need to pass `amount` as an option to `refund_transaction` method along with other options.
283
+
284
+ ```ruby
285
+ response = member.refund_transaction('testmid_123456.654321',
286
+ amount: 1000,
287
+ order_id: 'ord10001')
288
+ ```
289
+
290
+ ### 4. Profile Pay
291
+
292
+ You can use the `profile_no` returned from the OpenPayAPI after first payment by a customer to make future payments for him.
293
+
294
+ ```ruby
295
+ response = member.profile_pay('profile_1234567890', 'WON', 1000)
296
+
297
+ response.transaction_type
298
+ #=> :profile_pay
299
+
300
+ response.http_code
301
+ #=> "200"
302
+
303
+ response.json
304
+ #=> {"validecode"=>"00", "authcode"=>"12345678", "authdt"=>"20171120165728", "cardname"=>"BC \x00\x00\x00\x00", "cardnumber"=>"411111**********", "cardtype"=>"301310", "cardquota"=>"00", "cardexpiremonth"=>"11", "cardexpireyear"=>"2020", "merchantno"=>"12345678", "m_tid"=>nil, "paymethodname"=>"CARD_BASIC", "ReplyMsg"=>"\xBA\xBA\xBC\xBD\xC1\xC2\xC3\xC4 OK: 12345678", "ReplyCode"=>"0000", "receipttoname"=>"Test name\xC1\xD1\xB1\xB1\xC1\xA1", "receipttoemail"=>"dev@paygate.net", "subtotalprice"=>"1000", "transactionid"=>"testmid_123456.654321", "hashresult"=>"db1fdc6789cc8d088172b79ca680b3af8711e9fb32", "mb_serial_no"=>"\r\n"}
305
+ ```
306
+
307
+ ### 5. JavaScript helpers
308
+
309
+ `paygate-ruby` also provides a JavaScript class `Paygate` with some helper functions that can be used in your JavaScript e.g.
310
+
311
+ - _openPayApiForm_ - Returns the payment form
312
+ - _openPayApiScreen_ - Returns the screen for paygate API response
313
+ - _findInputByName_ - Find an input field in payment form by name. Pass the _camelCased_ form of field names from section 1.2 above as arguments.
314
+ - _responseCode_
315
+ - _responseMessage_
316
+ - _tid_
317
+ - _profileNo_
318
+ - _fillInput_ - Accepts input name (_camelCased_) and a value to set
319
+ - _submitForm_ - Makes a call to PayGate API with the payment form inputs
320
+
321
+ ## Contributing
322
+
323
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tablecheck/paygate-ruby.
324
+
325
+ ## License
326
+
327
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).