Best Practice for Deploying Sandbox Python SDK

Good afternoon. I have a very basic payment setup which is working fine in sandbox. Tbh, it’s so long since I set it up I forget the sdk’s nuts and bolts and I just want to confirm best practice to deploy. Unless you have a “deployment checklist” section in your docs which I missed, in which case feel free to link.

I’m using the python sdk as follows:

@csrf_exempt
def payment_req(request):
    bsk = Basket.objects.get(id=get_session_id(request, Basket))
    client = Client(
        access_token=access_token,
        environment='sandbox')
    idempotency_key = str(uuid.uuid4())
    r = json.loads(request.body.decode())
    pyt = {
        'idempotency_key': idempotency_key,
        'location_id': r['locationId'],
        'source_id': r["sourceId"],
        'amount_money': {
            'amount': int(bsk.total * 100),
            'currency': 'GBP'
        }
    }
    a = client.payments.create_payment(body=pyt)
    if a.is_error():
        return HttpResponse(json.dumps({'success': False,
                                        'payment': {"code": a.errors[0]['code'],
                                                    "detail": a.errors[0]['detail']}}),
                            status=500)
    return HttpResponse(json.dumps({'success': True,
                         'payment': {'id': a.body['payment']['id'],
                                    'status': a.status_code,
                                    'receipt_url': a.body['payment']['receipt_url'],
                                    'order_id': a.body['payment']['order_id']}}))

So, I obviously have to update the access_token from sandbox to live, set the environment string to 'production'. Then in terms of the js I update the appId and locationId? The src will have to change: “https://sandbox.web.squarecdn.com/v1/square.js” to whatever the production version is.

Anything else I’m missing?

And finally, once I move to the live server, how do I go about testing it without going broke? :wink:

Thanks!

You nailed the checklist! That’s all you need to do to go to production. Lastly, production is production and you will need to process payments with a valid card. You can definitely test with $1.00 payments and refund them. :slightly_smiling_face:

Sounds good. I’ll just have to sacrifice my lunch money on the altar of development! :wink:

Thanks for your help!