简体   繁体   中英

php mollie payments recurring billing

My code is :

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

The result is:

Fatal error: Uncaught exception 'Mollie\\Api\\Exceptions\\ApiException' with message 'Error executing API call (422: Unprocessable Entity): No suitable mandates found for customer. Field: customerId.

Is something that I missing??

You're missing the customer ID for the customer you created previously.

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

I find an answer on my own question: In order to add a subscription for an user you must first add the payment and after that the subscription.

        $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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM