I am getting following error when trying to get page url
$YOUR_DOMAIN = $_SERVER['HTTPS'];
$v=$_POST['price'];
$p=$_POST['product'];
$d=$_POST['domain'];
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount' => $v,
'product_data' => [
'name' => $p,
'images' => ["https://i.imgur.com/EHyR2nP.png"],
],
],
'quantity' => 1,
]],
"metadata[domain]"=>$d,
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success.php?domain='.$d,
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
]);
Fatal error: Uncaught (Status 400) (Request
req_FafwbsfPd38bhj) Not a valid URL
Use $_SERVER['SERVER_NAME'] instead of $_SERVER['HTTPS']
Related
I just want to add a redirect to a certain url after purchase by using the Stripe API for PHP. My approach so far is:
$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=' . $product['default_price'] . '',
],
'type' => 'redirect'
],
]);
but it's not working. Any hints what's going wrong here?
Thanks in advance!
Your request body is malformatted at the after_completion attribute level[1].
You should do like this instead:
$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=' . $product['default_price'] . '',
],
'type' => 'redirect'
],
]);
[1] https://stripe.com/docs/api/payment_links/payment_links/create#create_payment_link-after_completion
I've been trying to create a checkout session for a payment which should be directed in connected account.
whenever I'm trying to create a session using the code below I get InvalidRequestException saying Invalid array
Here's my code below,
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [
'price_data' => [
'unit_amount' => 25000,
'currency' => 'usd',
'product_data' => ['name' => 'Product8', 'active' => true],
],
'quantity' => 2,
],
'mode' => 'payment',
'success_url' => 'http://devweb.drivinggradebook.com/',
'cancel_url' => 'https://www.drivinggradebook.com/',
'payment_intent_data' => [
'application_fee_amount' => 10,
],
], ['stripe_account' => 'acct_1L7ugjSJzLhcy6eF']);
Please help me out with it,
Thanks
In my case I have it running as follows with laravel 8.75 and stripe/stripe-php 10.1
public function checkout(Request $request)
{
\Stripe\Stripe::setApiKey(STRIPE_SECRET);
header('Content-Type: application/json');
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [
[
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => 'Home'
],
'unit_amount' => 500
],
'quantity' => 1
],
],
'mode' => 'payment',
'success_url' => url("/stripe_success?session_id={CHECKOUT_SESSION_ID}&tenant_id=$request->id"),
'cancel_url' => route('payments.index'),
]);
return redirect()->away($checkout_session->url);
}
Can anyone help me? I migrate form v2 to v3 checkout.
how can I send my custom description order in stripe dashboard description column?
now I get only the payment id pi_1IrhQALKfdoxxl3X07seJ5anto
with old API by description I would do:
$charge = \Stripe\Charge::create(array(
"amount" => $_POST['amount'],
"currency" => "EUR",
"description" => "Order #".$_POST["order"],
"source" => $token,
));
with the new API :
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'payment_method_types' => ['card'],
'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
'mode' => 'payment',
]);
Thank you
according to the stripe documentation : https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-description
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'payment_method_types' => ['card'],
'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
'mode' => 'payment',
'payment_intent_data' => [
'description' => "Order #".$_POST["order"]
]
]);
I developped the last Stripe module for the end of the year as they ask, but since I put it, I haven't any more the description and the name of the customer in Stripe.
Do you know how can I put it again ?
This is my code in PHP :
try {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'customer_email' => $email,
'line_items' => [[
'price_data' => [
'product_data' => [
'name' => $custom['item_name'],
'metadata' => [
'pro_id' => $custom['item_name']
]
],
'unit_amount' => (isset($custom['amountTotal']) ? $custom['amountTotal'] : $custom['amount'])*100,
'currency' => $custom['currency_code'],
],
'quantity' => 1,
'description' => $custom['item_name'],
]],
'mode' => 'payment',
'success_url' => $url,
'cancel_url' => $request->cancel,
], ['stripe_account' => $_SESSION['param']->stripeUID]);
}catch(Exception $e) {
$api_error = $e->getMessage();
}
if(empty($api_error) && $session){
$response = array(
'status' => 1,
'message' => 'Checkout Session created successfully!',
'sessionId' => $session['id']
);
}else{
$response = array(
'status' => 0,
'error' => array(
'message' => 'Checkout Session creation failed! '.$api_error
)
);
}
And this is what I have now
You should be able to set it here: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-description
just add this line so the description appears, I mark it with asterisks or in bold
'payment_method_types' => ['card'],
'**payment_intent_data**' => [
'description' => ''.$productName.''
],
'line_items' => [[
'price_data' => [
'product_data' => [
'name' => $productName,
'description' => ''.$productName.'',
'metadata' => [
'pro_id' => $productID
]
],
'unit_amount' => $stripeAmount,
'currency' => $currency,
],
'quantity' => 1,
'description' => $descripcion,
]],
'mode' => 'payment',
I'm trying to create a cloudfront distribution while doing the authentication via hardcoded credentials.
However i receive this error when i run my code
Fatal error: Uncaught Aws\Exception\CredentialsException: Cannot read credentials from /.aws/credentials
It seems that the aws sdk is trying to authentificate using the second method listed here ( https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html ) - the one when you put the credentials in ./aws folder
Here is my code (taken from aws documentation ) - Any idea why this is not working ?
public function create_cloudfront_client(){
$region='us-east-1';
$client = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => 'latest',
'region' => 'us-east-1',
'debug' => true,
'credentials' =>[
'key' => $this->aws_key,
'secret' => $this->aws_secret,
],
]);
$originName = 'cloudfrontme';
$s3BucketURL = 'https://s3.amazonaws.com/cloudfrontme';
$callerReference = 'uniquestring99';
$comment = 'Created by AWS SDK for PHP';
$cacheBehavior = [
'AllowedMethods' => [
'CachedMethods' => [
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Items' => ['HEAD', 'GET'],
'Quantity' => 2,
],
'Compress' => false,
'DefaultTTL' => 0,
'FieldLevelEncryptionId' => '',
'ForwardedValues' => [
'Cookies' => [
'Forward' => 'none',
],
'Headers' => [
'Quantity' => 0,
],
'QueryString' => false,
'QueryStringCacheKeys' => [
'Quantity' => 0,
],
],
'LambdaFunctionAssociations' => ['Quantity' => 0],
'MaxTTL' => 0,
'MinTTL' => 0,
'SmoothStreaming' => false,
'TargetOriginId' => $originName,
'TrustedSigners' => [
'Enabled' => false,
'Quantity' => 0,
],
'ViewerProtocolPolicy' => 'allow-all',
];
$enabled = false;
$origin = [
'Items' => [
[
'DomainName' => $s3BucketURL,
'Id' => $originName,
'OriginPath' => '',
'CustomHeaders' => ['Quantity' => 0],
'S3OriginConfig' => ['OriginAccessIdentity' => ''],
],
],
'Quantity' => 1,
];
$distribution = [
'CallerReference' => $callerReference,
'Comment' => $comment,
'DefaultCacheBehavior' => $cacheBehavior,
'Enabled' => $enabled,
'Origins' => $origin,
];
try {
$result = $client->createDistribution([
'DistributionConfig' => $distribution, //REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}
}
The solution was to create the cloudfront client like this
$client = Aws\CloudFront\CloudFrontClient::factory(array(
'region' => $bucket_region,
'version' => 'latest',
'credentials' => [
'key' => $this->aws_key,
'secret' => $this->aws_secret,
]
));
However i don't understand why this version works while the one below (from aws docs ) does not. Can anyone explain this ?
Thanks
$client = new Aws\CloudFront\CloudFrontClient([
'version' => 'latest',
'region' => $bucket_region,
'debug' => true,
'credentials' =>[
'key' => $this->aws_key,
'secret' => $this->aws_secret,
],
]);