paygate-ruby 0.1.6 → 0.1.11

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.
@@ -1,80 +1,155 @@
1
- module Paygate
2
- module FormHelper
3
- def paygate_open_pay_api_js_url
4
- (Paygate.configuration.mode == :live) ?
5
- 'https://api.paygate.net/ajax/common/OpenPayAPI.js'.freeze :
6
- 'https://stgapi.paygate.net/ajax/common/OpenPayAPI.js'.freeze
7
- end
8
-
9
- def paygate_open_pay_api_form(options = {})
10
- form_tag({}, name: 'PGIOForm') do
11
- fields = []
12
-
13
- fields << text_field_tag(:mid, options[:mid].try(:[], :value),
14
- placeholder: options[:mid].try(:[], :placeholder) || 'Member ID').html_safe
15
-
16
- fields << text_field_tag(:locale, options[:locale].try(:[], :value) || 'KR',
17
- name: 'langcode', placeholder: options[:locale].try(:[], :placeholder) || 'Language').html_safe
18
-
19
- fields << text_field_tag(:charset, options[:charset].try(:[], :value) || 'UTF-8',
20
- placeholder: options[:charset].try(:[], :placeholder) || 'Charset').html_safe
21
-
22
- fields << text_field_tag(:title, options[:title].try(:[], :value),
23
- name: 'goodname', placeholder: options[:title].try(:[], :placeholder) || 'Title').html_safe
24
-
25
- fields << text_field_tag(:currency, options[:currency].try(:[], :value) || 'WON',
26
- name: 'goodcurrency', placeholder: options[:currency].try(:[], :placeholder) || 'Currency').html_safe
27
-
28
- fields << text_field_tag(:amount, options[:amount].try(:[], :value),
29
- name: 'unitprice', placeholder: options[:amount].try(:[], :placeholder) || 'Amount').html_safe
30
-
31
- fields << text_field_tag(:pay_method, options[:pay_method].try(:[], :value) || 'card',
32
- name: 'paymethod', placeholder: options[:pay_method].try(:[], :placeholder) || 'Pay Method').html_safe
33
-
34
- fields << text_field_tag(:customer_name, options[:customer_name].try(:[], :value),
35
- name: 'receipttoname', placeholder: options[:customer_name].try(:[], :placeholder) || 'Customer Name').html_safe
36
-
37
- fields << text_field_tag(:customer_email, options[:customer_email].try(:[], :value),
38
- name: 'receipttoemail', placeholder: options[:customer_email].try(:[], :placeholder) || 'Customer Email').html_safe
39
-
40
- fields << text_field_tag(:card_number, options[:card_number].try(:[], :value),
41
- name: 'cardnumber', placeholder: options[:card_number].try(:[], :placeholder) || 'Card Number').html_safe
42
-
43
- fields << text_field_tag(:expiry_year, options[:expiry_year].try(:[], :value),
44
- name: 'cardexpireyear', placeholder: options[:expiry_year].try(:[], :placeholder) || 'Expiry Year').html_safe
45
-
46
- fields << text_field_tag(:expiry_month, options[:expiry_month].try(:[], :value),
47
- name: 'cardexpiremonth', placeholder: options[:expiry_month].try(:[], :placeholder) || 'Expiry Month').html_safe
48
-
49
- fields << text_field_tag(:cvv, options[:cvv].try(:[], :value),
50
- name: 'cardsecretnumber', placeholder: options[:cvv].try(:[], :placeholder) || 'CVV').html_safe
51
-
52
- fields << text_field_tag(:card_auth_code, nil,
53
- name: 'cardauthcode', placeholder: options[:card_auth_code].try(:[], :placeholder) || 'Card Auth Code').html_safe
54
-
55
- fields << text_field_tag(:response_code, nil,
56
- name: 'replycode', placeholder: options[:response_code].try(:[], :placeholder) || 'Response Code').html_safe
57
-
58
- fields << text_field_tag(:response_message, nil,
59
- name: 'replyMsg', placeholder: options[:response_message].try(:[], :placeholder) || 'Response Message').html_safe
60
-
61
- fields << text_field_tag(:tid, nil,
62
- placeholder: options[:tid].try(:[], :placeholder) || 'TID').html_safe
63
-
64
- fields << text_field_tag(:profile_no, nil,
65
- placeholder: options[:profile_no].try(:[], :placeholder) || 'Profile No').html_safe
66
-
67
- fields << text_field_tag(:hash_result, nil,
68
- name: 'hashresult', placeholder: options[:hash_result].try(:[], :placeholder) || 'Hash Result').html_safe
69
-
70
- fields.join.html_safe
71
- end.html_safe
72
- end
73
-
74
- def paygate_open_pay_api_screen
75
- content_tag(:div, nil, id: 'PGIOscreen')
76
- end
77
- end
78
- end
79
-
80
- ActionView::Base.send :include, Paygate::FormHelper
1
+ module Paygate
2
+ module FormHelper
3
+ FORM_TEXT_FIELDS = {
4
+ mid: {
5
+ placeholder: 'Member ID'
6
+ },
7
+
8
+ locale: {
9
+ name: 'langcode',
10
+ default: 'KR',
11
+ placeholder: 'Language'
12
+ },
13
+
14
+ charset: {
15
+ default: 'UTF-8',
16
+ placeholder: 'Charset'
17
+ },
18
+
19
+ title: {
20
+ name: 'goodname',
21
+ placeholder: 'Title'
22
+ },
23
+
24
+ currency: {
25
+ name: 'goodcurrency',
26
+ default: 'WON',
27
+ placeholder: 'Currency'
28
+ },
29
+
30
+ amount: {
31
+ name: 'unitprice',
32
+ placeholder: 'Amount'
33
+ },
34
+
35
+ meta1: {
36
+ name: 'goodoption1',
37
+ placeholder: 'Good Option 1'
38
+ },
39
+
40
+ meta2: {
41
+ name: 'goodoption2',
42
+ placeholder: 'Good Option 2'
43
+ },
44
+
45
+ meta3: {
46
+ name: 'goodoption3',
47
+ placeholder: 'Good Option 3'
48
+ },
49
+
50
+ meta4: {
51
+ name: 'goodoption4',
52
+ placeholder: 'Good Option 4'
53
+ },
54
+
55
+ meta5: {
56
+ name: 'goodoption5',
57
+ placeholder: 'Good Option 5'
58
+ },
59
+
60
+ pay_method: {
61
+ name: 'paymethod',
62
+ default: 'card',
63
+ placeholder: 'Pay Method'
64
+ },
65
+
66
+ customer_name: {
67
+ name: 'receipttoname',
68
+ placeholder: 'Customer Name'
69
+ },
70
+
71
+ customer_email: {
72
+ name: 'receipttoemail',
73
+ placeholder: 'Customer Email'
74
+ },
75
+
76
+ card_number: {
77
+ name: 'cardnumber',
78
+ placeholder: 'Card Number'
79
+ },
80
+
81
+ expiry_year: {
82
+ name: 'cardexpireyear',
83
+ placeholder: 'Expiry Year'
84
+ },
85
+
86
+ expiry_month: {
87
+ name: 'cardexpiremonth',
88
+ placeholder: 'Expiry Month'
89
+ },
90
+
91
+ cvv: {
92
+ name: 'cardsecretnumber',
93
+ placeholder: 'CVV'
94
+ },
95
+
96
+ card_auth_code: {
97
+ name: 'cardauthcode',
98
+ placeholder: 'Card Auth Code'
99
+ },
100
+
101
+ response_code: {
102
+ name: 'replycode',
103
+ placeholder: 'Response Code'
104
+ },
105
+
106
+ response_message: {
107
+ name: 'replyMsg',
108
+ placeholder: 'Response Message'
109
+ },
110
+
111
+ tid: {
112
+ placeholder: 'TID'
113
+ },
114
+
115
+ profile_no: {
116
+ placeholder: 'Profile No'
117
+ },
118
+
119
+ hash_result: {
120
+ name: 'hashresult',
121
+ placeholder: 'Hash Result'
122
+ }
123
+ }
124
+
125
+ def paygate_open_pay_api_js_url
126
+ (Paygate.configuration.mode == :live) ?
127
+ 'https://api.paygate.net/ajax/common/OpenPayAPI.js'.freeze :
128
+ 'https://stgapi.paygate.net/ajax/common/OpenPayAPI.js'.freeze
129
+ end
130
+
131
+ def paygate_open_pay_api_form(options = {})
132
+ form_tag({}, name: 'PGIOForm') do
133
+ fields = []
134
+
135
+ FORM_TEXT_FIELDS.each do |key, opts|
136
+ arg_opts = options[key] || {}
137
+ fields << text_field_tag(
138
+ key,
139
+ arg_opts[:value] || opts[:default],
140
+ name: opts[:name] || key.to_s,
141
+ placeholder: arg_opts[:placeholder] || opts[:placeholder]
142
+ ).html_safe
143
+ end
144
+
145
+ fields.join.html_safe
146
+ end.html_safe
147
+ end
148
+
149
+ def paygate_open_pay_api_screen
150
+ content_tag(:div, nil, id: 'PGIOscreen')
151
+ end
152
+ end
153
+ end
154
+
155
+ ActionView::Base.send :include, Paygate::FormHelper
@@ -1,21 +1,21 @@
1
- module Paygate
2
- class Member
3
- attr_reader :mid, :secret
4
-
5
- def initialize(mid, secret)
6
- @mid, @secret = mid, secret
7
- end
8
-
9
- def refund_transaction(txn_id, options = {})
10
- txn = Transaction.new(txn_id)
11
- txn.member = self
12
- txn.refund(options)
13
- end
14
-
15
- def profile_pay(profile_no, currency, amount)
16
- profile = Profile.new(profile_no)
17
- profile.member = self
18
- profile.purchase(currency, amount)
19
- end
20
- end
21
- end
1
+ module Paygate
2
+ class Member
3
+ attr_reader :mid, :secret
4
+
5
+ def initialize(mid, secret)
6
+ @mid, @secret = mid, secret
7
+ end
8
+
9
+ def refund_transaction(txn_id, options = {})
10
+ txn = Transaction.new(txn_id)
11
+ txn.member = self
12
+ txn.refund(options)
13
+ end
14
+
15
+ def profile_pay(profile_no, currency, amount)
16
+ profile = Profile.new(profile_no)
17
+ profile.member = self
18
+ profile.purchase(currency, amount)
19
+ end
20
+ end
21
+ end
@@ -1,30 +1,30 @@
1
- require 'uri'
2
- require 'net/http'
3
-
4
- module Paygate
5
- class Profile
6
- PURCHASE_URL = 'https://service.paygate.net/INTL/pgtlProcess3.jsp'.freeze
7
-
8
- attr_reader :profile_no
9
- attr_accessor :member
10
-
11
- def initialize(profile_no)
12
- @profile_no = profile_no
13
- end
14
-
15
- def purchase(currency, amount)
16
- # Prepare params
17
- params = { profile_no: profile_no,
18
- mid: member.mid,
19
- goodcurrency: currency,
20
- unitprice: amount }.delete_if { |_, v| v.blank? }
21
-
22
- # Make request
23
- uri = URI(PURCHASE_URL)
24
- uri.query = ::URI.encode_www_form(params)
25
- response = ::Net::HTTP.get_response(uri)
26
-
27
- Response.build_from_net_http_response(:profile_pay, response)
28
- end
29
- end
30
- end
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module Paygate
5
+ class Profile
6
+ PURCHASE_URL = 'https://service.paygate.net/INTL/pgtlProcess3.jsp'.freeze
7
+
8
+ attr_reader :profile_no
9
+ attr_accessor :member
10
+
11
+ def initialize(profile_no)
12
+ @profile_no = profile_no
13
+ end
14
+
15
+ def purchase(currency, amount)
16
+ # Prepare params
17
+ params = { profile_no: profile_no,
18
+ mid: member.mid,
19
+ goodcurrency: currency,
20
+ unitprice: amount }.delete_if { |_, v| v.blank? }
21
+
22
+ # Make request
23
+ uri = URI(PURCHASE_URL)
24
+ uri.query = ::URI.encode_www_form(params)
25
+ response = ::Net::HTTP.get_response(uri)
26
+
27
+ Response.build_from_net_http_response(:profile_pay, response)
28
+ end
29
+ end
30
+ end
@@ -1,25 +1,25 @@
1
- module Paygate
2
- class Response
3
- attr_accessor :transaction_type, :http_code, :message, :body, :raw_info, :json
4
-
5
- def self.build_from_net_http_response(txn_type, response)
6
- r = new
7
- r.transaction_type = txn_type
8
- r.http_code = response.code
9
- r.message = response.message
10
- r.body = response.body
11
-
12
- case txn_type
13
- when :refund
14
- r.json = JSON.parse response.body.gsub(/^callback\((.*)\)$/, '\1') if response.code.to_i == 200
15
- when :profile_pay
16
- r.json = {}
17
- response.body.split('&').each do |key_value_pair|
18
- key_value_ary = key_value_pair.split('=')
19
- r.json[key_value_ary[0]] = key_value_ary[1]
20
- end
21
- end
22
- r
23
- end
24
- end
25
- end
1
+ module Paygate
2
+ class Response
3
+ attr_accessor :transaction_type, :http_code, :message, :body, :raw_info, :json
4
+
5
+ def self.build_from_net_http_response(txn_type, response)
6
+ r = new
7
+ r.transaction_type = txn_type
8
+ r.http_code = response.code
9
+ r.message = response.message
10
+ r.body = response.body
11
+
12
+ case txn_type
13
+ when :refund
14
+ r.json = JSON.parse response.body.gsub(/^callback\((.*)\)$/, '\1') if response.code.to_i == 200
15
+ when :profile_pay
16
+ r.json = {}
17
+ response.body.split('&').each do |key_value_pair|
18
+ key_value_ary = key_value_pair.split('=')
19
+ r.json[key_value_ary[0]] = key_value_ary[1]
20
+ end
21
+ end
22
+ r
23
+ end
24
+ end
25
+ end
@@ -1,47 +1,58 @@
1
- require 'digest'
2
- require 'uri'
3
- require 'net/http'
4
-
5
- module Paygate
6
- class Transaction
7
- FULL_AMOUNT_IDENTIFIER = 'F'.freeze
8
-
9
- attr_reader :tid
10
- attr_accessor :member
11
-
12
- def initialize(tid)
13
- @tid = tid
14
- end
15
-
16
- def refund(options = {})
17
- # Encrypt data
18
- api_key_256 = ::Digest::SHA256.hexdigest(member.secret)
19
- aes_ctr = AesCtr.encrypt(tid, api_key_256, 256)
20
- tid_enc = "AES256#{aes_ctr}"
21
-
22
- # Prepare params
23
- params = { callback: 'callback', mid: member.mid, tid: tid_enc }
24
- params.merge!(options.slice(:amount))
25
- params[:amount] ||= FULL_AMOUNT_IDENTIFIER
26
- params[:mb_serial_no] = options[:order_id]
27
- params.delete_if { |_, v| v.blank? }
28
-
29
- # Make request
30
- uri = URI(self.class.refund_api_url)
31
- uri.query = ::URI.encode_www_form(params)
32
- response = ::Net::HTTP.get_response(uri)
33
-
34
- r = Response.build_from_net_http_response(:refund, response)
35
- r.raw_info = OpenStruct.new(tid: tid, tid_enc: tid_enc, request_url: uri.to_s)
36
- r
37
- end
38
-
39
- private
40
-
41
- def self.refund_api_url
42
- (Paygate.configuration.mode == :live) ?
43
- 'https://service.paygate.net/service/cancelAPI.json' :
44
- 'https://stgsvc.paygate.net/service/cancelAPI.json'
45
- end
46
- end
47
- end
1
+ require 'digest'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module Paygate
6
+ class Transaction
7
+ FULL_AMOUNT_IDENTIFIER = 'F'.freeze
8
+
9
+ attr_reader :tid
10
+ attr_accessor :member
11
+
12
+ def initialize(tid)
13
+ @tid = tid
14
+ end
15
+
16
+ def refund(options = {})
17
+ # Encrypt data
18
+ api_key_256 = ::Digest::SHA256.hexdigest(member.secret)
19
+ aes_ctr = AesCtr.encrypt(tid, api_key_256, 256)
20
+ tid_enc = "AES256#{aes_ctr}"
21
+
22
+ # Prepare params
23
+ params = { callback: 'callback', mid: member.mid, tid: tid_enc }
24
+ params.merge!(options.slice(:amount))
25
+ params[:amount] ||= FULL_AMOUNT_IDENTIFIER
26
+ params[:mb_serial_no] = options[:order_id]
27
+ params.delete_if { |_, v| v.blank? }
28
+
29
+ # Make request
30
+ uri = URI(self.class.refund_api_url)
31
+ uri.query = ::URI.encode_www_form(params)
32
+ response = ::Net::HTTP.get_response(uri)
33
+
34
+ r = Response.build_from_net_http_response(:refund, response)
35
+ r.raw_info = OpenStruct.new(tid: tid, tid_enc: tid_enc, request_url: uri.to_s)
36
+ r
37
+ end
38
+
39
+ # Doc: https://km.paygate.net/pages/viewpage.action?pageId=9207875
40
+ def verify
41
+ params = { tid: tid, verifyNum: 100 }
42
+
43
+ uri = URI('https://service.paygate.net/djemals/settle/verifyReceived.jsp')
44
+ uri.query = ::URI.encode_www_form(params)
45
+ response = ::Net::HTTP.get_response(uri)
46
+
47
+ Response.build_from_net_http_response(:verify, response)
48
+ end
49
+
50
+ private
51
+
52
+ def self.refund_api_url
53
+ (Paygate.configuration.mode == :live) ?
54
+ 'https://service.paygate.net/service/cancelAPI.json' :
55
+ 'https://stgsvc.paygate.net/service/cancelAPI.json'
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
- module Paygate
2
- VERSION = '0.1.6'
3
- end
1
+ module Paygate
2
+ VERSION = '0.1.11'
3
+ end
data/lib/paygate-ruby.rb CHANGED
@@ -1,48 +1,48 @@
1
- require "paygate/version"
2
-
3
- require 'paygate/configuration'
4
- require 'paygate/aes'
5
- require 'paygate/aes_ctr'
6
-
7
- require 'paygate/member'
8
- require 'paygate/response'
9
- require 'paygate/transaction'
10
- require 'paygate/profile'
11
-
12
- require 'paygate/helpers/form_helper' if defined? ActionView
13
-
14
- module Paygate
15
- class Engine < ::Rails::Engine; end
16
-
17
- CONFIG = YAML.load(File.read(File.expand_path('../data/config.yml', File.dirname(__FILE__)))).freeze
18
- LOCALES_MAP = CONFIG[:locales].freeze
19
- INTL_BRANDS_MAP = CONFIG[:intl][:brands].freeze
20
- KOREA_BIN_NUMBERS = CONFIG[:korea][:bin_numbers].freeze
21
-
22
- DEFAULT_CURRENCY = 'WON'.freeze
23
- DEFAULT_LOCALE = 'US'.freeze
24
-
25
- def mapped_currency(currency)
26
- return DEFAULT_CURRENCY unless currency.present?
27
-
28
- currency.to_s == 'KRW' ? 'WON' : currency.to_s
29
- end
30
- module_function :mapped_currency
31
-
32
- def mapped_locale(locale)
33
- locale.present? ? LOCALES_MAP[locale.to_s] : DEFAULT_LOCALE
34
- end
35
- module_function :mapped_locale
36
-
37
- class << self
38
- attr_writer :configuration
39
- end
40
-
41
- def self.configuration
42
- @configuration ||= Configuration.new
43
- end
44
-
45
- def self.configure
46
- yield configuration
47
- end
48
- end
1
+ require 'yaml'
2
+ require 'paygate/version'
3
+ require 'paygate/configuration'
4
+ require 'paygate/aes'
5
+ require 'paygate/aes_ctr'
6
+ require 'paygate/member'
7
+ require 'paygate/response'
8
+ require 'paygate/transaction'
9
+ require 'paygate/profile'
10
+ require 'paygate/helpers/form_helper' if defined?(ActionView)
11
+
12
+ module Paygate
13
+ if defined?(Rails)
14
+ class Engine < ::Rails::Engine; end
15
+ end
16
+
17
+ CONFIG = YAML.load(File.read(File.expand_path('../data/config.yml', File.dirname(__FILE__)))).freeze
18
+ LOCALES_MAP = CONFIG[:locales].freeze
19
+ INTL_BRANDS_MAP = CONFIG[:intl][:brands].freeze
20
+ KOREA_BIN_NUMBERS = CONFIG[:korea][:bin_numbers].freeze
21
+
22
+ DEFAULT_CURRENCY = 'WON'.freeze
23
+ DEFAULT_LOCALE = 'US'.freeze
24
+
25
+ def mapped_currency(currency)
26
+ return DEFAULT_CURRENCY unless currency.present?
27
+
28
+ currency.to_s == 'KRW' ? 'WON' : currency.to_s
29
+ end
30
+ module_function :mapped_currency
31
+
32
+ def mapped_locale(locale)
33
+ locale.present? ? LOCALES_MAP[locale.to_s] : DEFAULT_LOCALE
34
+ end
35
+ module_function :mapped_locale
36
+
37
+ class << self
38
+ attr_writer :configuration
39
+ end
40
+
41
+ def self.configuration
42
+ @configuration ||= Configuration.new
43
+ end
44
+
45
+ def self.configure
46
+ yield configuration
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ RSpec.describe 'basic' do
6
+ it 'can load gem' do
7
+ expect(true).to eq true
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__)
4
+
5
+ require 'paygate-ruby'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+ config.order = 'random'
10
+ end