module Iamport

Constants

IAMPORT_HOST
VERSION

Public Class Methods

cancel(body) click to toggle source

Canceled payments api.iamport.kr/#!/payments/cancelPayment

# File lib/iamport.rb, line 82
def cancel(body)
  uri = "payments/cancel"

  pay_post(uri, body)
end
config() click to toggle source
# File lib/iamport.rb, line 17
def config
  @config ||= Config.new
end
configure() { |config| ... } click to toggle source
# File lib/iamport.rb, line 13
def configure
  yield(config) if block_given?
end
create_customer(customer_uid, payload = {}) click to toggle source
# File lib/iamport.rb, line 125
def create_customer(customer_uid, payload = {})
  uri = "subscribe/customers/#{customer_uid}"

  pay_post(uri, payload)
end
create_onetime_payment(payload = {}) click to toggle source

create onetime POST api.iamport.kr/#!/subscribe/payments/onetime

# File lib/iamport.rb, line 90
def create_onetime_payment(payload = {})
  uri = "subscribe/payments/onetime"

  pay_post(uri, payload)
end
create_payment_again(payload = {}) click to toggle source

create payment again POST api.iamport.kr/#!/subscribe/payments/again

# File lib/iamport.rb, line 103
def create_payment_again(payload = {})
  uri = "subscribe/payments/again"

  pay_post(uri, payload)
end
create_subscribe_customer(customer_uid, payload = {}) click to toggle source
# File lib/iamport.rb, line 120
def create_subscribe_customer(customer_uid, payload = {})
  warn "[DEPRECATION] `create_subscribe_customer` is deprecated.  Please use `create_customer` instead."
  create_customer(customer_uid, payload)
end
customer_payments(customer_uid) click to toggle source
# File lib/iamport.rb, line 131
def customer_payments(customer_uid)
  uri = "subscribe/customers/#{customer_uid}/payments"

  pay_get(uri)
end
find(merchant_uid) click to toggle source

Find payment information using merchant uid api.iamport.kr/#!/payments/getPaymentByMerchantUid

# File lib/iamport.rb, line 58
def find(merchant_uid)
  uri = "payments/find/#{merchant_uid}"

  pay_get(uri)
end
find_subscribe_customer(customer_uid) click to toggle source
# File lib/iamport.rb, line 96
def find_subscribe_customer(customer_uid)
  warn "[DEPRECATION] `find_subscribe_customer` is deprecated.  Please use `customer_payments` instead."
  customer_payments(customer_uid)
end
payment(imp_uid) click to toggle source

Get payment information using imp_uid api.iamport.kr/#!/payments/getPaymentByImpUid

# File lib/iamport.rb, line 38
def payment(imp_uid)
  uri = "payments/#{imp_uid}"

  pay_get(uri)
end
payments(options = {}) click to toggle source

Search payment information using status. default items per page: 20 api.iamport.kr/#!/payments/getPaymentsByStatus

# File lib/iamport.rb, line 47
def payments(options = {})
  status = options[:status] || "all"
  page = options[:page] || 1

  uri = "payments/status/#{status}?page=#{page}"

  pay_get(uri)
end
prepare(body) click to toggle source

Prepare payment validation api.iamport.kr/#!/payments/prepare

# File lib/iamport.rb, line 66
def prepare(body)
  uri = "payments/prepare"

  pay_post(uri, body)
end
prepared(merchant_uid) click to toggle source

Get prepared payment information by merchant_uid api.iamport.kr/#!/payments/prepare/:merchant_uid

# File lib/iamport.rb, line 74
def prepared(merchant_uid)
  uri = "payments/prepare/#{merchant_uid}"

  pay_get(uri)
end
token() click to toggle source

Get Token api.iamport.kr/#!/authenticate/getToken

# File lib/iamport.rb, line 23
def token
  url = "#{IAMPORT_HOST}/users/getToken"
  body = {
    imp_key: config.api_key,
    imp_secret: config.api_secret
  }

  result = HTTParty.post url, body: body

  raise "Invalid Token" unless result["response"]
  result["response"]["access_token"]
end

Private Class Methods

headers() click to toggle source

Get header data

# File lib/iamport.rb, line 140
def headers
  { "Authorization" => token }
end
pay_delete(uri, payload = {}) click to toggle source

DELETE

# File lib/iamport.rb, line 157
def pay_delete(uri, payload = {})
  url = "#{IAMPORT_HOST}/#{uri}"
  HTTParty.delete(url, headers: headers, body: payload)
end
pay_get(uri, payload = {}) click to toggle source

GET

# File lib/iamport.rb, line 145
def pay_get(uri, payload = {})
  url = "#{IAMPORT_HOST}/#{uri}"
  HTTParty.get(url, headers: headers, body: payload)
end
pay_post(uri, payload = {}) click to toggle source

POST

# File lib/iamport.rb, line 151
def pay_post(uri, payload = {})
  url = "#{IAMPORT_HOST}/#{uri}"
  HTTParty.post(url, headers: headers, body: payload)
end