简体   繁体   English

如何检索条带会话ID php

[英]How to retrieve stripe session id php

I hate to ask such a simple question on here but I can't seem to figure this out.我讨厌在这里问这么简单的问题,但我似乎无法弄清楚。 I create a stripe checkout session that goes through successfully, but am having trouble getting a response.我创建了一个成功通过的条带结帐会话,但无法获得响应。 I have read through stripe docs and answers on here, but still cannot seem to get the stripe session id returned.我已经阅读了此处的条带文档和答案,但似乎仍然无法返回条带会话 ID。 Here's what I have tried这是我尝试过的

<?php

require_once('stripe-php-7.86.0/init.php');

$priceId = $_POST['priceId'];

$stripe = new \Stripe\StripeClient(
    'my secret key here'
  );

  $stripe->checkout->sessions->create([
    'success_url' => 'http://localhost/stripe_test/success.html',
    'cancel_url' => 'http://localhost/stripe_test/cancel.html',
    'payment_method_types' => ['card'],
    'line_items' => [
      [
        'price' => $priceId,
        'quantity' => 1,
      ],
    ],
    'mode' => 'subscription',
  ]);

  // I've tried all of these individually, none of them work.
  
  echo json_encode($stripe);
  echo $stripe['id'];
  echo json_encode($stripe['id']);
  echo $stripe->checkout->sessions['id'];
  echo json_encode(['sessionId' => $stripe['id']]);

As per the official Stripe documentation , you can to assign the returned value of $stripe->checkout->sessions->create to the variable you want to use, then access the property id .根据官方 Stripe 文档,您可以将$stripe->checkout->sessions->create的返回值分配给您要使用的变量,然后访问属性id

$stripe->checkout->sessions->create returns the Session object $stripe->checkout->sessions->create返回Session object

For example例如

$stripe_session = $stripe->checkout->sessions->create([
    'success_url' => 'http://localhost/stripe_test/success.html',
    'cancel_url' => 'http://localhost/stripe_test/cancel.html',
    'payment_method_types' => ['card'],
    'line_items' => [
      [
        'price' => $priceId,
        'quantity' => 1,
      ],
    ],
    'mode' => 'subscription',
  ]);
echo $stripe_session->id;

我认为 response->id 将是你的会话 ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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