#simon-paymentlinks

1 messages · Page 1 of 1 (latest)

vast vale
#

hi! which part is not working exactly?

#

it returns a complete white page with no errors
@pulsar ore can you check your PHP server error log?

also are there any errors on API requests to Stripe? https://dashboard.stripe.com/test/logs

#

I think your syntax is wrong though, you have an extra [ ]

#
'after_completion' => [
   'redirect' => [
            'url' => 'https://www.trainer-va.de/Trainer-Cloud/123.php?product=' . $product['default_price'] . '',
    ],
    'type' => 'redirect'
],

should be that I would think

pulsar ore
#

it's still not working, returning a blank page. But I turned PHP Error Reporting 'ON' ?!

vast vale
#

I mean that code as written doesn't actually echo anything

#

so a blank page would be expected.

pulsar ore
#

I could echo $link

#

somewhere I missed the point. Wrong syntax for the stripe object with a redirect?

vast vale
#

you could! depends what your overall goal is

pulsar ore
#

just to create a link with a redirect

vast vale
#

and what do you do with the link once it's created?

pulsar ore
#

just embedd it in an HTML button "BUY NOW"

vast vale
#

cool, so where's the code that does that part?

pulsar ore
#

<?php

$stripe = new \Stripe\StripeClient(
'sk_live_xxx'
);
$prodarray = $stripe->products->all(['limit' => 30]);

$interval = "";
$payment_url = "";

foreach($prodarray->data as $product){
echo "<b>" . $product['name'] . "</b><br/>";
echo $product['description'];

$price = $stripe->prices->retrieve(
    $product['default_price'],
    []
);

if ($price['recurring'] != null) {
    if ($price['recurring']['interval'] == "month") {
        $interval = " / Monat";
    }

    if ($price['recurring']['interval'] == "year") {
        $interval = " / Jahr";
    }
    
}

$link = $stripe->paymentLinks->create([
    'line_items' => [
        [
        'price' => $product['default_price'],
        'quantity' => 1,
        ],  
    ],
   'after_completion' => [
    'redirect' => [
        'url' => 'https://www.trainer-va.de/Trainer-Cloud/123.php?product=',
    ],
    'type' => 'redirect',
    ],


    ]

]);



$price_amount = ($price['unit_amount'] / 100) . " €". $interval;

echo "<div class=\"cta-cta\">";
echo "<a class=\"button button-primary\" href=\"" . $link['url'] . "\">" .$price_amount . "</a>";
echo "</div>";
echo "</p>";

$interval = "";
$payment_url = "";

}

?>

vast vale
#

cool, if you add an echo("link created") before the line with $price_amount is the code reaching that point?

#

have you tried wrapping the call to Stripe in a try/catch and echo-ing the exception? Have you looked at your Stripe API logs?

pulsar ore
#

no, no entry in the Stripe API logs

#

it's not reaching the line

#

when I remove the "after_completion" object everything works except the redirect

vast vale
#

there's an extra unmatched ] in that code you posted

#

sorry but you need to debug this a little on your side too

#
$link = $stripe->paymentLinks->create([
     'line_items' => [
         [
         'price' => "price_xxx",
         'quantity' => 1,
         ],
     ],
    'after_completion' => [
     'redirect' => [
         'url' => 'https://www.example.com',
     ],
     'type' => 'redirect',
     ],
 ]);
``` works fine for me