Class: Solidgate::Payment
- Inherits:
-
Object
- Object
- Solidgate::Payment
- Defined in:
- lib/solidgate/payment.rb
Overview
Payment resource for handling payment-related operations
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#capture(payment_id, amount: nil) ⇒ Hash
Capture a previously authorized payment.
-
#create(params) ⇒ Hash
Create a new payment charge.
-
#get(payment_id) ⇒ Hash
Retrieve payment information.
-
#initialize(client = nil) ⇒ Payment
constructor
A new instance of Payment.
-
#refund(payment_id, amount: nil, reason: nil) ⇒ Hash
Refund a payment (full or partial).
-
#void(payment_id) ⇒ Hash
Void a payment (cancel an authorization).
Constructor Details
#initialize(client = nil) ⇒ Payment
Returns a new instance of Payment.
8 9 10 |
# File 'lib/solidgate/payment.rb', line 8 def initialize(client = nil) @client = client || Solidgate.client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/solidgate/payment.rb', line 6 def client @client end |
Instance Method Details
#capture(payment_id, amount: nil) ⇒ Hash
Capture a previously authorized payment
42 43 44 45 46 47 48 49 |
# File 'lib/solidgate/payment.rb', line 42 def capture(payment_id, amount: nil) raise ArgumentError, "payment_id is required" if payment_id.nil? || payment_id.empty? params = {} params[:amount] = amount if amount client.capture_payment(payment_id, params) end |
#create(params) ⇒ Hash
Create a new payment charge
22 23 24 25 |
# File 'lib/solidgate/payment.rb', line 22 def create(params) validate_create_params(params) client.create_payment(params) end |
#get(payment_id) ⇒ Hash
Retrieve payment information
31 32 33 34 35 |
# File 'lib/solidgate/payment.rb', line 31 def get(payment_id) raise ArgumentError, "payment_id is required" if payment_id.nil? || payment_id.empty? client.get_payment(payment_id) end |
#refund(payment_id, amount: nil, reason: nil) ⇒ Hash
Refund a payment (full or partial)
67 68 69 70 71 72 73 74 75 |
# File 'lib/solidgate/payment.rb', line 67 def refund(payment_id, amount: nil, reason: nil) raise ArgumentError, "payment_id is required" if payment_id.nil? || payment_id.empty? params = {} params[:amount] = amount if amount params[:reason] = reason if reason client.refund_payment(payment_id, params) end |
#void(payment_id) ⇒ Hash
Void a payment (cancel an authorization)
55 56 57 58 59 |
# File 'lib/solidgate/payment.rb', line 55 def void(payment_id) raise ArgumentError, "payment_id is required" if payment_id.nil? || payment_id.empty? client.void_payment(payment_id) end |