class PayU::Client
Public Class Methods
new(configuration, http_client)
click to toggle source
# File lib/pay_u/client.rb, line 9 def initialize(configuration, http_client) @configuration = configuration @http_client = http_client end
Public Instance Methods
cancel_order(order_id)
click to toggle source
# File lib/pay_u/client.rb, line 32 def cancel_order(order_id) orders_service.cancel_order(order_id, PayU::BaseRequest.new(headers)) end
place_order(buyer, products, total_amount, meta = {})
click to toggle source
# File lib/pay_u/client.rb, line 18 def place_order(buyer, products, total_amount, meta = {}) request_hash = order_meta(meta).merge({ buyer: buyer, products: products, total_amount: total_amount }) request = PayU::BaseRequest.new(headers, request_hash) orders_service.place_order(request) end
refund_order(order_id, amount = nil)
click to toggle source
# File lib/pay_u/client.rb, line 27 def refund_order(order_id, amount = nil) request_hash = { refund: { description: "Refund" } }.merge(refund_amount(amount)) orders_service.refund_order(order_id, PayU::BaseRequest.new(headers, request_hash)) end
Private Instance Methods
default_order_params()
click to toggle source
# File lib/pay_u/client.rb, line 50 def default_order_params { notify_url: @configuration.notify_url, merchant_pos_id: @configuration.pos_id } end
headers()
click to toggle source
# File lib/pay_u/client.rb, line 60 def headers { "Authorization" => "Bearer #{authorization.access_token}" } end
order_meta(meta)
click to toggle source
# File lib/pay_u/client.rb, line 42 def order_meta(meta) default_order_params.merge(meta) end
orders_service()
click to toggle source
# File lib/pay_u/client.rb, line 46 def orders_service @orders_service ||= Orders::Service.new(@http_client) end
refund_amount(amount)
click to toggle source
# File lib/pay_u/client.rb, line 38 def refund_amount(amount) amount.nil? ? {} : { amount: amount } end