首页 > 解决方案 > 条纹 webhook 给出空白页面看不到页面

问题描述

在条纹 webhook 付款成功后,我想发送一封电子邮件并将数据插入数据库。但是当付款成真时,您在我已包含在成功页面中的页面上看不到成功消息。页面完全空白。

当我插入我的 sendemail() 函数时,它不想插入数据并发送电子邮件,它说 $email = $_get['email'] not defined 但我包含了我的 fetch.php 我从url: cadeau.php?bon=voetbehandeling&client_secret=src_client_secret_E745XOwwOtHh45umH8WM6iGA&email=test%40gmail.com&id=581584884891450162oaana&livemode=false&source=src_1GPU9uGzJT0kic6B2AxtPOAh

脚本.js

  var idealBank = elements.create('idealBank', options);

// Add an instance of the idealBank Element into
// the `ideal-bank-element` <div>.
idealBank.mount('#ideal-bank-element');
idealBank.on('change', function(event) {
  var bank = event.value;
  // Perform any additional logic here...

});
// Create a source or display an error when the form is submitted.
var form = document.getElementById('payment-form');

form.addEventListener('submit', function(event) {
  event.preventDefault();
  var randNo = Math.floor(Math.random() * 100) + 2 + "" + new Date().getTime() +  Math.floor(Math.random() * 100) + 2 + (Math.random().toString(36).replace(/[^a-zA-Z]+/g, '').substr(0, 5));
  var email = document.querySelector('input[name="email"]').value;
  var sourceData = {
    type: 'ideal',
    amount: price,
    currency: 'eur',
    statement_descriptor: 'U heeft een tegoedbon gekocht = ' + bon,
    owner: {
      name: document.querySelector('input[name="name"]').value,
      email: document.querySelector('input[name="email"]').value,
    },
    // Specify the URL to which the customer should be redirected
    // after paying.
    redirect: {
      return_url: 'https://www.pedicurepraktijkpapendrecht.nl/stripe/cadeau.php' + '?email=' + email + '&id=' + randNo + '&bon=' + bon,

    },
  };

  // Call `stripe.createSource` with the idealBank Element and
  // additional options.
  stripe.createSource(idealBank, sourceData).then(function(result) {
    if (result.error) {
      // Inform the customer that there was an error.
      var errorElement = document.getElementById('error-message');
      errorElement.textContent = error.message;
    } else {
      // Redirect the customer to the authorization URL.
      stripeSourceHandler(result.source);
    }
  });
});


function stripeSourceHandler(source) {
  // Redirect the customer to the authorization URL.
  document.location.href = source.redirect.url;
}

成功页面

    ?php
include('./webhook.php');
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="https://js.stripe.com/v3/"></script>
    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"
        integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="style.css">
    <title>Email versturen naar uw email!</title>
</head>

<body>
    <div class="form-row">
        <h1>Bedankt voor het kopen van een tegoedbon!</h1>
        <p>Uw tegoedbon word gestuurd naar uw email!</p>
        <div class="flex">
            <a href="https://www.pedicurepraktijkpapendrecht.nl/"
                class="btn text-center margin-right max-width">Naar de
                website</a>
            <a href="checkout.php" class="btn text-center margin-right max-width">Nog een tegoedbon kopen?</a>
        </div>

    </div>

</body>

网络钩子.php

    require('./vendor/autoload.php');
$endpoint_secret = 'whsec_4lLBwyPL7TG2zi4Azl8Q5KBggzOZUqet';


$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;

try {
    $event = \Stripe\Webhook::constructEvent(
        $payload, $sig_header, $endpoint_secret
    );
} catch(\UnexpectedValueException $e) {
    // Invalid payload
    http_response_code(400);
    exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
    // Invalid signature
    http_response_code(400);
    exit();
}

if ($event->type == "source.chargeable") {
    $intent = $event->data->object;
    printf("Succeeded: %s", $intent->id);
    http_response_code(200);
    exit();
} elseif ($event->type == "source.failed") {
    $intent = $event->data->object;
    $error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
    printf("Failed: %s, %s", $intent->id, $error_message);
    http_response_code(200);
    exit();
}
?>

标签: phpstripe-payments

解决方案


推荐阅读