0

我在 php 中使用 mollie API 付款。但它给了我一些错误。我已经发布了我的代码和错误截图。

这是我的代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

try {
    require_once "vendor/autoload.php";

    $mollie = new \Mollie\Api\MollieApiClient();
    $mollie->setApiKey("test_XXXX");

    $orderId = time();

    $amount = $_POST['amount'];
    $payment = $mollie->payments->create([
        "amount" => [
            "currency" => "EUR",
            "value" => "$amount", // You must send the correct number of decimals, thus we enforce the use of strings
        ],
        "description" => "Order #{$orderId}",
        "redirectUrl" => "https://example.com/Mollie/return/".$orderId."/",
        "webhookUrl" => "https://example.com/Mollie/webhook/",
        "metadata" => [
            "order_id" => $orderId,
        ],
    ]);
    print_r($payment);

    $payment_data = array(
            'payment_id' => $payment->id,
            'user_id' => $_POST['user_id'],
            'order_id' => $orderId,
            'mode' => $payment->mode,
            'description' => $payment->description,
            'status' => $payment->status,
            'added_date' => date('Y-m-d'),
            'added_time' => date('H:i:s')
    );
    print_r($payment_data);

    header("Location: " . $payment->getCheckoutUrl(), true, 303);

} catch (\Mollie\Api\Exceptions\ApiException $e) {
    echo "API call failed: ". htmlspecialchars($e->getMessage());
}

截图:

  1. 第一个图像以红色显示“Uncaught SyntaxError: Unexpected token M in JSON at position 0”。
  2. 第二张图片是我收到的警告

第一张图片

第二张图片

4

0 回答 0