繁体   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