Class: PCPServerSDK::Endpoints::PaymentExecutionApiClient

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

Constant Summary collapse

PAYMENT_EXECUTION_ID_REQUIRED_ERROR =
'Payment Execution ID is required'

Instance Attribute Summary

Attributes inherited from BaseApiClient

#http_client

Instance Method Summary collapse

Constructor Details

#initialize(config, http_client = nil) ⇒ PaymentExecutionApiClient

Returns a new instance of PaymentExecutionApiClient.



17
18
19
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 17

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

Instance Method Details

#cancel_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::CancelPaymentResponse

Cancel a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::CancelPaymentRequest)

    The cancel payment request

Returns:

Raises:

  • (TypeError)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 72

def cancel_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

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

  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::CancelPaymentResponse)
end

#capture_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::CapturePaymentResponse

Capture a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::CapturePaymentRequest)

    The capture payment request

Returns:

Raises:

  • (TypeError)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 49

def capture_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

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

  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::CapturePaymentResponse)
end

#complete_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::CompletePaymentResponse

Complete a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::CompletePaymentRequest)

    The complete payment request

Returns:

Raises:

  • (TypeError)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 118

def complete_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

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

  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::CompletePaymentResponse)
end

#create_fund_split(merchant_id, commerce_case_id, checkout_id, payment_execution_id, event_id, payload) ⇒ PCPServerSDK::Models::FundSplitResponse

Create a fund split for a payment event

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • event_id (String)

    The payment event identifier

  • payload (PCPServerSDK::Models::FundSplitRequest)

    The fund split request

Returns:

Raises:

  • (TypeError)


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 188

def create_fund_split(merchant_id, commerce_case_id, checkout_id, payment_execution_id, event_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?
  raise TypeError, 'Event ID is required' if event_id.nil? || event_id.empty?

  url = URI.join(get_config.host, "/v1/#{merchant_id}/commerce-cases/#{commerce_case_id}/checkouts/#{checkout_id}/payment-executions/#{payment_execution_id}/events/#{event_id}/fund-splits")

  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::FundSplitResponse)
end

#create_payment(merchant_id, commerce_case_id, checkout_id, payload) ⇒ PCPServerSDK::Models::CreatePaymentResponse

Create a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payload (PCPServerSDK::Models::PaymentExecutionRequest)

    The payment execution request

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 27

def create_payment(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-executions")

  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::CreatePaymentResponse)
end

#pause_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::PausePaymentResponse

Pause a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::PausePaymentRequest)

    The pause payment request

Returns:

Raises:

  • (TypeError)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 141

def pause_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

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

  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::PausePaymentResponse)
end

#refresh_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::PaymentExecution

Refresh a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::RefreshPaymentRequest)

    The refresh payment request

Returns:

Raises:

  • (TypeError)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 164

def refresh_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

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

  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::PaymentExecution)
end

#refund_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ PCPServerSDK::Models::RefundPaymentResponse

Refund a payment

Parameters:

  • merchant_id (String)

    The merchant identifier

  • commerce_case_id (String)

    The commerce case identifier

  • checkout_id (String)

    The checkout identifier

  • payment_execution_id (String)

    The payment execution identifier

  • payload (PCPServerSDK::Models::RefundRequest)

    The refund request

Returns:

Raises:

  • (TypeError)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/PCP-server-Ruby-SDK/endpoints/payment_execution_api_client.rb', line 95

def refund_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload)
  validate_ids(merchant_id, commerce_case_id, checkout_id)
  raise TypeError, PAYMENT_EXECUTION_ID_REQUIRED_ERROR if payment_execution_id.nil? || payment_execution_id.empty?

  url = URI.join(get_config.host, "/v1/#{merchant_id}/commerce-cases/#{commerce_case_id}/checkouts/#{checkout_id}/payment-executions/#{payment_execution_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::RefundPaymentResponse)
end