我使用条纹元素测试支付连接帐户,但我发送的正常付款,它是成功的.以下是原始代码:

$paymentIntent = $stripe->paymentIntents->create([
        'amount' => calculateOrderAmount($jsonObj->items),
        'currency' => 'usd',
        // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
        'automatic_payment_methods' => [
            'enabled' => true,
        ],
    ]);

但是我用连接帐户的客户ID发送连接帐户,它返回错误.以下是编辑后的代码:

$paymentIntent = $stripe->paymentIntents->create([
        'amount' => calculateOrderAmount($jsonObj->items),
        'currency' => 'usd',
        // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
        'automatic_payment_methods' => [
            'enabled' => true,
        ],
        'customer' => 'cus_PRCCEKscFngTLa',

    ],
    ['stripe_account' => 'acct_1OcJ3gPHPf7OvbrK']

    );

这里的错误是:

message
: 
"The client_secret provided does not match any associated PaymentIntent on this account. Ensure the publishable key used belongs to the same account that created the PaymentIntent."
param
: 
"client_secret"
request_log_url
: 
"https://dashboard.stripe.com/test/logs/req_eLCngHnF0vGVEM?t=1706241616"
status
: 
400
type
: 
"invalid_request_error"

我怎么才能修好它们呢?我try 判断私钥和公钥,但我提供了正确的值. 文件Create.php

<?php

require_once '../vendor/autoload.php';
require_once '../secrets.php';

$stripe = new \Stripe\StripeClient($stripeSecretKey);

function calculateOrderAmount(array $items): int {
    // Replace this constant with a calculation of the order's amount
    // Calculate the order total on the server to prevent
    // people from directly manipulating the amount on the client
    return 1400;
}

header('Content-Type: application/json');

try {
    // retrieve JSON from POST body
    $jsonStr = file_get_contents('php://input');
    $jsonObj = json_decode($jsonStr);

    // Create a PaymentIntent with amount and currency
    $paymentIntent = $stripe->paymentIntents->create([
        'amount' => calculateOrderAmount($jsonObj->items),
        'currency' => 'usd',
        // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
        'automatic_payment_methods' => [
            'enabled' => true,
        ],
        'customer' => 'cus_PRCCEKscFngTLa',

    ],
    ['stripe_account' => 'acct_1OcJ3gPHPf7OvbrK']

    );

    $output = [
        'clientSecret' => $paymentIntent->client_secret,
    ];

    echo json_encode($output);
} catch (Error $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}


文件Checkout.js文件

// This is your test publishable API key.
const stripe = Stripe("pk_test_51ObgQ7AapkrJHjBL5v8QlnwtO6ARkY0cjR1PQHdol7DHzvwMnfHp7yJo44O1uMoAu17hotn4NOaI6FITTVH84auC00Cq4IfMCd");

// The items the customer wants to buy
const items = [{ id: "xl-tshirt" }];

let elements;

initialize();
checkStatus();

document
  .querySelector("#payment-form")
  .addEventListener("submit", handleSubmit);

// Fetches a payment intent and captures the client secret
async function initialize() {
  const { clientSecret } = await fetch("/create.php", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ items }),
  }).then((r) => r.json());

  elements = stripe.elements({ clientSecret });

  const paymentElementOptions = {
    layout: "tabs",
  };

  const paymentElement = elements.create("payment", paymentElementOptions);
  paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
  e.preventDefault();
  setLoading(true);

  const { error } = await stripe.confirmPayment({
    elements,
    confirmParams: {
      // Make sure to change this to your payment completion page
      return_url: "http://localhost:4242/checkout.html",
    },
  });

  // This point will only be reached if there is an immediate error when
  // confirming the payment. Otherwise, your customer will be redirected to
  // your `return_url`. For some payment methods like iDEAL, your customer will
  // be redirected to an intermediate site first to authorize the payment, then
  // redirected to the `return_url`.
  if (error.type === "card_error" || error.type === "validation_error") {
    showMessage(error.message);
  } else {
    showMessage("An unexpected error occurred.");
  }

  setLoading(false);
}

// Fetches the payment intent status after payment submission
async function checkStatus() {
  const clientSecret = new URLSearchParams(window.location.search).get(
    "payment_intent_client_secret"
  );

  if (!clientSecret) {
    return;
  }

  const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);

  switch (paymentIntent.status) {
    case "succeeded":
      showMessage("Payment succeeded!");
      break;
    case "processing":
      showMessage("Your payment is processing.");
      break;
    case "requires_payment_method":
      showMessage("Your payment was not successful, please try again.");
      break;
    default:
      showMessage("Something went wrong.");
      break;
  }
}

// ------- UI helpers -------

function showMessage(messageText) {
  const messageContainer = document.querySelector("#payment-message");

  messageContainer.classList.remove("hidden");
  messageContainer.textContent = messageText;

  setTimeout(function () {
    messageContainer.classList.add("hidden");
    messageContainer.textContent = "";
  }, 4000);
}

// Show a spinner on payment submission
function setLoading(isLoading) {
  if (isLoading) {
    // Disable the button and show a spinner
    document.querySelector("#submit").disabled = true;
    document.querySelector("#spinner").classList.remove("hidden");
    document.querySelector("#button-text").classList.add("hidden");
  } else {
    document.querySelector("#submit").disabled = false;
    document.querySelector("#spinner").classList.add("hidden");
    document.querySelector("#button-text").classList.remove("hidden");
  }
}```



I want to payment for connect account but its return error, for normal code ( i mean payment for normal account - owner account, its return successfull). Please support to me

推荐答案

由于您使用StripeAccount头创建对象,这意味着对象是在连接的帐户上创建的.

同样,在处理此对象时,您还应该使用StripeAccount头初始化Stripe客户端.看到https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application

另外,如果您不想在每个请求服务器端设置StripeAccount标头,则始终可以在初始化stripe-php时设置StripeAccount标头

$stripe = new \Stripe\StripeClient(
  [
    'api_key' => 'sk_test_...',
    'stripe_account' => 'acct_...'
    ]
);

Php相关问答推荐

Laravel有一个具有两个匹配字段

Symfony Monolog:使用多个格式化程序

如何使用属性#[Embedded]嵌入带有规则的对象集合?

如何使用URL链接(mdl)切换选项卡

致命错误:未捕获错误:Google\Auth\HttpHandler\HttpHandlerFactory::build()

Laravel:测试命令时无法获取工作通知::AssertSentTo

来自POST请求的(无效)json字符串中的奇怪字符(编码问题)

为什么只有最后一次点击的点赞/心形会按预期改变 colored颜色 ,而其他的保持正常 colored颜色 ?

使用与OpenSSL命令行兼容的AES-256-CTR为大型文件创建php代码OpenSSL加密

Azure应用程序无法访问共享文件夹

Shopware 6 插件:如何删除/迁移布尔配置到多选配置

如何使用 PHP 将带有图像的文本上传到 Linkedin?

主机中未检索用户表数据

PHP:数组的等边

Laravel 添加到经过身份验证的用户的数据将应用于每个查询

在 Symfony 测试中何时使用 TestCase 而不是 KernelTestCase

如何使用在产品快速编辑菜单前端的自定义框中 Select 的值更新 woocommerce 产品属性值?

PHP 中的正则表达式,具有字符范围,但不包括特定字符

使用 Eloquent 更新现有的外键值

使用 PHP ImageMagick 库将 pdf 文件的前 n 页转换为单个 png 图像文件