Class: Solidgate::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/solidgate/payment.rb

Overview

Payment resource for handling payment-related operations

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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

Parameters:

  • payment_id (String)

    payment ID

  • amount (Integer) (defaults to: nil)

    amount to capture in cents (optional, defaults to full amount)

Returns:

  • (Hash)

    capture response

Raises:

  • (ArgumentError)


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

Parameters:

  • params (Hash)

    payment parameters

Options Hash (params):

  • :order_id (String)

    unique order identifier

  • :amount (Integer)

    amount in cents

  • :currency (String)

    currency code (e.g., “USD”)

  • :card_data (Hash)

    card information

  • :customer (Hash)

    customer information

  • :description (String)

    payment description

Returns:

  • (Hash)

    payment response



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

Parameters:

  • payment_id (String)

    payment ID

Returns:

  • (Hash)

    payment details

Raises:

  • (ArgumentError)


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)

Parameters:

  • payment_id (String)

    payment ID

  • amount (Integer) (defaults to: nil)

    amount to refund in cents (optional, defaults to full amount)

  • reason (String) (defaults to: nil)

    refund reason (optional)

Returns:

  • (Hash)

    refund response

Raises:

  • (ArgumentError)


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)

Parameters:

  • payment_id (String)

    payment ID

Returns:

  • (Hash)

    void response

Raises:

  • (ArgumentError)


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