CashApp 支付方法未在具有 Adyen 集成的 Django 中呈现

问题描述 投票:0回答:1

我正在尝试将 Adyen 的支付方式(包括 CashApp)集成到我的 Django Web 应用程序中,但 CashApp 支付方式未在前端呈现。相反,我收到以下错误:

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)

相同的代码正在渲染卡支付网关,但不适用于 cashapp。

我的html代码: 哪里使用的是adyen sdk=5.68.0版本。大于 5.69.0 的版本给出了不同的错误,即 AdyenCheckout 未定义,我也不知道如何解决这个问题。

<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 文件:


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)
python python-3.x django django-rest-framework adyen
1个回答
0
投票

根据 CashApp 的 Adyen 文档,您必须在请求中包含以下两个参数:

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

我还要确保在页面上调用 startCheckout(..) 。我没有看到在插入的代码片段中调用 startCheckout(..) 。

example of cash app rendering on Drop-in

这是我的代码版本,我稍微修改了 Github 上的 Python-integration-example

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

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.