Class: Walletone::Invoicing::Client

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

Constant Summary collapse

CABINET_ID =

yessplaycheckout

'checkout'
OPERATORS =
%w(MtsRUB MegafonRUB Tele2RUB BeelineRUB)
BASE_URL =
"https://wl.walletone.com/#{CABINET_ID}/invoicingapi/"

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, secret_key:, hash_type: Walletone::Signer::DEFAULT_HASH_TYPE) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
# File 'lib/walletone/invoicing/client.rb', line 14

def initialize(user_id:, secret_key:, hash_type: Walletone::Signer::DEFAULT_HASH_TYPE)
  @user_id    = user_id or fail 'no user_id'
  @user_id    = @user_id.to_s
  @secret_key = secret_key or fail 'no secret_key'
  @hash_type  = hash_type or fail 'no hash_type'
  @timestamp  = Time.now.utc.strftime('%FT%T')
end

Instance Method Details

#do_phone_payment(amount:, order_id:, phone:, additional_params:) ⇒ Object



22
23
24
25
# File 'lib/walletone/invoicing/client.rb', line 22

def do_phone_payment(amount:, order_id:, phone: ,additional_params:)
  invoice = make_invoice amount: amount, order_id: order_id, additional_params: additional_params
  make_payments_process_with_phone payment_id: invoice['Invoice']['Payment']['PaymentId'], phone: phone
end

#make_invoice(invoice) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/walletone/invoicing/client.rb', line 46

def make_invoice(invoice)
  fail 'Must be a RecurrentInvoice' unless invoice.is_a? Walletone::Recurrent::Invoice

  body = {
    'OrderId'       => invoice.OrderId.to_s,
    'Amount'        => invoice.Amount.to_f,
    'CurrencyId'    => invoice.CurrencyId,
    'PaymentTypeId' => invoice.PaymentTypeId
  }

  body['InvoiceAdditionalParams'] = invoice.InvoiceAdditionalParams if invoice.InvoiceAdditionalParams.is_a?(Hash) && !invoice.InvoiceAdditionalParams.empty?

  make_request 'invoices', body.to_json
end

#make_payments_process(payment_id, params = {}) ⇒ Object

Для рекурентов { “CustomerId”:“123456”, “UseSavedAuthData”:true, “CreditCardTerminal”:Non3Ds, “AuthData”: [

"RecurrentCreditCardAuthSecurityCode":"123"

] }



37
38
39
40
# File 'lib/walletone/invoicing/client.rb', line 37

def make_payments_process(payment_id, params = {})
  fail 'must be payment_id' unless payment_id
  make_request "payments/#{payment_id}/process", params.to_json
end

#make_payments_process_with_phone(payment_id:, customer_id:, phone:) ⇒ Object



42
43
44
# File 'lib/walletone/invoicing/client.rb', line 42

def make_payments_process_with_phone(payment_id:, customer_id:, phone:)
  make_payments_process payment_id, { 'CustomerId' => customer_id, 'AuthData' => { 'MobileCommercePhoneNumber' => phone } }
end