Class: PaymobAccept::Api::Charge
- Inherits:
-
Base
- Object
- Base
- PaymobAccept::Api::Charge
show all
- Defined in:
- lib/paymob_accept/api/charge.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#api_key, #client
Instance Method Summary
collapse
Methods inherited from Base
#create_order, #generate_payment_intent, #get_auth_token
Constructor Details
#initialize(api_key: PaymobAccept.configuration.api_key) ⇒ Charge
Returns a new instance of Charge.
6
7
8
|
# File 'lib/paymob_accept/api/charge.rb', line 6
def initialize(api_key: PaymobAccept.configuration.api_key)
super(api_key: api_key)
end
|
Instance Attribute Details
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
4
5
6
|
# File 'lib/paymob_accept/api/charge.rb', line 4
def transaction_id
@transaction_id
end
|
Instance Method Details
#capture!(transaction_id:, amount_cents:) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/paymob_accept/api/charge.rb', line 15
def capture!(transaction_id:, amount_cents:)
body = {
auth_token: get_auth_token,
transaction_id: transaction_id,
amount_cents: amount_cents
}
@client.request('/acceptance/capture', body)
end
|
#charge(transaction_id:) ⇒ Object
10
11
12
13
|
# File 'lib/paymob_accept/api/charge.rb', line 10
def charge(transaction_id:)
response = @client.get(endpoint: "/acceptance/transactions/#{transaction_id}", headers: )
JSON.parse(response.body).to_h
end
|
#refund!(transaction_id:, amount_cents:) ⇒ Object
30
31
32
33
34
|
# File 'lib/paymob_accept/api/charge.rb', line 30
def refund!(transaction_id:, amount_cents:)
body = { auth_token: get_auth_token, transaction_id: transaction_id, amount_cents: amount_cents }
response = @client.request('/acceptance/void_refund/refund', body)
['true', true].include? response['success']
end
|
#void!(transaction_id:) ⇒ Object
24
25
26
27
28
|
# File 'lib/paymob_accept/api/charge.rb', line 24
def void!(transaction_id:)
body = { auth_token: get_auth_token, transaction_id: transaction_id }
response = @client.request('/acceptance/void_refund/void', body)
['true', true].include? response['success']
end
|