Class: PaymentExecutionApiClient

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

Constant Summary collapse

PAYMENT_EXECUTION_ID_REQUIRED_ERROR =
'Payment Execution ID is required'

Instance Method Summary collapse

Methods inherited from BaseApiClient

parse_json, parse_void

Constructor Details

#initialize(config) ⇒ PaymentExecutionApiClient

Returns a new instance of PaymentExecutionApiClient.



19
20
21
# File 'lib/PCP-server-Ruby-SDK/api/payment_execution_api_client.rb', line 19

def initialize(config)
  super(config)
end

Instance Method Details

#cancel_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ Object

Raises:

  • (TypeError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/PCP-server-Ruby-SDK/api/payment_execution_api_client.rb', line 52

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)
  }

  make_api_call(url.to_s, request_init)
end

#capture_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ Object

Raises:

  • (TypeError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/PCP-server-Ruby-SDK/api/payment_execution_api_client.rb', line 37

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)
  }

  make_api_call(url.to_s, request_init)
end

#complete_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ Object

Raises:

  • (TypeError)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/PCP-server-Ruby-SDK/api/payment_execution_api_client.rb', line 82

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)
  }

  make_api_call(url.to_s, request_init)
end

#create_payment(merchant_id, commerce_case_id, checkout_id, payload) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/PCP-server-Ruby-SDK/api/payment_execution_api_client.rb', line 23

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)
  }

  make_api_call(url.to_s, request_init)
end

#refund_payment(merchant_id, commerce_case_id, checkout_id, payment_execution_id, payload) ⇒ Object

Raises:

  • (TypeError)


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

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)
  }

  make_api_call(url.to_s, request_init)
end