#tronx-payments
1 messages · Page 1 of 1 (latest)
@indigo furnace sure, you can choose the amount you charge. The easiest way is to use Checkout and pass price_data with the dynamic amount your code decides on
it's what the example at https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout does, it passes the amount directly
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
ask for
"line_items[0][price]"=price_H5ggYwtDq4fbrJ \
As tronx ask we no want having product existing in stripe, but don't want embedded paiement form . How can we do it ?
ho! sorry et thanks, i will try it with price_data array
sorry again, i would no pass an item but a global amount that I have already calculated on my server. Please could you help me for that ? Give me a example ?
do the examples above not help?
it's just passing unit_amount: totalMyCodeCalculated , it's all straightforward. Have you tried something that didn't work?
Ithank you for reply ! unit_amount comes with curl https://api.stripe.com/v1/prices \ isn't ?
so did I have to change https://api.stripe.com/v1/checkout/sessions to https://api.stripe.com/v1/prices ?
no..
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data it's a field you can pass when calling the CheckoutSession API.
what code do you have so far? I can maybe show you what has to change.
Yes thank you very much for this help. Let's me trying again before sending my code, to avoid you losting time
I am lost...
here my code :
why are you using curl like that not and not our official PHP library?
I'd highly suggest stopping, and start over with https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout and follow it closely.
your code has a couple of problems (like you're using your public key pk_test_xxx when this API call needs a secret key).
in any case, to pass price_data with code like that, you'd have to change the POST data to something like
'line_items[0][price_data][unit_amount]'=>4200,
'line_items[0][price_data][currency]'=>"usd",
'line_items[0][price_data][product_data][name]'=>"T-shirt",
for instance.
but really you should just replace all this with code using our actual PHP library as documented in the guide.
thank. I already tried the official code but gave me an error, and I passed time but not solved. I will in first time test with your suggest for unit_amount on my code. If not working I will try again official code with your help if you agree👍
ok forget for moment curl
Hey there 👋 I'm stepping in so @sacred merlin take a much needed break. Please bear with me while I get caught up on the context of the thread (but feel free to continue posting as I read)
I have tried this wich is working
echo '<form action="index.php?affPageSite=19" method="POST">';
echo "<script src='https://checkout.stripe.com/checkout.js' class='stripe-button boutons'
data-key='".$secret."' data-amount=".$amount." data-name='".$_SESSION['siteNom']."'
data-email='".$idMail."' data-description='Achat sur ".$_SESSION['siteNom']."'
data-image='".$prodServer."/".$titreImgPt[5]."' data-currency='eur' >";
echo '</script>';
echo '</form>';
But the problem I can't see noting in my dasboard
that code is the legacy version of Checkout so it's not related to what you've been discussing, and you should never use it
ok,
as you says, it give me the error I couldn't resolve :
Fatal error: Uncaught TypeError: Argument 1 passed to Slim\Http\Response::__construct() must implement interface Psr\Http\Message\ResponseInterface, int given, called in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/DefaultServicesProvider.php on line 68 and defined in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/http/src/Response.php:60 Stack trace: #0 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/DefaultServicesProvider.php(68): Slim\Http\Response->__construct() #1 /datas/7Prod/wwwRoot/Sites/include/vendor/pimple/pimple/src/Pimple/Container.php(118): Slim\DefaultServicesProvider->Slim{closure}() #2 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/Container.php(109): Pimple\Container->offsetGet() #3 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/App.php(293): Slim\Container->get() #4 /datas/7Prod/wwwRoot/Sites/laboheme.wbAdm/panier/stripe/old/stripeCheckout.php(40): Slim\App->run() #5 /datas/7Prod/wwwRoot/Sites/laboheme.wbAdm/panier/stripe/modePaie.formStripe.php(79): include('/ in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/http/src/Response.php on line 60
I'am fighting with this error that I don't understand. I copied the code from stripe and only change the key.
Hm, I'm not able to make much sense of that error either. Could you provide the code that results in that error?
yes of course, I have just copied it form stripe with the link you gave me,
int given instead interface Psr\Http\Message\ResponseInterface
but for me I don't understand, perhaps a problem with the librairies ?
Apologies, I'm juggling a couple threads currently so it'll take me a moment to go through this.
No problem, take your time to investigate, I do the same on my side
Could you do me a huge favor though, could you delete your most recent code message and repaste it without the secret key in it?
I'd also recommend rolling that key
yes I will change the keys after, but for moment I just want it to works, ok I remove it from chat
<?php
// This example sets up an endpoint using the Slim framework.
// Watch this video to get started: https://youtu.be/sGcNPFX1Ph4.
use Slim\Http\Request;
use Slim\Http\Response;
use Stripe\Stripe;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->add(function ($request, $response, $next) {
\Stripe\Stripe::setApiKey('sk_test_51JZiq0GPrxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
);
return $next($request, $response);
});
$app->post('/create-checkout-session', function (Request $request, Response $response) {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'T-shirt',
],
'unit_amount' => 2000,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
]);
return $response->withHeader('Location', $session->url)->withStatus(303);
});
$app->run();
?>
Thank you for your patience, I'm still reviewing.
yes ok,
You are here ?
Yes I am, sorry my PHP is a little rusty so I'm consulting with my colleagues.
yes ok, thank you for this 👍
Do you happen to know which version of Slim you have installed? I just noticed they had a recent(ish) release and am wondering if that's relevant.
stripe/stripe-php (v7.100.0)
- Locking nikic/fast-route (v1.3.0)
- Locking psr/container (2.0.1)
- Locking psr/http-factory (1.0.1)
- Locking psr/http-message (1.0.1)
- Locking psr/http-server-handler (1.0.1)
- Locking psr/http-server-middleware (1.0.1)
- Locking psr/log (1.1.4)
- Locking slim/slim (4.9.0)
normaly everything is updated
Thanks for that! Apologies for the seemingly trivial questions, just want to make sure we've covered the basics. You did install our library via composer, right?
No problem, we have to advance. Stripe is intalled via composer
composer require stripe/stripe-php
Using version ^7.100 for stripe/stripe-php
./composer.json has been updated
Running composer update stripe/stripe-php
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the composer fund command to find out more!
You know I am fighting with stripe since 3 days ! But I am not very familiar with API and Object Progamation. Any way, I propose you something to debug step by step: I forget my page, and I use a new blank page from scrtach, as the example on stripe like theis :
<html>
<head>
<title>Buy cool new product</title>
</head>
<body>
<form action="/create-checkout-session" method="POST">
<button type="submit">Checkout</button>
</form>
</body>
</html>
After my question is how can I call the stripeCheckout.php, because for moment the html I give send a 404
something miss me
I understand : action="/create-checkout-session" is an endpoint, but I don't have sympfony neither nodeJs. Can i put instead stripeCheckout.php ? I will test that
Ok, give exactly the same error. So nothing come from my code, but problem with librairies.
Should I try to remove stripe and reinstall with composer ?
Ok, give exactly the same error
what's the error?
also if you're not familiar with programming, maybe use one of our no-code solutions : https://stripe.com/docs/payments/no-code
No I don't want this solution. I am developping myself a CMS under PHP, I already have others kind of payments, that I have put in place in a afternoon with API. But, here I faced this issue only with checkout. For embeeded charges it is ok, as I try it, but I don't really want it, I prefer a checkout solution. But all I tried doesn't work for moment. Certainly for the librairie problem but still not resolved
What is the error message that you are seeing?
Fatal error: Uncaught TypeError: Argument 1 passed to Slim\Http\Response::__construct() must implement interface Psr\Http\Message\ResponseInterface, int given, called in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/DefaultServicesProvider.php on line 68 and defined in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/http/src/Response.php:60 Stack trace: #0 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/DefaultServicesProvider.php(68): Slim\Http\Response->__construct() #1 /datas/7Prod/wwwRoot/Sites/include/vendor/pimple/pimple/src/Pimple/Container.php(118): Slim\DefaultServicesProvider->Slim{closure}() #2 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/Container.php(109): Pimple\Container->offsetGet() #3 /datas/7Prod/wwwRoot/Sites/include/vendor/slim/slim/Slim/App.php(293): Slim\Container->get() #4 /datas/7Prod/wwwRoot/Sites/laboheme.wbAdm/panier/stripe/old/stripeCheckout.php(40): Slim\App->run() #5 /datas/7Prod/wwwRoot/Sites/laboheme.wbAdm/panier/stripe/modePaie.formStripe.php(79): include('/ in /datas/7Prod/wwwRoot/Sites/include/vendor/slim/http/src/Response.php on line 60
to clarify, have you ever used Slim before or are you just using it because it's in our examples?
because we can just ditch that if you want!
I just use it for stripe and follow the Php Slim Starter that you propose.
For some more information : I have just removed slim/http slim/slim and stripe/stripe-php with composer, and the message is the same !! Do you think that's mean in fact it nevers find the librairy (even before when was installed) ?
ok let's forget about Slim
ok,
i agree
so all you really need to get started is something like this ;
<?php
require '../vendor/autoload.php';
$key = "sk_test_xxxx"; // https://dashboard.stripe.com/test/apikeys
\Stripe\Stripe::setApiKey($key);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
echo 'Invalid request';
exit;
}
$checkout_session = \Stripe\Checkout\Session::create([
'success_url' => 'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/canceled.html',
'payment_method_types' => ["card"],
'mode' => 'payment',
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'T-shirt',
],
'unit_amount' => 2000,
],
'quantity' => 1,
]],
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
?>
you can save that somewhere(like checkout.php ) and then use that simple form you mentioned earlier
<html>
<head>
<title>Buy cool new product</title>
</head>
<body>
<form action="/checkout.php" method="POST">
<button type="submit">Checkout</button>
</form>
</body>
</html>
I just tested this and have it running. Can you try? make sure to add your secret key as that $key variable
ok, let's me test
here the result :
Fatal error: Uncaught (Status 400) (Request req_GCE6FWLKRa4UKa) In order to use Checkout, you must set an account or business name at https://dashboard.stripe.com/account. thrown in /datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
I have to set an account ?
you have to set a name
the page will have to show your company's name, "FooBar" in this example), so you need one on your account, per the link in the error message
great!
hopefully now you can see how to expand this and add more code to calculate the amount you want to charge and so on and pass it to unit_amount
Yes, of course, I will have a break before... and follow now the developpements
So the business name should be mandatory when we subscribe ? It is ? Why I missed it ?
I have understand : it is mandatory only for checkout....
yes you need a name, since the page has to show something on that left side column so the customer can see who they're buying from, as in my screenshot
Yes, fine. I thank you very much as I passed a lot of time to make it works. Question for futur : If a need subscription or plan, or others should I nedd Slim or never ?
You can create Subscriptions without Slim as well
Slim is something we use in our docs but it is not necessary to use it to use Stripe
ok, thanks for all. I test again with slim, and it give a different error message when we declare in the php $app = new \slim\app...It wants at least one parameter like something of httpRequestInterface as the construct define it to be mandatory. Perhaps a problem of versionning.
For moment slim/http and slim/slim are removed.
And I see that for subscription we can set the mode to 'subscription', so that fine, I will create the plan manually for me, or by API for my customers if they ask it.
I will now continue to customize Stripe paiement with checkout, and training in deeper way with stripe.
Awesome, let us know if you need more help!
Yes, I have alredy one question, but simply now. Isee when I tried with js there is a field data-image='pathToImage' to change picture of the businness in checkout page. I don't find that with checkout, does it exist ?
I don't really follow what you mean. That code is likely just a really extremely basic example to show a button.
You can do what you want in that case depending on how you integrate Stripe We don't have a "ready to use" button for Checkout, it's something you would add
Sorry, il want to says : how to change the picture in the stripe paiement windows ? Perhaps it is a fied data-image in the form ?
In which stripe paiement window?
which picture are you trying to change, can you show me an example?
Sorry I don't know how to give a screen shot, but it is on the page https://checkout.stripe.com/pay/cs_test_a1kAHcSBF......... on the top of the left side, it is a awesome icon, an when we mouseover a link to go back appear. I wanted to put my logo instead. I already did it with js test.
exemple
@sacred merlin We made it work! Many thanks for the assistance! Great service by the way!
Gotcha, so that is your own account's icon for your business, you configure it here: https://dashboard.stripe.com/settings/branding I think if that's what you meant?