簡體   English   中英

PHP的莫莉支付定期計費

[英]php mollie payments recurring billing

我的代碼是:

$customer = $mollie->customers->create([
    "name"    => $name,
    "email"   => $email,
]);

$customer->createSubscription([
    "amount"          => [
            "currency"    => 'USD',
            "value"       => 20.00,
    ],
    "interval"        => '2months',
    "times"           => 3,
    "description"     => $someDescription,
    "webhookUrl"      => $webhook,
    "method"          => NULL,
]);

$payment = $customer->createPayment([
    "amount" => [
            "currency"    => 'USD',
            "value"       => 20.00,
    ],
    "description"     => $someDescription,
    "redirectUrl"     => $siteUrl,
    "webhookUrl"      => $webhook,
    "metadata" => [
        "order_id" => $orderId,
    ],
    "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
]);

結果是:

致命錯誤:未捕獲的異常'Mollie \\ Api \\ Exceptions \\ ApiException'和消息'執行API調用時出錯(422:無法處理的實體):未為客戶找到合適的任務。 字段:customerId。

我缺少什么了嗎?

您缺少先前創建的客戶的客戶ID。

    $payment = $customer->createPayment([
        "customerId"      => $customer->id, /* see #3 in documentation */
        "amount" => [
                "currency"    => 'USD',
                "value"       => 20.00,
        ],
        "description"     => $someDescription,
        "redirectUrl"     => $siteUrl,
        "webhookUrl"      => $webhook,
        "metadata" => [
            "order_id" => $orderId,
        ],
        "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
    ]);

我對自己的問題有一個答案:為了為用戶添加訂閱,您必須先添加付款,然后再添加訂閱。

        $customer = $mollie->customers->create([
            "name"    => $fullName,
            "email"   => $email,
        ]);

        $payment = $customer->createPayment([
            "amount" => [
                "currency"    => $currency,
                "value"       => $amount,
            ],
            "description"     => $description,
            "redirectUrl"     => $siteUrl,
            "webhookUrl"      => $webhook,
            "metadata" => [
                "order_id" => $orderId,
            ],
            "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
        ]);

        $customer->createSubscription([
            "amount"      => [
                "currency"    => $currency,
                "value"       => $amount,
            ],
            "times"       => $recurringLimit,
            "interval"    => $interval,
            "description" => $description,
            "webhookUrl"  => $webhook,
            "method"      => NULL,
        ]);

在創建訂閱之前,您必須創建任務( $customer->createMandate )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM