nicepay_ruby 1.0.0 → 1.1.0

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.
@@ -0,0 +1,233 @@
1
+ module NicepayRuby
2
+ # =============================
3
+ # Payout Registration (V2)
4
+ # =============================
5
+ class PayoutRegistrationBuilder
6
+ def initialize
7
+ @request_body = {}
8
+ end
9
+
10
+ def set_payout_v2(
11
+ i_mid:,
12
+ time_stamp:,
13
+ pay_method:,
14
+ currency:,
15
+ amt:,
16
+ reference_no:,
17
+ goods_nm:,
18
+ merchant_token:,
19
+ shop_id:,
20
+ billing_nm:,
21
+ billing_phone:,
22
+ billing_email:,
23
+ billing_addr:,
24
+ billing_city:,
25
+ billing_state:,
26
+ billing_post_cd:,
27
+ billing_country:,
28
+ delivery_nm:,
29
+ delivery_phone:,
30
+ delivery_addr:,
31
+ delivery_city:,
32
+ delivery_state:,
33
+ delivery_post_cd:,
34
+ delivery_country:,
35
+ db_process_url:,
36
+ vat:,
37
+ fee:,
38
+ notax_amt:,
39
+ description:,
40
+ req_dt:,
41
+ req_tm:,
42
+ req_domain:,
43
+ req_server_ip:,
44
+ req_client_ver:,
45
+ user_ip:,
46
+ user_session_id:,
47
+ user_agent:,
48
+ user_language:,
49
+ cart_data:
50
+ )
51
+ @request_body["timeStamp"] = time_stamp
52
+ @request_body["iMid"] = i_mid
53
+ @request_body["payMethod"] = pay_method
54
+ @request_body["currency"] = currency
55
+ @request_body["amt"] = amt
56
+ @request_body["referenceNo"] = reference_no
57
+ @request_body["goodsNm"] = goods_nm
58
+ @request_body["merchantToken"] = merchant_token
59
+ @request_body["shopId"] = shop_id
60
+ @request_body["billingNm"] = billing_nm
61
+ @request_body["billingPhone"] = billing_phone
62
+ @request_body["billingEmail"] = billing_email
63
+ @request_body["billingAddr"] = billing_addr
64
+ @request_body["billingCity"] = billing_city
65
+ @request_body["billingState"] = billing_state
66
+ @request_body["billingPostCd"] = billing_post_cd
67
+ @request_body["billingCountry"]= billing_country
68
+ @request_body["dbProcessUrl"] = db_process_url
69
+ @request_body["deliveryNm"] = delivery_nm
70
+ @request_body["deliveryPhone"] = delivery_phone
71
+ @request_body["deliveryAddr"] = delivery_addr
72
+ @request_body["deliveryCity"] = delivery_city
73
+ @request_body["deliveryState"] = delivery_state
74
+ @request_body["deliveryPostCd"]= delivery_post_cd
75
+ @request_body["deliveryCountry"]= delivery_country
76
+ @request_body["vat"] = vat
77
+ @request_body["fee"] = fee
78
+ @request_body["notaxAmt"] = notax_amt
79
+ @request_body["description"] = description
80
+ @request_body["reqDt"] = req_dt
81
+ @request_body["reqTm"] = req_tm
82
+ @request_body["reqDomain"] = req_domain
83
+ @request_body["reqServerIP"] = req_server_ip
84
+ @request_body["reqClientVer"] = req_client_ver
85
+ @request_body["userIP"] = user_ip
86
+ @request_body["userSessionID"] = user_session_id
87
+ @request_body["userAgent"] = user_agent
88
+ @request_body["userLanguage"] = user_language
89
+ @request_body["cartData"] = cart_data
90
+
91
+ self
92
+ end
93
+
94
+ def build
95
+ @request_body
96
+ end
97
+ end
98
+
99
+ # =============================
100
+ # Check Balance
101
+ # =============================
102
+ class PayoutCheckBalanceBuilder
103
+ def initialize
104
+ @request_body = {}
105
+ end
106
+
107
+ def set_check_balance(
108
+ time_stamp:,
109
+ i_mid:,
110
+ merchant_token:
111
+ )
112
+ @request_body["timeStamp"] = time_stamp
113
+ @request_body["iMid"] = i_mid
114
+ @request_body["merchantToken"] = merchant_token
115
+
116
+ self
117
+ end
118
+
119
+ def build
120
+ @request_body
121
+ end
122
+ end
123
+
124
+ # =============================
125
+ # Approve Payout
126
+ # =============================
127
+ class PayoutApproveBuilder
128
+ def initialize
129
+ @request_body = {}
130
+ end
131
+
132
+ def set_approve(
133
+ time_stamp:,
134
+ i_mid:,
135
+ merchant_token:,
136
+ t_xid:
137
+ )
138
+ @request_body["timeStamp"] = time_stamp
139
+ @request_body["iMid"] = i_mid
140
+ @request_body["merchantToken"] = merchant_token
141
+ @request_body["tXid"] = t_xid
142
+
143
+ self
144
+ end
145
+
146
+ def build
147
+ @request_body
148
+ end
149
+ end
150
+
151
+ # =============================
152
+ # Reject Payout
153
+ # =============================
154
+ class PayoutRejectBuilder
155
+ def initialize
156
+ @request_body = {}
157
+ end
158
+
159
+ def set_reject(
160
+ time_stamp:,
161
+ i_mid:,
162
+ merchant_token:,
163
+ t_xid:
164
+ )
165
+ @request_body["timeStamp"] = time_stamp
166
+ @request_body["iMid"] = i_mid
167
+ @request_body["merchantToken"] = merchant_token
168
+ @request_body["tXid"] = t_xid
169
+
170
+ self
171
+ end
172
+
173
+ def build
174
+ @request_body
175
+ end
176
+ end
177
+
178
+ # =============================
179
+ # Inquiry Payout
180
+ # =============================
181
+ class PayoutInquiryBuilder
182
+ def initialize
183
+ @request_body = {}
184
+ end
185
+
186
+ def set_inquiry(
187
+ i_mid:,
188
+ time_stamp:,
189
+ merchant_token:,
190
+ account_no:,
191
+ t_xid:
192
+ )
193
+ @request_body["iMid"] = i_mid
194
+ @request_body["timeStamp"] = time_stamp
195
+ @request_body["merchantToken"] = merchant_token
196
+ @request_body["accountNo"] = account_no
197
+ @request_body["tXid"] = t_xid
198
+
199
+ self
200
+ end
201
+
202
+ def build
203
+ @request_body
204
+ end
205
+ end
206
+
207
+ # =============================
208
+ # Cancel Payout
209
+ # =============================
210
+ class PayoutCancelBuilder
211
+ def initialize
212
+ @request_body = {}
213
+ end
214
+
215
+ def set_cancel(
216
+ time_stamp:,
217
+ i_mid:,
218
+ merchant_token:,
219
+ t_xid:
220
+ )
221
+ @request_body["timeStamp"] = time_stamp
222
+ @request_body["iMid"] = i_mid
223
+ @request_body["merchantToken"] = merchant_token
224
+ @request_body["tXid"] = t_xid
225
+
226
+ self
227
+ end
228
+
229
+ def build
230
+ @request_body
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,98 @@
1
+ # builder/qris_registration.rb
2
+ module NicepayRuby
3
+ class QrisRegistrationBuilder
4
+ def initialize
5
+ @request_body = {}
6
+ end
7
+
8
+ def set_qris_v2(
9
+ i_mid:,
10
+ time_stamp:,
11
+ pay_method:,
12
+ currency:,
13
+ amt:,
14
+ reference_no:,
15
+ goods_nm:,
16
+ merchant_token:,
17
+ shop_id: nil,
18
+ billing_nm:,
19
+ billing_phone:,
20
+ billing_email:,
21
+ billing_addr:,
22
+ billing_city:,
23
+ billing_state:,
24
+ billing_post_cd:,
25
+ billing_country:,
26
+ delivery_nm: nil,
27
+ delivery_phone: nil,
28
+ delivery_addr: nil,
29
+ delivery_city: nil,
30
+ delivery_state: nil,
31
+ delivery_post_cd: nil,
32
+ delivery_country: nil,
33
+ db_process_url:,
34
+ vat: nil,
35
+ fee: nil,
36
+ notax_amt: nil,
37
+ description: nil,
38
+ req_dt:,
39
+ req_tm:,
40
+ req_domain:,
41
+ req_server_ip:,
42
+ req_client_ver:,
43
+ user_ip:,
44
+ user_session_id:,
45
+ user_agent:,
46
+ user_language:,
47
+ cart_data:,
48
+ mitra_cd: nil
49
+ )
50
+ @request_body["timeStamp"] = time_stamp
51
+ @request_body["iMid"] = i_mid
52
+ @request_body["payMethod"] = pay_method
53
+ @request_body["currency"] = currency
54
+ @request_body["amt"] = amt
55
+ @request_body["referenceNo"] = reference_no
56
+ @request_body["goodsNm"] = goods_nm
57
+ @request_body["merchantToken"] = merchant_token
58
+ @request_body["shopId"] = shop_id
59
+ @request_body["billingNm"] = billing_nm
60
+ @request_body["billingPhone"] = billing_phone
61
+ @request_body["billingEmail"] = billing_email
62
+ @request_body["billingAddr"] = billing_addr
63
+ @request_body["billingCity"] = billing_city
64
+ @request_body["billingState"] = billing_state
65
+ @request_body["billingPostCd"] = billing_post_cd
66
+ @request_body["billingCountry"] = billing_country
67
+ @request_body["dbProcessUrl"] = db_process_url
68
+ @request_body["deliveryNm"] = delivery_nm
69
+ @request_body["deliveryPhone"] = delivery_phone
70
+ @request_body["deliveryAddr"] = delivery_addr
71
+ @request_body["deliveryCity"] = delivery_city
72
+ @request_body["deliveryState"] = delivery_state
73
+ @request_body["deliveryPostCd"] = delivery_post_cd
74
+ @request_body["deliveryCountry"]= delivery_country
75
+ @request_body["vat"] = vat
76
+ @request_body["fee"] = fee
77
+ @request_body["notaxAmt"] = notax_amt
78
+ @request_body["description"] = description
79
+ @request_body["reqDt"] = req_dt
80
+ @request_body["reqTm"] = req_tm
81
+ @request_body["reqDomain"] = req_domain
82
+ @request_body["reqServerIP"] = req_server_ip
83
+ @request_body["reqClientVer"] = req_client_ver
84
+ @request_body["userIP"] = user_ip
85
+ @request_body["userSessionID"] = user_session_id
86
+ @request_body["userAgent"] = user_agent
87
+ @request_body["userLanguage"] = user_language
88
+ @request_body["cartData"] = cart_data
89
+ @request_body["mitraCd"] = mitra_cd
90
+ self
91
+ end
92
+
93
+
94
+ def build
95
+ @request_body
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,121 @@
1
+ module NicepayRuby
2
+ class RedirectRegistrationBuilder
3
+ def initialize
4
+ @request_body = {}
5
+ end
6
+
7
+ def set_regist_redirect_v2(
8
+ time_stamp:,
9
+ i_mid:,
10
+ pay_method:,
11
+ bank_cd:,
12
+ currency:,
13
+ amt:,
14
+ reference_no:,
15
+ merchant_token:,
16
+ call_back_url:,
17
+ db_process_url:,
18
+ goods_nm:,
19
+ mitra_cd:,
20
+ vacct_valid_dt:,
21
+ vacct_valid_tm:,
22
+ description:,
23
+ billing_nm:,
24
+ billing_phone:,
25
+ billing_email:,
26
+ billing_addr:,
27
+ billing_city:,
28
+ billing_state:,
29
+ billing_post_cd:,
30
+ billing_country:,
31
+ user_ip:,
32
+ cart_data:,
33
+ delivery_nm:,
34
+ delivery_phone:,
35
+ delivery_addr:,
36
+ delivery_city:,
37
+ delivery_state:,
38
+ delivery_post_cd:,
39
+ delivery_country:,
40
+ vat: "",
41
+ fee: "",
42
+ notax_amt: "",
43
+ req_dt: "",
44
+ req_tm: "",
45
+ req_domain: "",
46
+ req_server_ip: "",
47
+ req_client_ver: "",
48
+ user_session_id: "",
49
+ user_agent: "",
50
+ user_language: "",
51
+ instmnt_type: "",
52
+ instmnt_mon:"",
53
+ recurr_opt:"",
54
+ payment_exp_dt: "",
55
+ payment_exp_tm:"",
56
+ shop_id: "",
57
+ pay_valid_dt: "",
58
+ pay_valid_tm: "",
59
+ mer_fix_acct_id:""
60
+ )
61
+ @request_body["timeStamp"] = time_stamp
62
+ @request_body["iMid"] = i_mid
63
+ @request_body["payMethod"] = pay_method
64
+ @request_body["bankCd"] = bank_cd
65
+ @request_body["currency"] = currency
66
+ @request_body["amt"] = amt
67
+ @request_body["referenceNo"] = reference_no
68
+ @request_body["merchantToken"] = merchant_token
69
+ @request_body["callBackUrl"] = call_back_url
70
+ @request_body["dbProcessUrl"] = db_process_url
71
+ @request_body["goodsNm"] = goods_nm
72
+ @request_body["mitraCd"] = mitra_cd
73
+ @request_body["vacctValidDt"] = vacct_valid_dt
74
+ @request_body["vacctValidTm"] = vacct_valid_tm
75
+ @request_body["description"] = description
76
+ @request_body["billingNm"] = billing_nm
77
+ @request_body["billingPhone"] = billing_phone
78
+ @request_body["billingEmail"] = billing_email
79
+ @request_body["billingAddr"] = billing_addr
80
+ @request_body["billingCity"] = billing_city
81
+ @request_body["billingState"] = billing_state
82
+ @request_body["billingPostCd"] = billing_post_cd
83
+ @request_body["billingCountry"]= billing_country
84
+ @request_body["userIP"] = user_ip
85
+ @request_body["cartData"] = cart_data
86
+ @request_body["deliveryNm"] = delivery_nm
87
+ @request_body["deliveryPhone"] = delivery_phone
88
+ @request_body["deliveryAddr"] = delivery_addr
89
+ @request_body["deliveryCity"] = delivery_city
90
+ @request_body["deliveryState"] = delivery_state
91
+ @request_body["deliveryPostCd"]= delivery_post_cd
92
+ @request_body["deliveryCountry"]= delivery_country
93
+ @request_body["vat"] = vat
94
+ @request_body["fee"] = fee
95
+ @request_body["notaxAmt"] = notax_amt
96
+ @request_body["reqDt"] = req_dt
97
+ @request_body["reqTm"] = req_tm
98
+ @request_body["reqDomain"] = req_domain
99
+ @request_body["reqServerIP"] = req_server_ip
100
+ @request_body["reqClientVer"] = req_client_ver
101
+ @request_body["userSessionID"] = user_session_id
102
+ @request_body["userAgent"] = user_agent
103
+ @request_body["userLanguage"] = user_language
104
+ @request_body["instmntType"] = instmnt_type
105
+ @request_body["instmntMon"] = instmnt_mon
106
+ @request_body["recurrOpt"] = recurr_opt
107
+ @request_body["paymentExpDt"] = payment_exp_dt
108
+ @request_body["paymentExpTm"] = payment_exp_tm
109
+ @request_body["shopId"] = shop_id
110
+ @request_body["payValidDt"] = pay_valid_dt
111
+ @request_body["payValidTm"] = pay_valid_tm
112
+ @request_body["merFixAcctId"] = mer_fix_acct_id
113
+
114
+ self
115
+ end
116
+
117
+ def build
118
+ @request_body
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,42 @@
1
+ module NicepayRuby
2
+ class VirtualAccountBuilder
3
+ def initialize
4
+ @request_body = {}
5
+ end
6
+
7
+ # === Versi Virtual Account Merchant (Non-SNAP) ===
8
+ def set_virtual_account(
9
+ i_mid:, time_stamp:, pay_method:, currency:, amt:, reference_no:, goods_nm:, merchant_token:,
10
+ bank_cd:, billing_nm:, billing_phone:, billing_email:, billing_addr:, billing_city:, billing_state:,
11
+ billing_post_cd:, billing_country:, vacct_valid_dt:, vacct_valid_tm:, db_process_url:, mer_fix_acct_id:
12
+ )
13
+ @request_body["timeStamp"] = time_stamp
14
+ @request_body["iMid"] = i_mid
15
+ @request_body["payMethod"] = pay_method
16
+ @request_body["currency"] = currency
17
+ @request_body["amt"] = amt
18
+ @request_body["referenceNo"] = reference_no
19
+ @request_body["goodsNm"] = goods_nm
20
+ @request_body["merchantToken"] = merchant_token
21
+ @request_body["bankCd"] = bank_cd
22
+ @request_body["billingNm"] = billing_nm
23
+ @request_body["billingPhone"] = billing_phone
24
+ @request_body["billingEmail"] = billing_email
25
+ @request_body["billingAddr"] = billing_addr
26
+ @request_body["billingCity"] = billing_city
27
+ @request_body["billingState"] = billing_state
28
+ @request_body["billingPostCd"] = billing_post_cd
29
+ @request_body["billingCountry"] = billing_country
30
+ @request_body["vacctValidDt"] = vacct_valid_dt
31
+ @request_body["vacctValidTm"] = vacct_valid_tm
32
+ @request_body["dbProcessUrl"] = db_process_url
33
+ @request_body["merFixAcctId"] = mer_fix_acct_id
34
+ self
35
+ end
36
+
37
+
38
+ def build
39
+ @request_body
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,63 @@
1
+
2
+ require_relative 'signatureUtils'
3
+ require_relative 'nicepayConstant'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+
8
+ module NicepayRuby
9
+ class AccessTokenClient
10
+ # def initialize(is_production: false)
11
+ # @client_id = NicepayCredential.client_id
12
+ # @private_key_base64 = NicepayCredential.private_key
13
+ # @url = is_production ?
14
+ # 'https://www.nicepay.co.id/nicepay/v1.0/access-token/b2b' :
15
+ # 'https://dev.nicepay.co.id/nicepay/v1.0/access-token/b2b'
16
+ # end
17
+
18
+ def initialize(client_id: nil, private_key: nil, is_production: nil, is_cloud_server: nil)
19
+ config = NicepayRuby.configuration
20
+
21
+ @client_id = client_id || config.client_id
22
+ @private_key = private_key || config.private_key
23
+ @is_production = is_production.nil? ? config.is_production : is_production
24
+ @is_cloud_server = is_cloud_server.nil? ? config.is_cloud_server : is_cloud_server
25
+
26
+ Config.set_environment(
27
+ production: @is_production,
28
+ cloud_server: @is_cloud_server
29
+ )
30
+ end
31
+
32
+ def request_access_token
33
+ timestamp = Time.now.getlocal('+07:00').strftime('%Y-%m-%dT%H:%M:%S%:z')
34
+ signature = SignatureGeneratorUtils.generate_signature(@private_key, @client_id, timestamp)
35
+ endpoints = ApiEndpoints.new
36
+ full_url = build_full_url(endpoints.access_token)
37
+ puts full_url
38
+ uri = URI(full_url)
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ http.use_ssl = true
41
+
42
+ headers = {
43
+ 'Content-Type' => 'application/json',
44
+ 'X-CLIENT-KEY' => @client_id,
45
+ 'X-TIMESTAMP' => timestamp,
46
+ 'X-SIGNATURE' => signature
47
+ }
48
+
49
+ request = Net::HTTP::Post.new(uri, headers)
50
+ request.body = { grantType: 'client_credentials' }.to_json
51
+
52
+ response = http.request(request)
53
+ JSON.parse(response.body)
54
+ end
55
+
56
+
57
+ def build_full_url(path)
58
+ base_url = NicepayRuby::Config.base_url
59
+ "#{base_url}#{path}"
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,27 @@
1
+ module NicepayRuby
2
+ class Configuration
3
+ attr_accessor :client_id, :client_secret, :private_key, :channel_id, :partner_id,
4
+ :is_production, :is_cloud_server, :merchant_key
5
+
6
+ def initialize
7
+ @client_id = nil
8
+ @client_secret = nil
9
+ @merchant_key = nil
10
+ @private_key = nil
11
+ @channel_id = nil
12
+ @partner_id = nil
13
+ @is_production = false
14
+ @is_cloud_server = false
15
+ end
16
+ end
17
+
18
+ # ⬇️ pindahin ke luar class Configuration
19
+ class << self
20
+ attr_accessor :configuration
21
+ end
22
+
23
+ def self.configure
24
+ self.configuration ||= Configuration.new
25
+ yield(configuration)
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ # lib/nicepay_ruby/merchant_token_builder.rb
2
+ require_relative 'signatureUtils'
3
+ require_relative 'nicepayConstant'
4
+
5
+
6
+ module NicepayRuby
7
+ class MerchantTokenGenerate
8
+ def initialize
9
+ @time_stamp = nil
10
+ @i_mid = nil
11
+ @ref_no = nil
12
+ @amount = nil
13
+ @merchant_key = nil
14
+ @account_no = nil
15
+ @txid = nil
16
+ end
17
+
18
+ def set_time_stamp(time_stamp); @time_stamp = time_stamp; self; end
19
+ def set_account_no(account_no); @account_no = account_no; self; end
20
+ def set_imid(i_mid); @i_mid = i_mid; self; end
21
+ def set_ref_no(ref_no); @ref_no = ref_no; self; end
22
+ def set_amount(amount); @amount = amount; self; end
23
+ def set_txid(txid); @txid = txid; self; end
24
+ def set_merchant_key(merchant_key); @merchant_key = merchant_key; self; end
25
+
26
+ # --- Build Tokens ---
27
+ def build_merchant_token
28
+ raw = "#{@time_stamp}#{@i_mid}#{@ref_no}#{@amount}#{@merchant_key}"
29
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
30
+
31
+ end
32
+
33
+ def build_payout_merchant_token
34
+ raw = "#{@time_stamp}#{@i_mid}#{@amount}#{@account_no}#{@merchant_key}"
35
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
36
+
37
+ end
38
+
39
+ def build_payout_status_merchant_token
40
+ raw = "#{@time_stamp}#{@i_mid}#{@txid}#{@account_no}#{@merchant_key}"
41
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
42
+
43
+ end
44
+
45
+ def build_payout_step_merchant_token
46
+ raw = "#{@time_stamp}#{@i_mid}#{@txid}#{@merchant_key}"
47
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
48
+
49
+ end
50
+
51
+ def build_payout_balance_merchant_token
52
+ raw = "#{@time_stamp}#{@i_mid}#{@merchant_key}"
53
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
54
+
55
+ end
56
+
57
+ def build_cancel_merchant_token
58
+ raw = "#{@time_stamp}#{@i_mid}#{@txid}#{@amount}#{@merchant_key}"
59
+ NicepayRuby::SignatureGeneratorUtils.encrypt(raw)
60
+
61
+ end
62
+ end
63
+ end