Programmatically manage customer profiles
Install and import our clientCopied!
For this recipe, we will use the Python SDK, which you can install using pip install getopenpay
or poetry add getopenpay
from getopenpay.client import ApiKeys, OpenPayClient
OP_PUBLISHABLE_TOKEN = 'TODO_YOUR_PUBLISHABLE_TOKEN'
OP_SECRET_TOKEN = 'TODO_YOUR_SECRET_TOKEN'
api_keys = ApiKeys(publishable_key=OP_PUBLISHABLE_TOKEN, secret_key=OP_SECRET_TOKEN)
# sandbox/staging environment
sandbox_host = 'https://connto.openpaystaging.com'
# production environment
production_host = 'https://connto.getopenpay.com'
Customer buying more of the same priceCopied!
new_quantity = 2
update_request = UpdateSubscriptionRequest(
items=[
InlineSubscriptionItemUpdate(
id='TARGET_SUBSCRIPTION_ID', quantity=new_quantity
)
],
)
# Execute the update
update_response = client.subscriptions.update_subscription(sub_created.id, update_request)
Customer upgrading pricesCopied!
update_request = UpdateSubscriptionRequest(
items=[
InlineSubscriptionItemUpdate(
id='TARGET_SUBSCRIPTION_ID', price_id='TARGET_PRICE_ID'
)
],
)
# Execute the update
update_response = client.subscriptions.update_subscription(sub_created.id, update_request)
List customer payment methodsCopied!
pm_methods = client.customers.list_customer_payment_methods('TARGET_CUSTOMER_ID',
CustomerPaymentMethodQueryParams()).data
List invoicesCopied!
invoice_resp = client.invoices.list_invoices(
invoice_query_params=InvoiceQueryParams(customer_id='TARGET_CUSTOMER_ID')
)