Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout.com V2: Support tokenized and saved credit cards #3215

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Support using checkout payment tokens
obahareth committed May 12, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 51c054566776d194528b18f358790399024269d4
31 changes: 26 additions & 5 deletions lib/active_merchant/billing/gateways/checkout_v2.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class CheckoutPaymentToken < PaymentToken
def type
'checkout'
end
end

class CheckoutV2Gateway < Gateway
self.display_name = 'Checkout.com Unified Payments'
self.homepage_url = 'https://www.checkout.com/'
@@ -96,12 +102,27 @@ def add_invoice(post, money, options)

def add_payment_method(post, payment_method)
post[:source] = {}

if payment_method.is_a?(CreditCard)
add_credit_card(post, payment_method)

elsif payment_method.is_a?(CheckoutPaymentToken)
add_payment_token(post, payment_method)
end
end

def add_credit_card(post, credit_card)
post[:source][:type] = 'card'
post[:source][:name] = payment_method.name
post[:source][:number] = payment_method.number
post[:source][:cvv] = payment_method.verification_value
post[:source][:expiry_year] = format(payment_method.year, :four_digits)
post[:source][:expiry_month] = format(payment_method.month, :two_digits)
post[:source][:name] = credit_card.name
post[:source][:number] = credit_card.number
post[:source][:cvv] = credit_card.verification_value
post[:source][:expiry_year] = format(credit_card.year, :four_digits)
post[:source][:expiry_month] = format(credit_card.month, :two_digits)
end

def add_payment_token(post, token)
post[:source][:type] = 'token'
post[:source][:token] = token.payment_data
end

def add_customer_data(post, options)