Class: PaymobAccept::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paymob_accept/api/base.rb

Direct Known Subclasses

Charge, Pay

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/paymob_accept/api/base.rb', line 6

def initialize(api_key:)
  @client = PaymobAccept::Api::Client.new
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



4
5
6
# File 'lib/paymob_accept/api/base.rb', line 4

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/paymob_accept/api/base.rb', line 4

def client
  @client
end

Instance Method Details

#create_order(amount_cents:, amount_currency: 'EGP', auth_token: get_auth_token, delivery_needed: false, items: []) ⇒ Object

  1. Order Registration API



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/paymob_accept/api/base.rb', line 18

def create_order(amount_cents:, amount_currency: 'EGP', auth_token: get_auth_token,
                 delivery_needed: false, items: [])
  body = {
    "auth_token": auth_token,
    "delivery_needed": delivery_needed,
    "amount_cents": amount_cents.to_i,
    "currency": amount_currency,
    "items": items
  }
  @client.request('/ecommerce/orders', body)
end

#generate_payment_intent(customer:, address:, integration_id:, amount_cents:, amount_currency:, iframe_id: nil, order_id: nil, auth_token: get_auth_token) ⇒ Object

  1. Payment Key Request



31
32
33
34
35
36
37
38
39
40
# File 'lib/paymob_accept/api/base.rb', line 31

def generate_payment_intent(customer:, address:, integration_id:, amount_cents:, amount_currency:, iframe_id: nil, order_id: nil, auth_token: get_auth_token)
  if order_id.nil?
    order = create_order(amount_cents: amount_cents, amount_currency: amount_currency)
    order_id = order['id']
  end
  payment_token = generate_payment_key(auth_token: auth_token, customer: customer, address: address, order_id: order_id, amount_cents: amount_cents, amount_currency: amount_currency,
                                       integration_id: integration_id)

  format_bill_reference(payment_token, iframe_id)
end

#get_auth_tokenObject

  1. Authentication Request



12
13
14
15
# File 'lib/paymob_accept/api/base.rb', line 12

def get_auth_token
  response = @client.request('/auth/tokens', { api_key: api_key })
  response['token']
end