Skip to content

Commit bfbad5b

Browse files
committed
updates readme to include app store api
1 parent 6889c54 commit bfbad5b

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The xero-python SDK makes it easy for developers to access Xero's APIs in their
1313
- [Configuration](#configuration)
1414
- [Authentication](#authentication)
1515
- [Custom Connections](#custom-connections)
16+
- [App Store Subscriptions](#app-store-subscriptions)
1617
- [API Clients](#api-clients)
1718
- [Helper Methods](#helper-methods)
1819
- [Usage Examples](#usage-examples)
@@ -332,6 +333,84 @@ Because Custom Connections are only valid for a single organisation you don't ne
332333

333334
> Because the SDK is generated from the OpenAPI spec the parameter remains. For now you are required to pass an empty string to use this SDK with a Custom Connection.
334335
336+
---
337+
338+
## App Store Subscriptions
339+
340+
If you are implementing subscriptions to participate in Xero's App Store you will need to setup [App Store subscriptions](https://developer.xero.com/documentation/guides/how-to-guides/xero-app-store-referrals/) endpoints.
341+
342+
When a plan is successfully purchased, the user is redirected back to the URL specified in the setup process. The Xero App Store appends the subscription Id to this URL so you can immediately determine what plan the user has subscribed to through the subscriptions API.
343+
344+
With your app credentials you can create a client via `client_credentials` grant_type with the `marketplace.billing` scope. This unique access_token will allow you to query any functions in `AppStoreApi`. Client Credentials tokens to query app store endpoints will only work for apps that have completed the App Store on-boarding process.
345+
```python
346+
# configure xero-python sdk client
347+
api_client = ApiClient(
348+
Configuration(
349+
debug=app.config["DEBUG"],
350+
oauth2_token=OAuth2Token(
351+
client_id=app.config["CLIENT_ID"], client_secret=app.config["CLIENT_SECRET"]
352+
),
353+
),
354+
pool_threads=1,
355+
)
356+
357+
try:
358+
# pass True for app_store_billing - defaults to False if no value provided
359+
xero_token = api_client.get_client_credentials_token(True)
360+
except Exception as e:
361+
print(e)
362+
raise
363+
364+
app_store_api = AppStoreApi(api_client)
365+
366+
subscription = app_store_api.get_subscription(subscription_id)
367+
print(subscription)
368+
369+
{
370+
'current_period_end': datetime.datetime(2021, 9, 2, 14, 8, 58, 772536, tzinfo=tzutc()),
371+
'end_date': None,
372+
'id': '03bc74f2-1237-4477-b782-2dfb1a6d8b21',
373+
'organisation_id': '79e8b2e5-c63d-4dce-888f-e0f3e9eac647',
374+
'plans':[
375+
{
376+
'id': '6abc26f3-9390-4194-8b25-ce8b9942fda9',
377+
'name': 'Small',
378+
'status': 'ACTIVE',
379+
'subscription_items': [
380+
{
381+
'end_date': None,
382+
'id': '834cff4c-b753-4de2-9e7a-3451e14fa17a',
383+
'price': {
384+
'amount': Decimal('0.1000'),
385+
'currency': 'NZD',
386+
'id': '2310de92-c7c0-4bcb-b972-fb7612177bc7'
387+
},
388+
'product': {
389+
'id': '9586421f-7325-4493-bac9-d93be06a6a38',
390+
'name': '',
391+
'type': 'FIXED',
392+
'seat_unit': None
393+
},
394+
'start_date': datetime.datetime(2021, 8, 2, 14, 8, 58, 772536, tzinfo=tzutc()),
395+
'test_mode': True
396+
}
397+
]
398+
}
399+
],
400+
'start_date': datetime.datetime(2021, 8, 2, 14, 8, 58, 772536, tzinfo=tzutc()),
401+
'status': 'ACTIVE',
402+
'test_mode': True
403+
}
404+
405+
```
406+
You should use the subscription data to provision user access/permissions to your application.
407+
### App Store Subscription Webhooks
408+
409+
In additon to a subscription Id being passed through the URL, when a purchase or an upgrade takes place you will be notified via a webhook. You can then use the subscription Id in the webhook payload to query the AppStore endpoints and determine what plan the user purchased, upgraded, downgraded or cancelled.
410+
411+
Refer to Xero's documenation to learn more about setting up and receiving webhooks.
412+
> https://developer.xero.com/documentation/guides/webhooks/overview/
413+
335414
---
336415
## API Clients
337416
You can access the different API sets and their available methods through the following:

0 commit comments

Comments
 (0)