php mollie 付款定期计费

Posted

技术标签:

【中文标题】php mollie 付款定期计费【英文标题】:php mollie payments recurring billing 【发布时间】:2019-02-04 00:01:33 【问题描述】:

我的代码是:

$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,$customer->id 应该保留它。请参阅documentation 上的#3 以引用客户。 【参考方案1】:

在创建订阅之前,您必须创建授权( $customer->createMandate )

【讨论】:

【参考方案2】:

我在自己的问题上找到了答案: 要为用户添加订阅,您必须先添加付款,然后再添加订阅。

        $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,
        ]);

【讨论】:

订阅需要在 webhook 中【参考方案3】:

您缺少之前创建的客户的客户 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->createSubscription([]);后触发错误 当我将 customerId 放入 createSubscription() 时,我得到: 致命错误:未捕获的异常 'Mollie\Api\Exceptions\ApiException' 并带有消息 'Error execution API call (422: Unprocessable Entity): Non - 此 API 调用的现有主体参数“customerId”。你的意思是:“次”?字段:customerId。

以上是关于php mollie 付款定期计费的主要内容,如果未能解决你的问题,请参考以下文章

在定期计费中,是不是可以退回被拒绝的付款?

贝宝定期付款计划修改

定期付款或特殊类别。关于计费的问题[关闭]

带有更新计费周期的 Paypal 定期付款

如何在 paypal pro 沙盒上设置和检查定期付款

如何使用 SDK 对 PayPal 定期付款配置文件进行计费