2015-03-07 16 views
19

Ho bisogno di aggiungere una scheda a un cliente preesistente. Ecco quello che ho fatto:Stripe - Aggiungi nuova scheda al cliente esistente

1. ottenere gettone da presentazione utente

card_token = request.POST('stripeToken') 

2. recuperare un cliente

customer = stripe.Customer.retrieve('cus_xxxxxxxxxx') 

3. scheda aggiuntiva a questo cliente

customer.Cards.create(card=card_token) 

E ' è # 3 che ho problemi perché sembra che il cust Omero non ha carte metodo, ma ho visto persone farlo altrove.

Come devo raggiungere questo obiettivo?

risposta

21

Se sei sulla versione 2015-02-18 API o più tardi poi l'attributo cards è stato cambiato in sources come si può vedere nel changelog

La documentazione sul Create Card API mostra il seguente codice ora:

customer = stripe.Customer.retrieve('cus_xxxxxxxxxx') 
customer.sources.create(card=card_token) 

Puoi trovare la tua versione API nelle chiavi API settings nella dashboard e puoi anche utilizzare l'intestazione Stripe-Version per forzare la tua richiesta API a una versione API precedente in modo che cards funzionare come spiegato nella documentazione Versioning:

stripe.api_version = '2015-01-26' 
+0

Grazie, problema risolto! – chenxi17

0

Esempio (customerId - cus_xxxxxxxxxx):

Stripe.apiKey = stripeApiKey; 

    Customer customer = Customer.retrieve(customerId); 

    Map<String, Object> cardParams = new HashMap<String, Object>(); 
    cardParams.put("number", "4242424242424242"); 
    cardParams.put("exp_month", "12"); 
    cardParams.put("exp_year", "2018"); 
    cardParams.put("cvc", "314"); 

    Map<String, Object> tokenParams = new HashMap<String, Object>(); 
    tokenParams.put("card", cardParams); 
    Token cardToken = Token.create(tokenParams); 

    Map<String, Object> sourceParams = new HashMap<String, Object>(); 
    sourceParams.put("source", cardToken.getId()); //? 
    Card source = (Card) customer.getSources().create(sourceParams); 
    logger.info("Card created: " + source.toString()); 
Problemi correlati