<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mmunir007</title>
    <description>The latest articles on DEV Community by mmunir007 (@mmunir007).</description>
    <link>https://dev.to/mmunir007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F935990%2Fb8a125c3-ef2e-482f-aeef-9d5f3ce760ca.png</url>
      <title>DEV Community: mmunir007</title>
      <link>https://dev.to/mmunir007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mmunir007"/>
    <language>en</language>
    <item>
      <title>how can i add success page with customer details in php slim stripe</title>
      <dc:creator>mmunir007</dc:creator>
      <pubDate>Sun, 02 Oct 2022 12:29:29 +0000</pubDate>
      <link>https://dev.to/mmunir007/how-can-i-add-success-page-with-customer-details-in-php-slim-stripe-aho</link>
      <guid>https://dev.to/mmunir007/how-can-i-add-success-page-with-customer-details-in-php-slim-stripe-aho</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
ini_set('display_errors',1);
error_reporting(E_ALL);

use Slim\Http\Request;
use Slim\Http\Response;
use Stripe\Stripe;




require 'vendor/autoload.php';

$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv-&amp;gt;load();

require './config.php';

$app = new \Slim\App;

$app-&amp;gt;add(function ($request, $response, $next) {
    Stripe::setApiKey(getenv('STRIPE_SECRET_KEY'));
    return $next($request, $response);
});

$app-&amp;gt;get('/', function (Request $request, Response $response, array $args) {
  return $response-&amp;gt;write(file_get_contents(getenv('STATIC_DIR') . '/index.html'));
});

$app-&amp;gt;post('/checkout_sessions', function(Request $request, Response $response) use ($app)  {
  $params = json_decode($request-&amp;gt;getBody());
  $payment_method_types = [
    'usd' =&amp;gt; ['card'],
    'eur' =&amp;gt; ['card'],
    'cad' =&amp;gt; ['card']
  ];
  $products = [
    'cause-a' =&amp;gt; 'prod_KP3YP2a3IGYqsb',
    'cause-b' =&amp;gt; 'prod_KP3iZRGcEjn5W8',
  ];

  $session = \Stripe\Checkout\Session::create([
    'success_url' =&amp;gt; 'http://localhost:4242/?success=true',
    'cancel_url' =&amp;gt; 'http://localhost:4242/?cancel=true',
    'mode' =&amp;gt; 'payment',
    'payment_method_types' =&amp;gt; $payment_method_types[$params-&amp;gt;currency],
    'metadata' =&amp;gt; [
      'cause' =&amp;gt; $params-&amp;gt;cause,
      'currency' =&amp;gt; $params-&amp;gt;currency,
    ],
    'submit_type' =&amp;gt; 'donate',
    'line_items' =&amp;gt; [[
      'price_data' =&amp;gt; [
        'currency' =&amp;gt; $params-&amp;gt;currency,
        'product' =&amp;gt; $products[$params-&amp;gt;cause],
        'unit_amount' =&amp;gt; $params-&amp;gt;amount,
      ],
      'quantity' =&amp;gt; 1,
    ]]
  ]);

  return $response-&amp;gt;withJson([
    'id' =&amp;gt; $session-&amp;gt;id
  ]);
});

$app-&amp;gt;post('/webhook', function(Request $request, Response $response) {
    $params = json_decode($request-&amp;gt;getBody(), true);
    $event = \Stripe\Event::constructFrom($params);
    switch($event-&amp;gt;type) {
      case 'checkout.session.completed':
        $session = $event-&amp;gt;data-&amp;gt;object;
        ob_start();
        var_dump('Checkout session completed!' . $session-&amp;gt;id);
        error_log(ob_get_clean(), 4);
        break;
    }

    return $response-&amp;gt;withJson([ 'status' =&amp;gt; 'success' ])-&amp;gt;withStatus(200);
});



$app-&amp;gt;run();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=FOLRATK4pVA"&gt;https://www.youtube.com/watch?v=FOLRATK4pVA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;i was trying this to learn stripe and i was wondering how can i show cause amount and customer details on success page so it can be used for verification what cause he paid for? &lt;/p&gt;

</description>
      <category>php</category>
      <category>stripe</category>
    </item>
  </channel>
</rss>
