toss_payments 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/toss_payments.rb +35 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b16cccf42152733567c97daae4c9949e97d15dc7b7f2b2d8d0ee228959bb6a52
4
- data.tar.gz: e4fab7035a23e2e82464a35c960e5bad288673b7112b802bc2a95694d32a6d7a
3
+ metadata.gz: 75a55683e83f0eaa4cead2cf31ce9d57fe73934b51edfe19886afc7130a9eccc
4
+ data.tar.gz: d4d69e88f3ea4056d8b9476f3c9219b017455c6d28cf5c501e500a27576524e2
5
5
  SHA512:
6
- metadata.gz: a18b3ee6f20c0fe4ba41bfe22b308aae55ccb2c8125d3acf6b3b3f0f116490803552d1ce5a75c9e883852f5b0290fd97334092ef4bed5f97ccc19e79f562e536
7
- data.tar.gz: b648fa7b53f35efdc236c028ce0479af6e8dd892fc0273e71dfc6bef2c9e28717f10686da5f281d50d18a9e88618a33237a30ad1d8ecc69e449fbe6c0b39c484
6
+ metadata.gz: 60e9a7babf7bce954585fa4e35e975b56e24d39fd28f64d3897dfec8af3f810187950a4e2a565ec7007b1aa2886cf71bc602cff94583d11cc7e2a33786fcb74e
7
+ data.tar.gz: ec26884c0664c3f3b5ec8b57b5441d843f4a7781d35e6d827a09b502b5279a7119d0d4c95d4347b6b88f7f8cc6ff8f24bf9e7f740dba1947eec9cf44e3d3a511
data/lib/toss_payments.rb CHANGED
@@ -41,6 +41,16 @@ module TossPayments
41
41
  keyword_init: true,
42
42
  )
43
43
 
44
+ BillingResponseData = Struct.new(
45
+ :m_id,
46
+ :customer_key,
47
+ :authenticated_at,
48
+ :method,
49
+ :billing_key,
50
+ :card,
51
+ keyword_init: true,
52
+ )
53
+
44
54
  HOST = "https://api.tosspayments.com/v1"
45
55
 
46
56
  class Config
@@ -93,12 +103,12 @@ module TossPayments
93
103
 
94
104
  def billing_auth_card(payload = {})
95
105
  uri = "billing/authorizations/card"
96
- post(uri, payload)
106
+ post(uri, payload, type: :billing)
97
107
  end
98
108
 
99
109
  def billing_auth_issue(payload = {})
100
110
  uri = "billing/authorizations/issue"
101
- post(uri, payload)
111
+ post(uri, payload, type: :billing)
102
112
  end
103
113
 
104
114
  def billing(billing_key, payload = {})
@@ -112,27 +122,27 @@ module TossPayments
112
122
  { "Authorization": "Basic #{Base64.strict_encode64(config.secret_key)}:" }
113
123
  end
114
124
 
115
- def get(uri, payload = {})
125
+ def get(uri, payload = {}, type: :payment)
116
126
  url = "#{HOST}/#{uri}"
117
127
  response = HTTParty.get(url, headers: headers, body: payload).parsed_response
118
128
  {
119
129
  code: response["code"],
120
130
  message: response["message"],
121
- data: response_data_to_model(response["data"]),
131
+ data: type == :payment ? payment_response_data_to_model(response["data"]) : billing_response_data_to_model(response["data"]),
122
132
  }
123
133
  end
124
134
 
125
- def post
135
+ def post(uri, payload = {}, type: :payment)
126
136
  url = "#{HOST}/#{uri}"
127
137
  response = HTTParty.post(url, headers: headers.merge("Content-Type": "application/json"), body: payload.to_json).parsed_response
128
138
  {
129
139
  code: response["code"],
130
140
  message: response["message"],
131
- data: response_data_to_model(response["data"]),
141
+ data: type == :payment ? payment_response_data_to_model(response["data"]) : billing_response_data_to_model(response["data"]),
132
142
  }
133
143
  end
134
144
 
135
- def response_data_to_model(data)
145
+ def payment_response_data_to_model(data)
136
146
  return nil if data.nil?
137
147
  PaymentResponseData.new(
138
148
  version: data["version"],
@@ -235,5 +245,23 @@ module TossPayments
235
245
  } : nil,
236
246
  )
237
247
  end
248
+
249
+ def billing_response_data_to_model(data)
250
+ return nil if data.nil?
251
+ BillingResponseData.new(
252
+ m_id: data["mId"],
253
+ customer_key: data["customerKey"],
254
+ authenticated_at: Time.parse(data["authenticatedAt"]),
255
+ method: data["method"],
256
+ billing_key: data["billingKey"],
257
+ card: {
258
+ issuer_code: data["card"]["issuerCode"],
259
+ acquirer_code: data["card"]["acquirerCode"],
260
+ number: data["card"]["number"],
261
+ card_type: data["card"]["cardType"],
262
+ owner_type: data["card"]["ownerType"],
263
+ },
264
+ )
265
+ end
238
266
  end
239
267
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toss_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soohyeon Lee