Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/checkout_sdk/payments/setups/bacs_payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Payments
# Bacs payment method configuration on a Payment Setup. Maps swagger `Bacs`.
#
# @!attribute status
# @return [String] (response-only) Payment method status.
# @return [String] (response-only) Payment method status, one of
# {PaymentSetupPaymentMethodStatus} (e.g. "ready").
# @!attribute flags
# @return [Array(String)] (response-only) Diagnostic flags returned by the API.
# @!attribute initialization
Expand Down
5 changes: 3 additions & 2 deletions lib/checkout_sdk/payments/setups/blik_payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module CheckoutSdk
module Payments
# Blik payment method configuration on a Payment Setup.
# Blik payment method configuration on a Payment Setup. Maps swagger `Blik`.
#
# @!attribute status
# @return [String] (response-only) Payment method status (e.g. "available").
# @return [String] (response-only) Payment method status, one of
# {PaymentSetupPaymentMethodStatus} (e.g. "ready").
# @!attribute flags
# @return [Array(String)] (response-only) Diagnostic flags returned by the API.
# @!attribute partner_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Payments
# Card Present payment method configuration on a Payment Setup. Maps swagger `CardPresent`.
#
# @!attribute status
# @return [String] (response-only) Payment method status.
# @return [String] (response-only) Payment method status, one of
# {PaymentSetupPaymentMethodStatus} (e.g. "ready").
# @!attribute flags
# @return [Array(String)] (response-only) Diagnostic flags returned by the API.
# @!attribute track2
Expand Down
84 changes: 80 additions & 4 deletions lib/checkout_sdk/payments/setups/payment_setups_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ def initialize(api_client, configuration)
# `paybybank`; the API ignores `pay_by_bank` without an error), a Hash with the keys documented
# on {PayByBankPaymentMethod}; you send :bank_id (the identifier of the bank the customer has
# selected for the payment).
# :payment_methods may also include (every key is optional unless marked required):
# - :card - :token (a Hash with :id, String, the Checkout.com card token), :details (the card
# data: :number (String, write-only), :expiry_month (Integer), :expiry_year (Integer), :name
# (String, write-only), :cvv (String, write-only), :stored (Boolean, write-only) and
# :allow_update (Boolean)), :store_for_future_use (Boolean, write-only), :phone
# (:country_code, String, min 1 character, max 7 characters, and :number, String, min 6
# characters, max 25 characters), :account_holder (:type, one of "individual", "government"
# or "corporate", :first_name, :last_name, :middle_name, :company_name (Strings) and
# :account_name_inquiry (Boolean)) and :preferred_scheme ("visa", "mastercard" or
# "cartes_bancaires"). The card data goes under :details; the API ignores it at the top level
# of :card.
# - :applepay - :token_data (write-only: :version, :data and :signature (Strings) and :header,
# a Hash with :ephemeral_public_key, :public_key_hash and :transaction_id (Strings)), :token (a
# Hash with :id, String, required, pattern ^(tok)_(\w{26})$, and :expires_on, date-time,
# ISO 8601; a String token is not accepted), :store_for_future_use (Boolean, write-only),
# :phone and :account_holder as on :card, and :preferred_scheme ("visa", "mastercard" or
# "cartes_bancaires"). Apple Pay has no :details.
# - :googlepay - :token_data (write-only: :protocol_version, :signature, :signed_message and
# :tokenization_key (Strings)), :token, :store_for_future_use, :phone and :account_holder as
# on :applepay, and :preferred_scheme ("visa" or "mastercard" only). Google Pay has no
# :details.
# - :instrument - :id (String, the unique identifier of the instrument to use).
# - :auto_confirm - String, the payment method that automatically confirms the payment when it
# is ready, for example "card".
# :settings may include :success_url and :failure_url (String, format uri, max 255
# characters), :capture (Boolean, whether to capture the payment immediately, default true) and
# :excluded_payment_methods (Array of Strings, payment method names, for example ["klarna"]).
# :order may include :sub_merchants, an Array of Hashes with :id (String), :product_category
# (String), :number_of_sales (Integer; the API does not define number_of_trades) and
# :registration_date (String, format date, yyyy-MM-dd).
# :metadata - A Hash of key/value pairs to attach to the payment (max 20 keys); each value is a
# String (max 255 characters), a Number or a Boolean.
# :risk {PaymentSetupRisk} - Risk assessment settings for the Payment Setup: :enabled
# (Boolean, whether a risk assessment should be performed, default true).
# :customer may include:
Expand Down Expand Up @@ -66,7 +98,10 @@ def initialize(api_client, configuration)
# @return [Hash] The Payment Setup (swagger `PaymentSetup`, 200). For Cash App Pay, read
# payment_methods.cashapp.action.redirect_url, payment_methods.cashapp.reference and, once only,
# payment_methods.cashapp.customer_profile. For Pay by Bank, read
# payment_methods.paybybank.action.banks.
# payment_methods.paybybank.action.banks. Card, Apple Pay and Google Pay return the read-only
# :schemes (supported card scheme names; Google Pay never lists cartes_bancaires) and card
# details :last4, :bin, :scheme (Strings) and :expires_on (date-time); instrument returns the
# read-only :type (String) and :action (:type, "set_instrument").
def create_payment_setup(payment_setups_request)
api_client.invoke_post(
build_path(PAYMENTS_PATH, SETUPS_PATH),
Expand Down Expand Up @@ -100,6 +135,38 @@ def create_payment_setup(payment_setups_request)
# `paybybank`; the API ignores `pay_by_bank` without an error), a Hash with the keys documented
# on {PayByBankPaymentMethod}; you send :bank_id (the identifier of the bank the customer has
# selected for the payment).
# :payment_methods may also include (every key is optional unless marked required):
# - :card - :token (a Hash with :id, String, the Checkout.com card token), :details (the card
# data: :number (String, write-only), :expiry_month (Integer), :expiry_year (Integer), :name
# (String, write-only), :cvv (String, write-only), :stored (Boolean, write-only) and
# :allow_update (Boolean)), :store_for_future_use (Boolean, write-only), :phone
# (:country_code, String, min 1 character, max 7 characters, and :number, String, min 6
# characters, max 25 characters), :account_holder (:type, one of "individual", "government"
# or "corporate", :first_name, :last_name, :middle_name, :company_name (Strings) and
# :account_name_inquiry (Boolean)) and :preferred_scheme ("visa", "mastercard" or
# "cartes_bancaires"). The card data goes under :details; the API ignores it at the top level
# of :card.
# - :applepay - :token_data (write-only: :version, :data and :signature (Strings) and :header,
# a Hash with :ephemeral_public_key, :public_key_hash and :transaction_id (Strings)), :token (a
# Hash with :id, String, required, pattern ^(tok)_(\w{26})$, and :expires_on, date-time,
# ISO 8601; a String token is not accepted), :store_for_future_use (Boolean, write-only),
# :phone and :account_holder as on :card, and :preferred_scheme ("visa", "mastercard" or
# "cartes_bancaires"). Apple Pay has no :details.
# - :googlepay - :token_data (write-only: :protocol_version, :signature, :signed_message and
# :tokenization_key (Strings)), :token, :store_for_future_use, :phone and :account_holder as
# on :applepay, and :preferred_scheme ("visa" or "mastercard" only). Google Pay has no
# :details.
# - :instrument - :id (String, the unique identifier of the instrument to use).
# - :auto_confirm - String, the payment method that automatically confirms the payment when it
# is ready, for example "card".
# :settings may include :success_url and :failure_url (String, format uri, max 255
# characters), :capture (Boolean, whether to capture the payment immediately, default true) and
# :excluded_payment_methods (Array of Strings, payment method names, for example ["klarna"]).
# :order may include :sub_merchants, an Array of Hashes with :id (String), :product_category
# (String), :number_of_sales (Integer; the API does not define number_of_trades) and
# :registration_date (String, format date, yyyy-MM-dd).
# :metadata - A Hash of key/value pairs to attach to the payment (max 20 keys); each value is a
# String (max 255 characters), a Number or a Boolean.
# :risk {PaymentSetupRisk} - Risk assessment settings for the Payment Setup: :enabled
# (Boolean, whether a risk assessment should be performed, default true).
# :customer may include:
Expand Down Expand Up @@ -127,7 +194,10 @@ def create_payment_setup(payment_setups_request)
# @return [Hash] The Payment Setup (swagger `PaymentSetup`, 200). For Cash App Pay, read
# payment_methods.cashapp.action.redirect_url, payment_methods.cashapp.reference and, once only,
# payment_methods.cashapp.customer_profile. For Pay by Bank, read
# payment_methods.paybybank.action.banks.
# payment_methods.paybybank.action.banks. Card, Apple Pay and Google Pay return the read-only
# :schemes (supported card scheme names; Google Pay never lists cartes_bancaires) and card
# details :last4, :bin, :scheme (Strings) and :expires_on (date-time); instrument returns the
# read-only :type (String) and :action (:type, "set_instrument").
def update_payment_setup(id, payment_setups_request)
api_client.invoke_put(
build_path(PAYMENTS_PATH, SETUPS_PATH, id),
Expand All @@ -143,7 +213,10 @@ def update_payment_setup(id, payment_setups_request)
# @return [Hash] The Payment Setup (swagger `PaymentSetup`, 200). For Cash App Pay, read
# payment_methods.cashapp.action.redirect_url, payment_methods.cashapp.reference and, once only,
# payment_methods.cashapp.customer_profile. For Pay by Bank, read
# payment_methods.paybybank.action.banks.
# payment_methods.paybybank.action.banks. Card, Apple Pay and Google Pay return the read-only
# :schemes (supported card scheme names; Google Pay never lists cartes_bancaires) and card
# details :last4, :bin, :scheme (Strings) and :expires_on (date-time); instrument returns the
# read-only :type (String) and :action (:type, "set_instrument").
def get_payment_setup(id)
api_client.invoke_get(
build_path(PAYMENTS_PATH, SETUPS_PATH, id),
Expand All @@ -161,7 +234,10 @@ def get_payment_setup(id)
# @return [Hash] The Payment Setup (swagger `PaymentSetup`, 200). For Cash App Pay, read
# payment_methods.cashapp.action.redirect_url, payment_methods.cashapp.reference and, once only,
# payment_methods.cashapp.customer_profile. For Pay by Bank, read
# payment_methods.paybybank.action.banks.
# payment_methods.paybybank.action.banks. Card, Apple Pay and Google Pay return the read-only
# :schemes (supported card scheme names; Google Pay never lists cartes_bancaires) and card
# details :last4, :bin, :scheme (Strings) and :expires_on (date-time); instrument returns the
# read-only :type (String) and :action (:type, "set_instrument").
def confirm_payment_setup(id, payment_method_name)
api_client.invoke_post(
build_path(PAYMENTS_PATH, SETUPS_PATH, id, CONFIRM_PATH, payment_method_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Payments
# Stablecoin payment method configuration on a Payment Setup. Maps swagger `Stablecoin`.
#
# @!attribute status
# @return [String] (response-only) Payment method status.
# @return [String] (response-only) Payment method status, one of
# {PaymentSetupPaymentMethodStatus} (e.g. "ready").
# @!attribute flags
# @return [Array(String)] (response-only) Diagnostic flags returned by the API.
class StablecoinPaymentMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
describe CheckoutSdk::Payments::BacsPaymentMethod do
it 'serializes its fields to their swagger keys' do
pm = described_class.new
pm.status = 'available'
pm.status = 'ready'
pm.flags = %w[flag_a]
pm.instrument_id = 'src_wkq7552u245upl5h75x24554xy'
pm.initialization = 'setup'
pm.initialization = 'enabled'
pm.account_holder = { 'type' => 'individual', 'first_name' => 'John' }
pm.account_number = '12345678'
pm.bank_code = '200000'
Expand All @@ -17,10 +17,10 @@

hash = CheckoutSdk::JsonSerializer.to_custom_hash(pm)

expect(hash['status']).to eq('available')
expect(hash['status']).to eq('ready')
expect(hash['flags']).to eq(%w[flag_a])
expect(hash['instrument_id']).to eq('src_wkq7552u245upl5h75x24554xy')
expect(hash['initialization']).to eq('setup')
expect(hash['initialization']).to eq('enabled')
expect(hash['account_holder']).to eq({ 'type' => 'individual', 'first_name' => 'John' })
expect(hash['account_number']).to eq('12345678')
expect(hash['bank_code']).to eq('200000')
Expand All @@ -33,7 +33,7 @@
describe CheckoutSdk::Payments::CardPresentPaymentMethod do
it 'serializes its fields to their swagger keys' do
pm = described_class.new
pm.status = 'available'
pm.status = 'ready'
pm.flags = %w[flag_a]
pm.track2 = 'track2-data'
pm.emv = 'emv-data'
Expand All @@ -44,7 +44,7 @@

hash = CheckoutSdk::JsonSerializer.to_custom_hash(pm)

expect(hash['status']).to eq('available')
expect(hash['status']).to eq('ready')
expect(hash['flags']).to eq(%w[flag_a])
expect(hash['track2']).to eq('track2-data')
expect(hash['emv']).to eq('emv-data')
Expand All @@ -59,14 +59,14 @@
it 'serializes bank_id, status, flags and action' do
pm = described_class.new
pm.bank_id = 'ob-natwest'
pm.status = 'available'
pm.status = 'ready'
pm.flags = %w[flag_a]
pm.action = { 'type' => 'select_bank', 'banks' => [{ 'bank_id' => 'ob-natwest' }] }

hash = CheckoutSdk::JsonSerializer.to_custom_hash(pm)

expect(hash['bank_id']).to eq('ob-natwest')
expect(hash['status']).to eq('available')
expect(hash['status']).to eq('ready')
expect(hash['flags']).to eq(%w[flag_a])
expect(hash['action']).to eq({ 'type' => 'select_bank', 'banks' => [{ 'bank_id' => 'ob-natwest' }] })
end
Expand Down Expand Up @@ -140,15 +140,28 @@
end
end

describe CheckoutSdk::Payments::BlikPaymentMethod do
it 'serializes its fields to their swagger keys' do
pm = described_class.new
pm.status = 'ready'
pm.flags = %w[flag_a]
pm.partner_code = '777123'

hash = CheckoutSdk::JsonSerializer.to_custom_hash(pm)

expect(hash).to eq({ 'status' => 'ready', 'flags' => %w[flag_a], 'partner_code' => '777123' })
end
end

describe CheckoutSdk::Payments::StablecoinPaymentMethod do
it 'serializes its response fields' do
pm = described_class.new
pm.status = 'available'
pm.status = 'ready'
pm.flags = %w[flag_a]

hash = CheckoutSdk::JsonSerializer.to_custom_hash(pm)

expect(hash['status']).to eq('available')
expect(hash['status']).to eq('ready')
expect(hash['flags']).to eq(%w[flag_a])
end
end
Expand Down
Loading