问题
I would like to know how can I create a charge using a stored credit card.
Using /card api I have successfully stored card in QuickBooks Online and received card id in return.
Now I want to create a charge against the stored card. For creating a charge I see there are 2 ways to provide card details.
- Provide explicit card details like card number, expiry date etc.
- By using card token. But even for retrieving card token we need to provide explicit card details to /tokens api call.
I tried retrieving the stored Card using it's Id and then using the returned card details in the Charge but it didn't work.
So I would like to know how can I create a charge by using a stored credit card and not requiring to provide explicit card details every time.
UPDATE
I have tried following test code but it's giving me 'card.number is invalid' error.
public Charge createCharge(Context context, String requestId) {
String uri = "https://sandbox.api.intuit.com/quickbooks/v4/payments/charges";
PaymentService paymentService = new PaymentService();
Charge charge = new Charge();
CreditCard card = null;
try {
card = paymentService.getCreditCard(context, getRequestId(), "https://sandbox.api.intuit.com/quickbooks/v4/customers/{customer_id}/cards/{card_id}");
} catch (Exception e) {
e.printStackTrace();
}
charge.setCard(card);
charge.setAmount(new BigDecimal(10.55));
charge.setCurrency("USD");
try {
charge = paymentService.createCharge(context, getRequestId(), charge, uri);
return charge;
} catch (Exception e) {
}
}
Error com.intuit.ipp.exception.BadRequestException: ERROR CODE:PMT-4000, ERROR MESSAGE:card.number is invalid., ERROR DETAIL:card.number, MORE ERROR DETAIL:HttpStatusCode=400; Type=invalid_request; MoreInfo=Credit/Debit card number format, InfoLink=https://developer.intuit.com/v2/docs?redirectID=PayErrors
The card number in the card that I retrieve using card id is (obviously) obfuscated and is in the format "xxxxxxxxxxxx1111" and so /charges api complains that it is invalid.
回答1:
Store the card details ("create a card") using this API endpoint:
- https://developer.intuit.com/docs/api/payments/cards
You get back a unique id
value.
Create a charge using this API endpoint:
- https://developer.intuit.com/docs/api/payments/charges
Make sure for the cardOnFile
you pass the id
value you got back from the first API call.
Your current code is incorrect. Where you should be passing cardOnFile
as a param, you're passing the card
node instead (which expects a full card number, vs. a card id
value). Specifically this line is incorrect:
charge.setCard(card);
来源:https://stackoverflow.com/questions/47979320/quickbooks-api-how-to-create-a-charge-using-stored-credit-card