Class: PCPServerSDK::Endpoints::PaymentIntentApiClient

Inherits:
BaseApiClient
  • Object
show all
Defined in:
lib/PCP-server-Ruby-SDK/endpoints/payment_intent_api_client.rb

Constant Summary collapse

PAYMENT_INTENT_ID_REQUIRED_ERROR =
'Payment Intent ID is required'

Instance Attribute Summary

Attributes inherited from BaseApiClient

#http_client

Instance Method Summary collapse

Methods inherited from BaseApiClient

#initialize

Constructor Details

This class inherits a constructor from PCPServerSDK::Endpoints::BaseApiClient

Instance Method Details

#create_payment_intent(merchant_id, payload) ⇒ Object

Raises:

  • (TypeError)


18
19
20
21
22
23
24
25
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_intent_api_client.rb', line 18

def create_payment_intent(merchant_id, payload)
  raise TypeError, MERCHANT_ID_REQUIRED_ERROR if merchant_id.nil? || merchant_id.empty?
  raise TypeError, PAYLOAD_REQUIRED_ERROR if payload.nil?

  response = make_api_call(URI.join(get_config.host, "/v1/#{merchant_id}/payment-intents").to_s,
                           method: 'POST', headers: { 'Content-Type' => 'application/json' }, body: JSON.generate(payload))
  deserialize_json(response, PCPServerSDK::Models::CreatePaymentIntentResponse)
end

#get_payment_intent(merchant_id, payment_intent_id) ⇒ Object

Raises:

  • (TypeError)


27
28
29
30
31
32
33
34
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_intent_api_client.rb', line 27

def get_payment_intent(merchant_id, payment_intent_id)
  raise TypeError, MERCHANT_ID_REQUIRED_ERROR if merchant_id.nil? || merchant_id.empty?
  raise TypeError, PAYMENT_INTENT_ID_REQUIRED_ERROR if payment_intent_id.nil? || payment_intent_id.empty?

  response = make_api_call(URI.join(get_config.host, "/v1/#{merchant_id}/payment-intents/#{payment_intent_id}").to_s,
                           method: 'GET', headers: {})
  deserialize_json(response, PCPServerSDK::Models::PaymentIntentResponse)
end