toss_payments 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/toss_payments.rb +124 -107
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bef2dd5c0d2e87f01690e5ed030c027e8e4917334e185887840f7e4132130376
|
4
|
+
data.tar.gz: 3e2753fab99116ce0835afb669aa519258ec60c3455d0dbe54ad8e0d018b663a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39dcda82ed1b015eb42d8199e358560f053479a7f986e7975eb9a841d4f5f49a638c62cb52673d3ee2ecc0ea3eb5fee3dee429e87119cbca965be25882c512ab
|
7
|
+
data.tar.gz: 3cab73313d0420bb3cd05dc6cacbdc579f482de64957670aa66f72d1a795c2c2c683576754a280f2d31c16196d635197fab2767465c3b4add35e867f413d94e5
|
data/lib/toss_payments.rb
CHANGED
@@ -2,7 +2,16 @@ require "httparty"
|
|
2
2
|
require "time"
|
3
3
|
|
4
4
|
module TossPayments
|
5
|
-
|
5
|
+
ErrorResponse = Struct.new(
|
6
|
+
:response_type,
|
7
|
+
:code,
|
8
|
+
:message,
|
9
|
+
:response,
|
10
|
+
keyword_init: true,
|
11
|
+
)
|
12
|
+
|
13
|
+
PaymentResponse = Struct.new(
|
14
|
+
:response_type,
|
6
15
|
:version,
|
7
16
|
:payment_key,
|
8
17
|
:type,
|
@@ -41,7 +50,8 @@ module TossPayments
|
|
41
50
|
keyword_init: true,
|
42
51
|
)
|
43
52
|
|
44
|
-
|
53
|
+
BillingResponse = Struct.new(
|
54
|
+
:response_type,
|
45
55
|
:m_id,
|
46
56
|
:customer_key,
|
47
57
|
:authenticated_at,
|
@@ -103,12 +113,12 @@ module TossPayments
|
|
103
113
|
|
104
114
|
def billing_auth_card(payload = {})
|
105
115
|
uri = "billing/authorizations/card"
|
106
|
-
post(uri, payload,
|
116
|
+
post(uri, payload, response_type: :billing)
|
107
117
|
end
|
108
118
|
|
109
119
|
def billing_auth_issue(payload = {})
|
110
120
|
uri = "billing/authorizations/issue"
|
111
|
-
post(uri, payload,
|
121
|
+
post(uri, payload, response_type: :billing)
|
112
122
|
end
|
113
123
|
|
114
124
|
def billing(billing_key, payload = {})
|
@@ -119,53 +129,60 @@ module TossPayments
|
|
119
129
|
private
|
120
130
|
|
121
131
|
def headers
|
122
|
-
{ "Authorization": "Basic #{Base64.strict_encode64(config.secret_key)}
|
132
|
+
{ "Authorization": "Basic #{Base64.strict_encode64(config.secret_key + ":")}" }
|
123
133
|
end
|
124
134
|
|
125
|
-
def get(uri, payload = {},
|
135
|
+
def get(uri, payload = {}, response_type: :payment)
|
126
136
|
url = "#{HOST}/#{uri}"
|
127
137
|
response = HTTParty.get(url, headers: headers, body: payload).parsed_response
|
128
|
-
|
129
|
-
code: response["code"],
|
130
|
-
message: response["message"],
|
131
|
-
data: type == :payment ? payment_response_data_to_model(response["data"]) : billing_response_data_to_model(response["data"]),
|
132
|
-
}
|
138
|
+
response_to_model(response, response_type: type)
|
133
139
|
end
|
134
140
|
|
135
|
-
def post(uri, payload = {},
|
141
|
+
def post(uri, payload = {}, response_type: :payment)
|
136
142
|
url = "#{HOST}/#{uri}"
|
137
143
|
response = HTTParty.post(url, headers: headers.merge("Content-Type": "application/json"), body: payload.to_json).parsed_response
|
138
|
-
|
144
|
+
response_to_model(response, response_type: type)
|
145
|
+
end
|
146
|
+
|
147
|
+
def response_to_model(response, response_type:)
|
148
|
+
return error_response_to_model(response) if response.keys.include?("code")
|
149
|
+
return payment_response_to_model(response) if response_type == :payment
|
150
|
+
return billing_response_to_model(response) if response_type == :billing
|
151
|
+
end
|
152
|
+
|
153
|
+
def error_response_to_model(response)
|
154
|
+
ErrorResponse.new(
|
155
|
+
response_type: :error,
|
139
156
|
code: response["code"],
|
140
157
|
message: response["message"],
|
141
|
-
data:
|
142
|
-
|
158
|
+
data: response["data"],
|
159
|
+
)
|
143
160
|
end
|
144
161
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
version:
|
149
|
-
payment_key:
|
150
|
-
type:
|
151
|
-
order_id:
|
152
|
-
order_name:
|
153
|
-
m_id:
|
154
|
-
currency:
|
155
|
-
method:
|
156
|
-
total_amount:
|
157
|
-
balanced_amount:
|
158
|
-
status:
|
159
|
-
requested_at: Time.parse(
|
160
|
-
approved_at: Time.parse(
|
161
|
-
use_escrow:
|
162
|
-
last_transaction_key:
|
163
|
-
supplied_amount:
|
164
|
-
vat:
|
165
|
-
culture_expense:
|
166
|
-
tax_free_amount:
|
167
|
-
tax_exemption_amount:
|
168
|
-
cancels:
|
162
|
+
def payment_response_to_model(response)
|
163
|
+
PaymentResponse.new(
|
164
|
+
response_type: :payment,
|
165
|
+
version: response["version"],
|
166
|
+
payment_key: response["paymentKey"],
|
167
|
+
type: response["type"],
|
168
|
+
order_id: response["orderId"],
|
169
|
+
order_name: response["orderName"],
|
170
|
+
m_id: response["mId"],
|
171
|
+
currency: response["currency"],
|
172
|
+
method: response["method"],
|
173
|
+
total_amount: response["totalAmount"],
|
174
|
+
balanced_amount: response["balancedAmount"],
|
175
|
+
status: response["status"].downcase.to_sym,
|
176
|
+
requested_at: Time.parse(response["requestedAt"]),
|
177
|
+
approved_at: Time.parse(response["approvedAt"]),
|
178
|
+
use_escrow: response["useEscrow"],
|
179
|
+
last_transaction_key: response["lastTransactionKey"],
|
180
|
+
supplied_amount: response["suppliedAmount"],
|
181
|
+
vat: response["vat"],
|
182
|
+
culture_expense: response["cultureExpense"],
|
183
|
+
tax_free_amount: response["taxFreeAmount"],
|
184
|
+
tax_exemption_amount: response["taxExemptionAmount"],
|
185
|
+
cancels: response["canceles"]&.map do |cancel|
|
169
186
|
{
|
170
187
|
cancel_amount: cancel["cancelAmount"],
|
171
188
|
cancel_reason: cancel["cancelReason"],
|
@@ -177,89 +194,89 @@ module TossPayments
|
|
177
194
|
transaction_key: cancel["transactionKey"],
|
178
195
|
}
|
179
196
|
end,
|
180
|
-
is_partial_cancelable:
|
181
|
-
card:
|
182
|
-
amount:
|
183
|
-
issuer_code:
|
184
|
-
acquirer_code:
|
185
|
-
number:
|
186
|
-
installment_plan_months:
|
187
|
-
approve_no:
|
188
|
-
use_card_point:
|
189
|
-
card_type:
|
190
|
-
owner_type:
|
191
|
-
acquire_status:
|
192
|
-
is_interest_free:
|
193
|
-
interset_payer:
|
197
|
+
is_partial_cancelable: response["isPartialCancelable"],
|
198
|
+
card: response["card"] ? {
|
199
|
+
amount: response["card"]["amount"],
|
200
|
+
issuer_code: response["card"]["issuerCode"],
|
201
|
+
acquirer_code: response["card"]["acquirerCode"],
|
202
|
+
number: response["card"]["number"],
|
203
|
+
installment_plan_months: response["card"]["installmentPlanMonths"],
|
204
|
+
approve_no: response["card"]["approveNo"],
|
205
|
+
use_card_point: response["card"]["useCardPoint"],
|
206
|
+
card_type: response["card"]["cardType"],
|
207
|
+
owner_type: response["card"]["ownerType"],
|
208
|
+
acquire_status: response["card"]["acquireStatus"].downcase.to_sym,
|
209
|
+
is_interest_free: response["card"]["isInterestFree"],
|
210
|
+
interset_payer: response["card"]["intersetPayer"].downcase.to_sym,
|
194
211
|
} : nil,
|
195
|
-
virtual_account:
|
196
|
-
account_type:
|
197
|
-
account_number:
|
198
|
-
bank_code:
|
199
|
-
customer_name:
|
200
|
-
due_date: Time.parse(
|
201
|
-
refund_status:
|
202
|
-
expired:
|
203
|
-
settlement_status:
|
212
|
+
virtual_account: response["virtualAccount"] ? {
|
213
|
+
account_type: response["virtualAccount"]["accountType"],
|
214
|
+
account_number: response["virtualAccount"]["accountNumber"],
|
215
|
+
bank_code: response["virtualAccount"]["bankCode"],
|
216
|
+
customer_name: response["virtualAccount"]["customerName"],
|
217
|
+
due_date: Time.parse(response["virtualAccount"]["dueDate"]),
|
218
|
+
refund_status: response["virtualAccount"]["refundStatus"].downcase.to_sym,
|
219
|
+
expired: response["virtualAccount"]["expired"],
|
220
|
+
settlement_status: response["virtualAccount"]["settlementStatus"],
|
204
221
|
} : nil,
|
205
|
-
secret:
|
206
|
-
mobile_phone:
|
207
|
-
customer_mobile_phone:
|
208
|
-
settlement_status:
|
209
|
-
receipt_url:
|
222
|
+
secret: response["secret"],
|
223
|
+
mobile_phone: response["mobilePhone"] ? {
|
224
|
+
customer_mobile_phone: response["mobilePhone"]["customerMobilePhone"],
|
225
|
+
settlement_status: response["mobilePhone"]["settlementStatus"],
|
226
|
+
receipt_url: response["mobilePhone"]["receiptUrl"],
|
210
227
|
} : nil,
|
211
|
-
gift_certificate:
|
212
|
-
approve_no:
|
213
|
-
settlement_status:
|
228
|
+
gift_certificate: response["giftCertificate"] ? {
|
229
|
+
approve_no: response["giftCertificate"]["approveNo"],
|
230
|
+
settlement_status: response["giftCertificate"]["settlementStatus"],
|
214
231
|
} : nil,
|
215
|
-
transfer:
|
216
|
-
bank_code:
|
217
|
-
settlement_status:
|
232
|
+
transfer: response["transfer"] ? {
|
233
|
+
bank_code: response["transfer"]["bankCode"],
|
234
|
+
settlement_status: response["transfer"]["settlementStatus"],
|
218
235
|
} : nil,
|
219
|
-
receipt:
|
220
|
-
url:
|
236
|
+
receipt: response["receipt"] ? {
|
237
|
+
url: response["receipt"]["url"],
|
221
238
|
} : nil,
|
222
|
-
checkout:
|
223
|
-
url:
|
239
|
+
checkout: response["checkout"] ? {
|
240
|
+
url: response["checkout"]["url"],
|
224
241
|
} : nil,
|
225
|
-
easy_pay:
|
226
|
-
provider:
|
227
|
-
amount:
|
228
|
-
discount_amount:
|
242
|
+
easy_pay: response["easyPay"] ? {
|
243
|
+
provider: response["easyPay"]["provider"],
|
244
|
+
amount: response["easyPay"]["amount"],
|
245
|
+
discount_amount: response["easyPay"]["discountAmount"],
|
229
246
|
} : nil,
|
230
|
-
country:
|
231
|
-
failure:
|
232
|
-
code:
|
233
|
-
message:
|
247
|
+
country: response["country"],
|
248
|
+
failure: response["failure"] ? {
|
249
|
+
code: response["failure"]["code"],
|
250
|
+
message: response["failure"]["message"],
|
234
251
|
} : nil,
|
235
|
-
cash_receipt:
|
236
|
-
receipt_key:
|
237
|
-
type:
|
238
|
-
amount:
|
239
|
-
tax_free_amount:
|
240
|
-
issue_number:
|
241
|
-
receipt_url:
|
252
|
+
cash_receipt: response["cashReceipt"] ? {
|
253
|
+
receipt_key: response["cashReceipt"]["receiptKey"],
|
254
|
+
type: response["cashReceipt"]["type"],
|
255
|
+
amount: response["cashReceipt"]["amount"],
|
256
|
+
tax_free_amount: response["cashReceipt"]["taxFreeAmount"],
|
257
|
+
issue_number: response["cashReceipt"]["issueNumber"],
|
258
|
+
receipt_url: response["cashReceipt"]["receiptUrl"],
|
242
259
|
} : nil,
|
243
|
-
discount:
|
244
|
-
amount:
|
260
|
+
discount: response["discount"] ? {
|
261
|
+
amount: response["discount"]["amount"],
|
245
262
|
} : nil,
|
246
263
|
)
|
247
264
|
end
|
248
265
|
|
249
|
-
def
|
250
|
-
|
251
|
-
|
252
|
-
m_id:
|
253
|
-
customer_key:
|
254
|
-
authenticated_at: Time.parse(
|
255
|
-
method:
|
256
|
-
billing_key:
|
266
|
+
def billing_response_to_model(response)
|
267
|
+
BillingResponse.new(
|
268
|
+
response_type: :billing,
|
269
|
+
m_id: response["mId"],
|
270
|
+
customer_key: response["customerKey"],
|
271
|
+
authenticated_at: Time.parse(response["authenticatedAt"]),
|
272
|
+
method: response["method"],
|
273
|
+
billing_key: response["billingKey"],
|
257
274
|
card: {
|
258
|
-
issuer_code:
|
259
|
-
acquirer_code:
|
260
|
-
number:
|
261
|
-
card_type:
|
262
|
-
owner_type:
|
275
|
+
issuer_code: response["card"]["issuerCode"],
|
276
|
+
acquirer_code: response["card"]["acquirerCode"],
|
277
|
+
number: response["card"]["number"],
|
278
|
+
card_type: response["card"]["cardType"],
|
279
|
+
owner_type: response["card"]["ownerType"],
|
263
280
|
},
|
264
281
|
)
|
265
282
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toss_payments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soohyeon Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: toss payments api
|
14
14
|
email: lsh59727@gmail.com
|