CashApp Payment Method Not Rendering in Django with Adyen Integration

I'm trying to integrate Adyen's payment methods (including CashApp) into my Django web application, but the CashApp payment method isn't rendering on the front end. Instead, I receive the following error:

ERROR Error during initialization ERROR: Error during initialization
at e.<anonymous> (https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.68.0/adyen.js:1:460538)
at P (https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.68.0/adyen.js:1:41524)
at Generator.<anonymous> (https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.68.0/adyen.js:1:42844)

This same code is rendering the card payment gateway but not working on the cashapp.

My html Code: Where is used adyen sdk=5.68.0 version. Version greater than 5.69.0 gives different error that AdyenCheckout is not defined I don't know how to solve that too.

<link rel="stylesheet" href="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.68.0/adyen.css">
<div id="component"></div>
<script src="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.68.0/adyen.js"></script>

async function startCheckout() {
    const checkoutSessionResponse = await callServer({% url 'sessions' %});
    const checkout = await createAdyenCheckout(checkoutSessionResponse);
    checkout.create(type).mount("#component");
}

async function createAdyenCheckout(session) {
    return new AdyenCheckout({
        clientKey,
        session: session,
        paymentMethodsConfiguration: {
            cashapp: { amount: { value: 100, currency: "USD" }, countryCode: "US" }
        }
    });
}

django view.py file:


def adyen_sessions(request):
    # payments = ["card", "cashapp", "ideal"]
    session_response = {
        'client_key': settings.ADYEN_CLIENT_KEY,
        'method': 'cashapp'
    }
    return render(request, 'component.html', context=session_response)

def sessions(request):
    if request.method == "POST":
        adyen = Adyen.Adyen()
        adyen.payment.client.xapikey = settings.ADYEN_API_KEY
        adyen.payment.client.platform = settings.ADYEN_ENVIRONMENT
        adyen.payment.client.merchant_account = settings.ADYEN_MERCHANT_ACCOUNT

        request_data = {
            'amount': {
                "value": 100,  # amount in minor units
                "currency": "USD"
            },
            'reference': f"Reference {uuid.uuid4()}",
            'returnUrl': f"{request.build_absolute_uri('/redirect/')}",
            'countryCode': "US",
            'lineItems': [
                {
                    "quantity": 1,
                    "amountIncludingTax": 5000,
                    "description": "Sunglasses"
                },
                {
                    "quantity": 1,
                    "amountIncludingTax": 5000,
                    "description": "Headphones"
                }
            ],
            'merchantAccount': settings.ADYEN_MERCHANT_ACCOUNT,
        }
        result = adyen.checkout.payments_api.sessions(request_data)
        data = json.loads(result.raw_response)
        print("/sessions response:\n" + data.__str__())
        return JsonResponse(data, status=200, safe=False)

According to the Adyen Documentation for CashApp you have to include the following two parameters in your request:

  • "storePaymentMethodMode": "askForConsent"
  • "recurringProcessingModel": "CardOnFile"

I'd also ensure that startCheckout(..) is called on the page. I don't see the startCheckout(..) being called in the inserted snippet.

example of cash app rendering on Drop-in

Here's my version of the code, I've modified the Python-integration-example on Github slightly:

def adyen_sessions(host_url):
    adyen = Adyen.Adyen()
    adyen.payment.client.xapikey = get_adyen_api_key() // your API key
    adyen.payment.client.platform = "test" 
    adyen.payment.client.merchant_account = get_adyen_merchant_account() // your merchant account

    request = {}

    request['amount'] = {"value": "10000", "currency": "USD"}  # amount in minor units
    request['reference'] = f"Reference {uuid.uuid4()}"  # provide your unique payment reference
    # set redirect URL required for some payment methods
    request['returnUrl'] = f"{host_url}/redirect?shopperOrder=myRef"
    request['countryCode'] = "US"
    request['recurringProcessingModel'] = "CardOnFile"
    request['storePaymentMethodMode'] = "askForConsent"

    # set lineItems: required for some payment methods (ie Klarna)
    request['lineItems'] = \
        [{"quantity": 1, "amountIncludingTax": 5000, "description": "Sunglasses"}, # amount in minor units
         {"quantity": 1, "amountIncludingTax": 5000, "description": "Headphones"}] # amount in minor units

    request['merchantAccount'] = get_adyen_merchant_account()

    result = adyen.checkout.payments_api.sessions(request)

    formatted_response = json.dumps((json.loads(result.raw_response)))
    print("/sessions response:\n" + formatted_response)

    return formatted_response

Hope this helped!

Вернуться на верх