Stripe PHP Redirect after Purchase - php

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

Related

Stripe creating Checkout session throws error ( Stripe\Exception\InvalidRequestException Invalid array )

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);
}

Extend an assiociative Array with variable

can someone help me, how I can extend an assiociative array with a variable?
I have a loop (foreach):
foreach($this->getWarehouseListForm() as $wareHouse) {
$wareHouseList[] =
[
"title" => "wareHouse[105]",
"form" => [
"storeId[105]" => [
"type" => "inputText",
"options" => [
"name" => "TSL",
],
],
],
];
}
And I want to extend a object like this:
"sections" => [
[
"title" => 'Schuhe24Assistant.ftpServerTitle',
"description" => 'Schuhe24Assistant.ftpServerDescription',
"form" => [
"ftpServer" => [
'type' => 'text',
'defaultValue' => 'ftp.hisasp2.com',
'options' => [
'name' => 'Schuhe24Assistant.ftpServer',
'required' => true,
]
],
"ftpUser" => [
'type' => 'text',
'defaultValue' => 'username',
'options' => [
'name' => 'Schuhe24Assistant.ftpUser',
'required' => true,
]
],
"ftpPassword" => [
'type' => 'text',
'defaultValue' => 'password',
'options' => [
'name' => 'Schuhe24Assistant.ftpPassword',
#'isPassword' => true,
'required' => true,
],
],
"deleteFiles" => [
'type' => 'toggle',
'defaultValue' => true,
'options' => [
'name' => 'Schuhe24Assistant.deleteFiles',
],
],
],
],
], $wareHouseList
But this code produces nothing (no error output) and the structure check fails in this case. If I remove the variable, the structure check is OK.
Can someone help me out?
Kind regards
Henning
Push your $wareHouseList array into the $sections array in the following ways
$sections['wareHouseList'] = $wareHouseList
It should be working.

Implement suggest function of elasticsearch-php client in my API

I am trying to implement the suggest function of elasticsearch-php client in my API to suggest people some already existing problems.
I have made index for my problems
'index' => 'newproblemindex',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2
],
'mappings' => [
'newproblems' => [ // type of index
'_source' => [
'enabled' => true
],
'properties' => [
'title' => [
'type' => 'text',
'analyzer' => 'standard'
],
'description' => [
'type' => 'text',
'analyzer' => 'standard'
], 'suggest' => [
'type' => 'completion'
]
]
]
]
]
But I am unable to find which param fields to use to implement suggest function
'index' => 'newproblemindex',
'body' => [
'try' => [
'text' => $request->search_key,
'completion' => [ 'text' => 'suggest' ]
]
],
I am using laravel and taking search_key as request param but I am getting "invalid_type_name_exception" and when I tried to give the type name, it is again giving me some error.
"suggest" => [
"song-suggest" => [
"prefix" => $request->search_key,
"completion" => ["field" => "suggest"]
]
]
I am getting error "suggest is not a valid param ". Please help
and Thanks in advance.

How to optimize elastic search query

I have been reading through elastic search docs over the last few months and have continued to optimize my query, but I can't seem to get a search query below 500-600ms. Locally with less data I can get responses in ~80-200ms.
To outline what I am trying to accomplish:
I have 12 different models in Laravel that are searchable from a single search bar. As someone types it is searched and returned in a list of results.
Currently, I have this for my search query. Are there any references for how I can improve this? I looked into multi_match, but I was having issues with partial matches and specifying all fields.
$results = $this->elastic->search([
'index' => config('scout.elasticsearch.index'),
'type' => $type ?? implode(',', array_keys($this->permissions, true, true)),
'body' => [
'query' => [
'bool' => [
'must' => [
[
'query_string' => [
'query' => "$searchQuery*",
],
],
],
'filter' => [
[
'term' => [
'account_id' => $accountId,
],
],
],
'should' => [
[
'term' => [
'_type' => [
'value' => 'customers',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'contacts',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'users',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'chart_accounts',
'boost' => 1.2,
],
],
],
],
],
],
'from' => $from,
'size' => $size,
],
]);

As in Yii 2.0 (Menu :: Widget ) use the span?

When I use the following code, the end result is " TEST " and should be "TEST" in the tags .
echo Menu::widget([
'options' => ['id' => 'navigate'],
'items' => [
[
'label' => '<span>TEST</span>',
'url' => ['#'],
],
['label' => '<span>TEST2</span>', 'url' => ['#']],
],
]);
I know I should use encodeLabel but does not work and returns an error. Can you do to help?
It works fine for me:
echo Menu::widget([
'options' => ['id' => 'navigate'],
'encodeLabels' => false,
'items' => [
[
'label' => '<span>TEST</span>',
'url' => ['#'],
],
['label' => '<span>TEST2</span>', 'url' => ['#']],
],
]);

Categories