Class: Inttegro::Resources::PaymentMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/inttegro/resources/payment_methods.rb

Overview

Payment Methods resource for tokenizing and managing customer payment instruments.

Payment methods are saved payment instruments (mobile money wallets, cards, bank accounts) that customers can reuse across purchases. Use this resource to tokenize new payment methods, verify ownership, and manage the payment method lifecycle.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ PaymentMethods

Returns a new instance of PaymentMethods.



14
15
16
# File 'lib/inttegro/resources/payment_methods.rb', line 14

def initialize(http)
  @http = T.let(http, Inttegro::HTTPClient)
end

Instance Method Details

#activate(payment_method_id:) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/inttegro/resources/payment_methods.rb', line 159

def activate(payment_method_id:)
  @http.post_resource(
    "/payment_methods/activate",
    Inttegro::PaymentMethod, :payment_method,
    { payment_method_id: payment_method_id }
  )
end

#archive(payment_method_id:) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/inttegro/resources/payment_methods.rb', line 177

def archive(payment_method_id:)
  @http.post_resource(
    "/payment_methods/archive",
    Inttegro::PaymentMethod, :payment_method,
    { payment_method_id: payment_method_id }
  )
end

#confirm_verification(payload) ⇒ Inttegro::PaymentMethod

Submit the OTP received by the customer to complete payment method verification.

On success, the payment method's verified flag is set to true. Tokens expire after 8 minutes, and after 5 failed attempts, verification is locked—call verify() again to restart.

Examples:

Confirm verification with OTP

result = client.payment_methods.confirm_verification(
  payment_method_id: 'pm_xyz789',
  token: '123456'
)

if result.verified_at
  puts 'Payment method verified successfully!'
end

Parameters:

  • payload (Hash)

    Confirmation parameters

Options Hash (payload):

  • :payment_method_id (String)

    ID of the payment method being verified (required)

  • :token (String)

    OTP code provided by customer (required, typically 6 digits)

Returns:

See Also:



110
111
112
113
114
115
116
# File 'lib/inttegro/resources/payment_methods.rb', line 110

def confirm_verification(payload)
  @http.post_resource(
    "/payment_methods/confirm_verification",
    Inttegro::PaymentMethod, :payment_method,
    payload
  )
end

#delete(payment_method_id:, request_meta: nil) ⇒ Inttegro::PaymentMethodDeletion

Delete a saved payment method, removing it from the customer's account.

Permanently deletes the payment method. This action cannot be undone. Use when a customer requests removal of their payment details or when a payment method is no longer valid.

Examples:

Delete a payment method

result = client.payment_methods.delete(
  payment_method_id: 'pm_xyz789'
)

puts "Payment method deleted"

Parameters:

  • payment_method_id (String)

    ID of the payment method to delete (required)

  • request_meta (Hash, nil) (defaults to: nil)

    Request controls such as idempotency_key (optional)

Returns:

See Also:



211
212
213
214
215
216
217
218
# File 'lib/inttegro/resources/payment_methods.rb', line 211

def delete(payment_method_id:, request_meta: nil)
  @http.post_model("/payment_methods/delete", Inttegro::PaymentMethodDeletion,
    {
      payment_method_id: payment_method_id,
      request_meta: request_meta || stable_payment_method_request_meta("delete", payment_method_id)
    }
  )
end

#disactivate(payment_method_id:) ⇒ Object Also known as: deactivate



167
168
169
170
171
172
173
# File 'lib/inttegro/resources/payment_methods.rb', line 167

def disactivate(payment_method_id:)
  @http.post_resource(
    "/payment_methods/disactivate",
    Inttegro::PaymentMethod, :payment_method,
    { payment_method_id: payment_method_id }
  )
end

#lookup(payment_method_id:) ⇒ Inttegro::PaymentMethod

Retrieve details of a saved payment method by its ID.

Returns full payment method information including type, verification status, and associated customer. Use this to display saved payment methods to customers or verify payment method status.

Examples:

Lookup a payment method

result = client.payment_methods.lookup(
  payment_method_id: 'pm_xyz789'
)

puts "Payment method type: #{result.type&.serialize}"

Parameters:

  • payment_method_id (String)

    ID of the payment method to retrieve (required)

Returns:

See Also:



135
136
137
138
139
140
141
# File 'lib/inttegro/resources/payment_methods.rb', line 135

def lookup(payment_method_id:)
  @http.post_resource(
    "/payment_methods/lookup",
    Inttegro::PaymentMethod, :payment_method,
    { payment_method_id: payment_method_id }
  )
end

#page(payload = {}) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/inttegro/resources/payment_methods.rb', line 143

def page(payload = {})
  @http.post_resource(
    "/payment_methods/page",
    Inttegro::PaymentMethodPage, :page,
    payload || {}
  )
end

#settingsInttegro::PaymentMethodSettings

Get configuration settings for payment methods in your application.

Returns settings that control payment method behavior, including whether verification is required before charging and supported payment method types.

Examples:

Get payment method settings

result = client.payment_methods.settings

puts "Mobile money enabled: #{result.mobile_money&.enabled}"

Returns:

See Also:



233
234
235
236
237
238
239
# File 'lib/inttegro/resources/payment_methods.rb', line 233

def settings
  @http.post_resource(
    "/payment_methods/settings",
    Inttegro::PaymentMethodSettings, :settings,
    {}
  )
end

#tokenize(payload) ⇒ Inttegro::PaymentMethod

Save a new payment method for a customer without charging it.

Tokenizes and stores payment details for future use. Currently supports mobile money wallets. Use this to collect payment details during customer onboarding, let customers save multiple payment instruments, or set up payment methods before subscription billing.

After tokenization, you can optionally verify the payment method to confirm customer ownership and enable frictionless charging.

Examples:

Tokenize a mobile money payment method

result = client.payment_methods.tokenize(
  customer_id: 'cu_abc123',
  payment_method_data: {
    type: 'mobile_money',
    mobile_money: {
      network: 'mtn',
      account_number: '0544998605'
    }
  },
  verify_immediately: true
)

puts "Tokenized payment method: #{result.id}"

Parameters:

  • payload (Hash)

    Tokenization parameters

Options Hash (payload):

  • :customer_id (String)

    Customer who will own this payment method (required)

  • :payment_method_data (Hash)

    Payment method details (required)

  • :verify_immediately (Boolean)

    Send verification OTP immediately (default: false)

Returns:

See Also:



50
51
52
53
54
55
56
# File 'lib/inttegro/resources/payment_methods.rb', line 50

def tokenize(payload)
  @http.post_resource(
    "/payment_methods/tokenize",
    Inttegro::PaymentMethod, :payment_method,
    payload
  )
end

#unarchive(payment_method_id:) ⇒ Object



185
186
187
188
189
190
191
# File 'lib/inttegro/resources/payment_methods.rb', line 185

def unarchive(payment_method_id:)
  @http.post_resource(
    "/payment_methods/unarchive",
    Inttegro::PaymentMethod, :payment_method,
    { payment_method_id: payment_method_id }
  )
end

#update(payload) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/inttegro/resources/payment_methods.rb', line 151

def update(payload)
  @http.post_resource(
    "/payment_methods/update",
    Inttegro::PaymentMethod, :payment_method,
    payload
  )
end

#verify(payment_method_id:, request_meta: nil) ⇒ Inttegro::PaymentMethodVerification

Send an OTP to confirm customer ownership of a payment method.

For mobile money, a 6-digit code is sent via SMS to the registered wallet number. The customer submits the token to complete verification. Verified payment methods can be charged without additional OTP confirmation, meet network provider requirements, and have better authorization rates.

Examples:

Verify a payment method

result = client.payment_methods.verify(
  payment_method_id: 'pm_xyz789'
)

puts "Verification request: #{result.request_id}"

Parameters:

  • payment_method_id (String)

    ID of the payment method to verify (required)

  • request_meta (Hash, nil) (defaults to: nil)

    Request controls such as idempotency_key (optional)

Returns:

See Also:



77
78
79
80
81
82
83
84
85
86
# File 'lib/inttegro/resources/payment_methods.rb', line 77

def verify(payment_method_id:, request_meta: nil)
  @http.post_resource(
    "/payment_methods/verify",
    Inttegro::PaymentMethodVerification, :verification,
    {
      payment_method_id: payment_method_id,
      request_meta: request_meta || stable_payment_method_request_meta("verify", payment_method_id)
    }
  )
end