Class: PaymobAccept::Api::Base
- Inherits:
-
Object
- Object
- PaymobAccept::Api::Base
- Defined in:
- lib/paymob_accept/api/base.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#create_order(amount_cents:, amount_currency: 'EGP', auth_token: get_auth_token, delivery_needed: false, items: []) ⇒ Object
2.
-
#generate_payment_intent(customer:, address:, integration_id:, amount_cents:, amount_currency:, cc_token: nil, iframe_id: nil, order_id: nil, auth_token: get_auth_token) ⇒ Object
3.
-
#get_auth_token ⇒ Object
1.
-
#initialize(api_key:) ⇒ Base
constructor
A new instance of Base.
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_key ⇒ Object (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 |
#client ⇒ Object (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
-
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:, cc_token: nil, iframe_id: nil, order_id: nil, auth_token: get_auth_token) ⇒ Object
-
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:, cc_token: nil, 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, cc_token: cc_token) { token: format_bill_reference(payment_token, iframe_id), order_id: order_id } end |
#get_auth_token ⇒ Object
-
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 |