【问题标题】:php mollie payments recurring billingphp mollie 付款定期计费
【发布时间】: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 以引用客户。

标签: php payment recurring-billing mollie


【解决方案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。
    猜你喜欢
    • 2015-10-04
    • 2014-12-07
    • 2012-12-03
    • 2014-09-01
    • 2014-12-23
    • 2020-04-11
    • 2018-07-09
    • 2022-01-05
    • 2015-12-20
    相关资源
    最近更新 更多