Class: Portmone::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/portmone/client.rb

Constant Summary collapse

API_URL =
'https://www.portmone.com.ua/gateway/'.freeze
MOBILE_API_URL =
'https://www.portmone.com.ua/r3/api/gateway/'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(payee_id:, login:, password:, locale:, currency:, exp_time: nil, timezone: 'Europe/Kiev', logger: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/portmone/client.rb', line 8

def initialize(payee_id:,
               login:,
               password:,
               locale:,
               currency:,
               exp_time: nil,
               timezone: 'Europe/Kiev',
               logger: nil)
  @payee_id = payee_id
  @login = 
  @password = password
  @locale = locale
  @currency = currency
  @timezone = timezone
  @logger = logger
  @exp_time = exp_time
end

Instance Method Details

#apple_pay(token:, amount:, order_id:, currency:, merchant_name:) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/portmone/client.rb', line 79

def apple_pay(token:, amount:, order_id:, currency:, merchant_name:)
  apple_pay_params = {
    aPayMerchantName: merchant_name,
    paymentData: token,
  }
  mobile_pay('APay', apple_pay_params, amount: amount, order_id: order_id, currency: currency)
end

#charge(order_id, amount) ⇒ Object



59
60
61
# File 'lib/portmone/client.rb', line 59

def charge(order_id, amount)
  generic_preauth_update(order_id: order_id, action: 'set_paid', amount: amount)
end

#finish_3ds(md:, pa_res:, shop_bill_id:) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/portmone/client.rb', line 87

def finish_3ds(md:, pa_res:, shop_bill_id:)
  params = {
    method: 'confirmMpi',
    params: { data: { 'MD': md.to_s, 'PaRes': pa_res.to_s, 'shopBillId': shop_bill_id.to_s } },
    id: '1',
  }
  make_json_request(MOBILE_API_URL, params, Portmone::Responses::Finish3DS)
end

#generate_url(shop_order_number:, amount:, description:, success_url:, failure_url:, authorize_only: true) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/portmone/client.rb', line 26

def generate_url(shop_order_number:, amount:, description:, success_url:, failure_url:, authorize_only: true)

  send_request(
    response_class: Portmone::Responses::GenerateURL,
    method: nil,
    shop_order_number: shop_order_number,
    bill_amount: format_amount(amount),
    bill_currency: @currency,
    description: description,
    success_url: success_url,
    failure_url: failure_url,
    encoding: 'utf-8',
    preauth_flag: authorize_only ? 'Y' : 'N',
    exp_time: @exp_time
  )
end

#google_pay(token:, amount:, order_id:, currency:) ⇒ Object



72
73
74
75
76
77
# File 'lib/portmone/client.rb', line 72

def google_pay(token:, amount:, order_id:, currency:)
  google_pay_params = {
    gPayToken: token,
  }
  mobile_pay('GPay', google_pay_params, amount: amount, order_id: order_id, currency: currency)
end

#order_status(shop_order_number, created_date: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/portmone/client.rb', line 43

def order_status(shop_order_number, created_date: nil)
  if created_date
    start_date = created_date - 1.day
    end_date = created_date + 1.day
    generic_report(shop_order_number: shop_order_number,
                   start_date: format_date(start_date),
                   end_date: format_date(end_date))
  else
    generic_report(shop_order_number: shop_order_number)
  end
end

#refund(order_id, amount:) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/portmone/client.rb', line 63

def refund(order_id, amount:)
  send_signed_request(
    response_class: Portmone::Responses::RefundOrderStatus,
    method: 'return',
    shop_bill_id: order_id,
    return_amount: format_amount(amount),
  )
end

#void(order_id) ⇒ Object



55
56
57
# File 'lib/portmone/client.rb', line 55

def void(order_id)
  generic_preauth_update(order_id: order_id, action: 'reject')
end