Class: PCPServerSDK::Endpoints::PaymentInformationApiClient

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

Constant Summary collapse

PAYMENT_INFORMATION_ID_REQUIRED_ERROR =
'Payment Information ID is required'

Instance Attribute Summary

Attributes inherited from BaseApiClient

#http_client

Instance Method Summary collapse

Constructor Details

#initialize(config, http_client = nil) ⇒ PaymentInformationApiClient

Returns a new instance of PaymentInformationApiClient.



14
15
16
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb', line 14

def initialize(config, http_client = nil)
  super(config, http_client)
end

Instance Method Details

#create_payment_information(merchant_id, commerce_case_id, checkout_id, payload) ⇒ PCPServerSDK::Models::PaymentInformationResponse

Create a payment information

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payload (PCPServerSDK::Models::PaymentInformationRequest)

    The payment information request

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb', line 24

def create_payment_information(merchant_id, commerce_case_id, checkout_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)

  url = URI.join(get_config.host, "/v1/#{merchant_id}/commerce-cases/#{commerce_case_id}/checkouts/#{checkout_id}/payment-information")

  request_init = {
    method: 'POST',
    headers: { 'Content-Type' => 'application/json' },
    body: JSON.generate(payload)
  }

  response = make_api_call(url.to_s, request_init)
  deserialize_json(response, PCPServerSDK::Models::PaymentInformationResponse)
end

#get_payment_information(merchant_id, commerce_case_id, checkout_id, payment_information_id) ⇒ PCPServerSDK::Models::PaymentInformationResponse

Get a payment information

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_information_id (String)

    The payment information identifier

Returns:

Raises:

  • (TypeError)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb', line 45

def get_payment_information(merchant_id, commerce_case_id, checkout_id, payment_information_id)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_INFORMATION_ID_REQUIRED_ERROR if payment_information_id.nil? || payment_information_id.empty?

  url = URI.join(get_config.host, "/v1/#{merchant_id}/commerce-cases/#{commerce_case_id}/checkouts/#{checkout_id}/payment-information/#{payment_information_id}")

  request_init = {
    method: 'GET',
    headers: {}
  }

  response = make_api_call(url.to_s, request_init)
  deserialize_json(response, PCPServerSDK::Models::PaymentInformationResponse)
end

#refund_payment_information(merchant_id, commerce_case_id, checkout_id, payment_information_id, payload) ⇒ PCPServerSDK::Models::PaymentInformationRefundResponse

Refund a payment information

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_information_id (String)

    The payment information identifier

  • payload (PCPServerSDK::Models::PaymentInformationRefundRequest)

    The refund request

Returns:

Raises:

  • (TypeError)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_information_api_client.rb', line 67

def refund_payment_information(merchant_id, commerce_case_id, checkout_id, payment_information_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_INFORMATION_ID_REQUIRED_ERROR if payment_information_id.nil? || payment_information_id.empty?
  raise TypeError, PAYLOAD_REQUIRED_ERROR if payload.nil?

  url = URI.join(get_config.host, "/v1/#{merchant_id}/commerce-cases/#{commerce_case_id}/checkouts/#{checkout_id}/payment-information/#{payment_information_id}/refund")

  request_init = {
    method: 'POST',
    headers: { 'Content-Type' => 'application/json' },
    body: JSON.generate(payload)
  }

  response = make_api_call(url.to_s, request_init)
  deserialize_json(response, PCPServerSDK::Models::PaymentInformationRefundResponse)
end