class PayPoint::Blue::API

Client class for the API product.

Constants

ENDPOINTS

Public Instance Methods

cancel_authorisation(transaction_id, **payload) click to toggle source

Cancel an authorisation

@api_url developer.paypoint.com/payments/docs/#payments/cancel_an_authorisation

@applies_defaults

+:commerce_type+, +:pre_auth_callback+, +:post_auth_callback+,
+:transaction_notification+, +:expiry_notification+

@param (see capture_authorisation)

@return the API response

# File lib/paypoint/blue/api.rb, line 104
def cancel_authorisation(transaction_id, **payload)
  payload = build_payload payload, defaults: %i(
    commerce_type pre_auth_callback post_auth_callback
    transaction_notification expiry_notification
  )
  client.post "transactions/#{inst_id}/#{transaction_id}/cancel", payload
end
capture_authorisation(transaction_id, **payload) click to toggle source

Capture an authorisation

@api_url developer.paypoint.com/payments/docs/#payments/capture_an_authorisation

@applies_defaults

+:commerce_type+, +:pre_auth_callback+, +:post_auth_callback+,
+:transaction_notification+, +:expiry_notification+

@param [String] transaction_id the id of the previous transaction @param [Hash] payload the payload is made up of the keyword

arguments passed to the method

@return the API response

# File lib/paypoint/blue/api.rb, line 85
def capture_authorisation(transaction_id, **payload)
  payload = build_payload payload, defaults: %i(
    commerce_type pre_auth_callback post_auth_callback
    transaction_notification expiry_notification
  )
  client.post "transactions/#{inst_id}/#{transaction_id}/capture", payload
end
customer(customer_id) click to toggle source

Get details of a customer

@api_url developer.paypoint.com/payments/docs/#customers/request_customer_and_cards

@param [String] customer_id the id of the customer as assigned by PayPoint

@return the API response

# File lib/paypoint/blue/api.rb, line 195
def customer(customer_id)
  client.get "customers/#{inst_id}/#{customer_id}"
end
customer_by_ref(customer_ref) click to toggle source

Get details of a customer by merchant reference

@api_url developer.paypoint.com/payments/docs/#customers/request_customer_and_cards

@param [String] customer_ref the merchant reference for the customer

@return the API response

# File lib/paypoint/blue/api.rb, line 206
def customer_by_ref(customer_ref)
  client.get "customers/#{inst_id}/byRef?merchantRef=#{customer_ref}"
end
customer_payment_method(customer_id, token) click to toggle source

Get a specific registered payment method of a customer

@api_url developer.paypoint.com/payments/docs/#customers/request_customer_and_cards

@param [String] customer_id the id of the customer as assigned by PayPoint @param [String] token the token identifying the payment method

@return the API response

# File lib/paypoint/blue/api.rb, line 229
def customer_payment_method(customer_id, token)
  client.get "customers/#{inst_id}/#{customer_id}/paymentMethods/#{token}"
end
customer_payment_methods(customer_id) click to toggle source

Get the list of the registered payment methods of a customer

@api_url developer.paypoint.com/payments/docs/#customers/request_customer_and_cards

@param [String] customer_id the id of the customer as assigned by PayPoint

@return the API response

# File lib/paypoint/blue/api.rb, line 217
def customer_payment_methods(customer_id)
  client.get "customers/#{inst_id}/#{customer_id}/paymentMethods"
end
make_payment(**payload) click to toggle source

Make a payment

@api_url developer.paypoint.com/payments/docs/#payments/make_a_payment

@applies_defaults

+:currency+, +:commerce_type+, +:pre_auth_callback+,
+:post_auth_callback+, +:transaction_notification+,
+:expiry_notification+

@param [Hash] payload the payload is made up of the keyword

arguments passed to the method

@return the API response

# File lib/paypoint/blue/api.rb, line 47
def make_payment(**payload)
  payload = build_payload payload, defaults: %i(
    currency commerce_type pre_auth_callback post_auth_callback
    transaction_notification expiry_notification customer_registration
  )
  client.post "transactions/#{inst_id}/payment", payload
end
ping() click to toggle source

Test connectivity

@return [true,false]

# File lib/paypoint/blue/api.rb, line 27
def ping
  client.get "transactions/ping"
  true
rescue Faraday::ClientError
  false
end
refund_payment(transaction_id, **payload) click to toggle source

Refund a payment

@api_url developer.paypoint.com/payments/docs/#payments/refund_a_payment

Without a payload this will refund the full amount. If you only want to refund a smaller amount, you will need to pass either the amount or a transaction hash as a keyword argument.

@example Partial refund

blue.refund_payment(txn_id, amount: '3.49') # assumes a default currency

@applies_defaults

only if amount is set: +:currency+, +:commerce_type+

@applies_defaults

+:pre_auth_callback+, +:post_auth_callback+,
+:transaction_notification+, +:expiry_notification+

@param (see capture_authorisation)

@return the API response

# File lib/paypoint/blue/api.rb, line 154
def refund_payment(transaction_id, **payload)
  defaults = %i(
    pre_auth_callback post_auth_callback
    transaction_notification expiry_notification
  )
  if payload[:amount] ||
      payload[:transaction] && payload[:transaction][:amount]
    defaults += %i(currency commerce_type)
  end
  payload = build_payload(payload, defaults: defaults)
  client.post "transactions/#{inst_id}/#{transaction_id}/refund", payload
end
remove_card(customer_id, token) click to toggle source

Remove card

# File lib/paypoint/blue/api.rb, line 234
def remove_card(customer_id, token)
  client.post "customers/#{inst_id}/#{customer_id}/paymentMethod/#{token}/remove"
end
submit_authorisation(**payload) click to toggle source

Submit an authorisation

@api_url developer.paypoint.com/payments/docs/#payments/submit_an_authorisation @see make_payment

This is a convenience method which makes a payment with the transaction's deferred value set to true.

@param (see make_payment)

@return the API response

# File lib/paypoint/blue/api.rb, line 66
def submit_authorisation(**payload)
  payload[:transaction] ||= {}
  payload[:transaction][:deferred] = true
  make_payment(**payload)
end
submit_payout(**payload) click to toggle source

Submit a payout

@api_url developer.paypoint.com/payments/docs/#payments/submit_a_payout

@applies_defaults

+:currency+, +:commerce_type+, +:pre_auth_callback+,
+:post_auth_callback+, +:transaction_notification+,
+:expiry_notification+

@param [Hash] payload the payload is made up of the keyword

arguments passed to the method

@return the API response

# File lib/paypoint/blue/api.rb, line 180
def submit_payout(**payload)
  payload = build_payload payload, defaults: %i(
    currency commerce_type pre_auth_callback post_auth_callback
    transaction_notification expiry_notification
  )
  client.post "transactions/#{inst_id}/payout", payload
end
transaction(transaction_id) click to toggle source

Get transaction details

@api_url developer.paypoint.com/payments/docs/#payments/request_a_previous_transaction

@param [String] transaction_id the id of the transaction

@return the API response

# File lib/paypoint/blue/api.rb, line 119
def transaction(transaction_id)
  client.get "transactions/#{inst_id}/#{transaction_id}"
end
transactions_by_ref(merchant_ref) click to toggle source

Get transaction details by merchant reference

@api_url developer.paypoint.com/payments/docs/#payments/request_a_previous_transaction

@param [String] merchant_ref the merchant reference for the transactions

@return the API response

# File lib/paypoint/blue/api.rb, line 130
def transactions_by_ref(merchant_ref)
  client.get "transactions/#{inst_id}/byRef?merchantRef=#{merchant_ref}"
end