module Workarea decorate Payment::Purchase::CreditCard, with: :checkoutdotcom do decorated do delegate :address, to: :tender end def complete! transaction.response = handle_active_merchant_errors do gateway.purchase( transaction.amount.cents, tender.to_token_or_active_merchant, transaction_options ) end if transaction.response.success? && tender.token.blank? tender.token = transaction.response.params["source"]["id"] tender.save! end transaction.response end private def transaction_options options = { reference: tender.payment.id, customer: { email: tender.profile.email, name: address.first_name + ' ' + address.last_name }, billing_address: { address1: address.street, address2: address.street_2, city: address.city, state: address.region, country: address.country.alpha2, zip: address.postal_code } } end end end