Ошибка добавления клиентов в подписку в полосе - PullRequest
0 голосов
/ 15 апреля 2019

Я пытаюсь создать клиента и создать подписку.

  • Но когда я делаю это, я получаю ошибку.
  • Я попытался сделать это способом node.js и php. через node.js
  • Я установил stripe и через php установил composer и stripe / stripe-php.

Когда я делаю это с помощью javascript, все находит и удобно, без ошибок, но когда я перехожу на панель мониторинга полос, в данных тестового режима не создается новое создание клиента или подписки.

<?php // Create a customer using a Stripe token

// If you're using Composer, use Composer's autoload:
require_once('vendor/autoload.php');

// Be sure to replace this with your actual test API key
// (switch to the live key later)
\Stripe\Stripe::setApiKey("pk_test_pjUIBAynO2WA1gA7woSLBny3");

try
{
  $customer = \Stripe\Customer::create([
    'email' => $_POST['stripeEmail'],
    'source'  => $_POST['stripeToken'],
  ]);

  $subscription = \Stripe\Subscription::create([
    'customer' => $customer->id,
    'items' => [['plan' => 'gold']],
  ]);

  if ($subscription->status != 'incomplete')
  {
    header('Location: thankyou.html');
  }
  else
  {
    header('Location: payment_failed.html');
    error_log("failed to collect initial payment for subscription");
  }
  exit;
}
catch(Exception $e)
{
  header('Location:oops.html');
  error_log("unable to sign up customer:" . $_POST['stripeEmail'].
    ", error:" . $e->getMessage());
}

и это HTML-файл

<form action="/create_subscription.php" id="start" method="POST">
                <script
                  src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                  data-key="pk_test_pjUIBAynO2WA1gA7woSLBny3"

                  data-name="500 a month package"
                  data-description="Subscription will be billed every 30 days"
                  data-amount="50000"
                  data-label="Get Started!">
                </script>
                <script>
                  var stripe = require("stripe")("pk_test_pjUIBAynO2WA1gA7woSLBny3");
                  var stripeToken = req.body.stripeToken;
                  stripe.subscriptions.create({
                  customer: id,
                  items: [
                    {
                       plan: "prod_EtGDP9qICl6tvW",
                       interval: "month"
                      },
                  ]

                      }  , function(err, subscription) {
                  // asynchronously called
                  function(err, custumor){
                  if(err){
                    res.send({
                      success: false,
                      message:'Error'
                    });
                  } else {
                    const { id } = customer;
                  }
           };
              stripe.customers.create({
                email:"jenny@rosen.com",
                source: stripeToken,
               },
                function(err, custumor){
                  if(err){
                    res.send({
                      success: false,
                      message:'Error'
                    });
                  } else {
                    const { id } = customer;
                  }
                });
                </script>
              </form>
...