Search code examples
restbalanced-payments

How to specify which credit card to charge using Balanced API


I am following the documentation in https://docs.balancedpayments.com/1.0/overview/getting-started/#charge-a-credit-card

I have created the customer and I have tokenized two cards and added them to the customer. Now I have only recoded the customer URI, as I have associated the cards with the customer I did not think I needed to record the card URIs and keep a record of which customer they were associated with. I assumed that this is what balanced does.

However when I come to charge a card I have the following code

Balanced\Settings::$api_key = "ak-test-2KZfoLyijij3Y6OyhDAvFRF9tXzelBLpD";

$customer = \Balanced\Customer::get("/v1/customers/CU6vs1tjxBtifgTuzKjCGtVS");
$customer->debit('5000');

(1) How do I tell balanced which card to charge?

(2) Assuming I can do this, how do I retrieve the card information from the customer's balanced account so they can choose which card?


Solution

  • The example you gave uses the default funding instrument. If you want to charge a specific card, specify the URI of the funding instrument you wish to debit as the source parameter. https://github.com/balanced/balanced-php/blob/master/src/Balanced/Customer.php#L146

    You don't need to store in your database the URIs for the funding instruments, but you can if you wish. If you want to build out a view where users can pick the funding source, just get all the Customer's cards with something like $customer->cards and loop through that to display each card's information as desired.

    NOTE: In the new v1.1 API debits and credits are performed directly on funding instruments (Card and BankAccount resources) and not via Customer.

    I also invite you to swing by #balanced in Freenode IRC where you can get integration help directly from Balanced developers.