Search code examples
pythonrecurly

how to add a Recurly Billinginfo with the Python API?


If I create an account with the Recurly web interface, it has no billing info, I get an AttributeError when I try to access it. I can't seem to add an billing info to the account. I'm using the Python API version 2.2.4.

I need to create a BillingInfo without knowing the credit card number or other fields I can't see locally to keep PCI compliance, so I'm trying to use a token as described in https://docs.recurly.com/api/billing-info#update-billing-info-token. I can do this for an existing BillingInfo (by setting the token_id and saving the BillingInfo), but I need a BillingInfo to do this.

How do I save billing info for an account that does not yet have one?

(Pdb) acct = recurly.Account.get(code)
(Pdb) acct
<recurly.Account object at 0x7f2a160530d0>
(Pdb) acct.billing_info
*** AttributeError: billing_info
(Pdb) b_i = recurly.BillingInfo()
(Pdb) b_i.email = '[email protected]'
(Pdb) b_i.save()
*** AttributeError: collection_path
(Pdb) account.billing_info = b_i
*** AttributeError: can't set attribute

Solution

  • Use the Account:update_billing_info method.

    In your code snippet it would be something like: acct.update_billing_info(b_i).