user21398
user21398

Reputation: 1493

Saving payment for later with activemerchant

Active Merchant seems like a nice gem for payments. However, I need the ability to save a customer's payment information and then charge the card at a later date (ie, at time of shipping not at time of order placement).

Both Braintree and Stripe have a way to do this by giving me a customer id to save to my db. Then I would use this id to charge the customer at some date.

I looked through Active Merchant Stripe code, and its purchase() has comments:

   # To create a charge on a customer, call
   #   purchase(money, nil, { :customer => id, ... })

Which seems like there's a way to get a customer id.

How do I get Active Merchant to create a customer object and return the customer id for Stripe and Braintree? And is this feature supported in activemerchant for all gateways that support this payment method?

Upvotes: 3

Views: 504

Answers (1)

agf
agf

Reputation: 176740

I work at Braintree. If you have more questions, you can always get in touch with our support team.

The various methods that create or update a customer / credit card in the Braintree vault return :customer_vault_id on the response, for example:

Response.new(result.success?, message_from_result(result),
  {
    :braintree_customer => (
      customer_hash(result.customer, :include_credit_cards) if result.success?
    ),
    :customer_vault_id => (
      result.customer.id if result.success?
    ),
    :credit_card_token => (
      result.customer.credit_cards[0].token if result.success?
    )
  },
  :authorization => (result.customer.id if result.success?)
)

You can store that ID and use it in later calls to purchase.

Upvotes: 3

Related Questions