I am using a php, balde, laravel system and I want to be able to pass data from another class/component, likely as an array and then dump the array data into the line items of the stripe hosted checkout.
I am new to php and laravel and I have tried several ways, every method I have tried it says undefined…
<code> public function fetchPartials()
{
$this->prepareVars();
return [
'#cart-items' => $this->renderPartial('@items'),
'#cart-coupon' => $this->renderPartial('@coupon_form'),
'#cart-tip' => $this->renderPartial('@tip_form'),
'#cart-totals' => $this->renderPartial('@totals'),
'#cart-buttons' => $this->renderPartial('@buttons'),
'[data-cart-total]' => currency_format(Cart::total()),
'[data-cart-count]' => Cart::count(),
'#notification' => $this->renderPartial('flash'),
];
}
</code>
<code> public function fetchPartials()
{
$this->prepareVars();
return [
'#cart-items' => $this->renderPartial('@items'),
'#cart-coupon' => $this->renderPartial('@coupon_form'),
'#cart-tip' => $this->renderPartial('@tip_form'),
'#cart-totals' => $this->renderPartial('@totals'),
'#cart-buttons' => $this->renderPartial('@buttons'),
'[data-cart-total]' => currency_format(Cart::total()),
'[data-cart-count]' => Cart::count(),
'#notification' => $this->renderPartial('flash'),
];
}
</code>
public function fetchPartials()
{
$this->prepareVars();
return [
'#cart-items' => $this->renderPartial('@items'),
'#cart-coupon' => $this->renderPartial('@coupon_form'),
'#cart-tip' => $this->renderPartial('@tip_form'),
'#cart-totals' => $this->renderPartial('@totals'),
'#cart-buttons' => $this->renderPartial('@buttons'),
'[data-cart-total]' => currency_format(Cart::total()),
'[data-cart-count]' => Cart::count(),
'#notification' => $this->renderPartial('flash'),
];
}
<code><div class="cart-items pt-2">
<ul>
@foreach ($order->getOrderMenusWithOptions() as $orderItem)
<li>
<span class="price pull-right">{{ currency_format($orderItem->subtotal) }}</span>
<span class="name fw-bold">
@if ($orderItem->quantity > 1)
<span class="quantity">
{{ $orderItem->quantity }} @lang('igniter.cart::default.text_times')
</span>
@endif
{{ $orderItem->name }}
</span>
@php $itemOptionGroup = $orderItem->menu_options->groupBy('order_option_category') @endphp
@if ($itemOptionGroup->isNotEmpty())
<ul class="list-unstyled small">
@foreach ($itemOptionGroup as $itemOptionGroupName => $itemOptions)
<li>
<u class="text-muted">{{ $itemOptionGroupName }}:</u>
<ul class="list-unstyled">
@foreach ($itemOptions as $itemOption)
<li>
@if ($itemOption->quantity > 1)
{{ $itemOption->quantity }} @lang('igniter.cart::default.text_times')
@endif
{{ $itemOption->order_option_name }}
@if ($itemOption->order_option_price > 0)
({{ currency_format($itemOption->quantity * $itemOption->order_option_price) }})
@endif
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
@endif
@if (!empty($orderItem->comment))
<p class="comment text-muted small">
{!! $orderItem->comment !!}
</p>
@endif
</li>
@endforeach
</ul>
</div>
</code>
<code><div class="cart-items pt-2">
<ul>
@foreach ($order->getOrderMenusWithOptions() as $orderItem)
<li>
<span class="price pull-right">{{ currency_format($orderItem->subtotal) }}</span>
<span class="name fw-bold">
@if ($orderItem->quantity > 1)
<span class="quantity">
{{ $orderItem->quantity }} @lang('igniter.cart::default.text_times')
</span>
@endif
{{ $orderItem->name }}
</span>
@php $itemOptionGroup = $orderItem->menu_options->groupBy('order_option_category') @endphp
@if ($itemOptionGroup->isNotEmpty())
<ul class="list-unstyled small">
@foreach ($itemOptionGroup as $itemOptionGroupName => $itemOptions)
<li>
<u class="text-muted">{{ $itemOptionGroupName }}:</u>
<ul class="list-unstyled">
@foreach ($itemOptions as $itemOption)
<li>
@if ($itemOption->quantity > 1)
{{ $itemOption->quantity }} @lang('igniter.cart::default.text_times')
@endif
{{ $itemOption->order_option_name }}
@if ($itemOption->order_option_price > 0)
({{ currency_format($itemOption->quantity * $itemOption->order_option_price) }})
@endif
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
@endif
@if (!empty($orderItem->comment))
<p class="comment text-muted small">
{!! $orderItem->comment !!}
</p>
@endif
</li>
@endforeach
</ul>
</div>
</code>
<div class="cart-items pt-2">
<ul>
@foreach ($order->getOrderMenusWithOptions() as $orderItem)
<li>
<span class="price pull-right">{{ currency_format($orderItem->subtotal) }}</span>
<span class="name fw-bold">
@if ($orderItem->quantity > 1)
<span class="quantity">
{{ $orderItem->quantity }} @lang('igniter.cart::default.text_times')
</span>
@endif
{{ $orderItem->name }}
</span>
@php $itemOptionGroup = $orderItem->menu_options->groupBy('order_option_category') @endphp
@if ($itemOptionGroup->isNotEmpty())
<ul class="list-unstyled small">
@foreach ($itemOptionGroup as $itemOptionGroupName => $itemOptions)
<li>
<u class="text-muted">{{ $itemOptionGroupName }}:</u>
<ul class="list-unstyled">
@foreach ($itemOptions as $itemOption)
<li>
@if ($itemOption->quantity > 1)
{{ $itemOption->quantity }} @lang('igniter.cart::default.text_times')
@endif
{{ $itemOption->order_option_name }}
@if ($itemOption->order_option_price > 0)
({{ currency_format($itemOption->quantity * $itemOption->order_option_price) }})
@endif
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
@endif
@if (!empty($orderItem->comment))
<p class="comment text-muted small">
{!! $orderItem->comment !!}
</p>
@endif
</li>
@endforeach
</ul>
</div>
StripeCheckout.php
<code>protected function getPaymentFormFields($order, $data = [])
{
$cancelUrl = $this->makeEntryPointUrl('stripe_checkout_cancel_url').'/'.$order->hash;
$successUrl = $this->makeEntryPointUrl('stripe_checkout_return_url').'/'.$order->hash;
$successUrl .= '?redirect='.array_get($data, 'successPage').'&cancel='.array_get($data, 'cancelPage');
$fields = [
'line_items' => [
[
'price_data' => [
'currency' => currency()->getUserCurrency(),
// All amounts sent to Stripe must be in integers, representing the lowest currency unit (cents)
'unit_amount_decimal' => number_format($order->order_total, 2, '.', '') * 100,
'product_data' => [
'name' => $options[] = $cartOption,
],
],
'quantity' => 1,
],
],
'cancel_url' => $cancelUrl.'?redirect='.array_get($data, 'cancelPage'),
'success_url' => $successUrl,
'mode' => 'payment',
'metadata' => [
'order_id' => $order->order_id,
],
'payment_intent_data' => [
'capture_method' => $this->shouldAuthorizePayment() ? 'manual' : 'automatic',
],
];
// Share the email field in our form to Stripe checkout session,
// so customers don't need to enter twice
if (!is_null(array_get($data, 'email'))) {
// if is unregistered customer
$fields['customer_email'] = array_get($data, 'email');
} elseif (!is_null($order->customer) && !is_null($order->customer->email)) {
// else if is registered, get email from customer profile
$fields['customer_email'] = $order->customer->email;
}
$this->fireSystemEvent('payregister.stripecheckout.extendFields', [&$fields, $order, $data]);
return $fields;
}
</code>
<code>protected function getPaymentFormFields($order, $data = [])
{
$cancelUrl = $this->makeEntryPointUrl('stripe_checkout_cancel_url').'/'.$order->hash;
$successUrl = $this->makeEntryPointUrl('stripe_checkout_return_url').'/'.$order->hash;
$successUrl .= '?redirect='.array_get($data, 'successPage').'&cancel='.array_get($data, 'cancelPage');
$fields = [
'line_items' => [
[
'price_data' => [
'currency' => currency()->getUserCurrency(),
// All amounts sent to Stripe must be in integers, representing the lowest currency unit (cents)
'unit_amount_decimal' => number_format($order->order_total, 2, '.', '') * 100,
'product_data' => [
'name' => $options[] = $cartOption,
],
],
'quantity' => 1,
],
],
'cancel_url' => $cancelUrl.'?redirect='.array_get($data, 'cancelPage'),
'success_url' => $successUrl,
'mode' => 'payment',
'metadata' => [
'order_id' => $order->order_id,
],
'payment_intent_data' => [
'capture_method' => $this->shouldAuthorizePayment() ? 'manual' : 'automatic',
],
];
// Share the email field in our form to Stripe checkout session,
// so customers don't need to enter twice
if (!is_null(array_get($data, 'email'))) {
// if is unregistered customer
$fields['customer_email'] = array_get($data, 'email');
} elseif (!is_null($order->customer) && !is_null($order->customer->email)) {
// else if is registered, get email from customer profile
$fields['customer_email'] = $order->customer->email;
}
$this->fireSystemEvent('payregister.stripecheckout.extendFields', [&$fields, $order, $data]);
return $fields;
}
</code>
protected function getPaymentFormFields($order, $data = [])
{
$cancelUrl = $this->makeEntryPointUrl('stripe_checkout_cancel_url').'/'.$order->hash;
$successUrl = $this->makeEntryPointUrl('stripe_checkout_return_url').'/'.$order->hash;
$successUrl .= '?redirect='.array_get($data, 'successPage').'&cancel='.array_get($data, 'cancelPage');
$fields = [
'line_items' => [
[
'price_data' => [
'currency' => currency()->getUserCurrency(),
// All amounts sent to Stripe must be in integers, representing the lowest currency unit (cents)
'unit_amount_decimal' => number_format($order->order_total, 2, '.', '') * 100,
'product_data' => [
'name' => $options[] = $cartOption,
],
],
'quantity' => 1,
],
],
'cancel_url' => $cancelUrl.'?redirect='.array_get($data, 'cancelPage'),
'success_url' => $successUrl,
'mode' => 'payment',
'metadata' => [
'order_id' => $order->order_id,
],
'payment_intent_data' => [
'capture_method' => $this->shouldAuthorizePayment() ? 'manual' : 'automatic',
],
];
// Share the email field in our form to Stripe checkout session,
// so customers don't need to enter twice
if (!is_null(array_get($data, 'email'))) {
// if is unregistered customer
$fields['customer_email'] = array_get($data, 'email');
} elseif (!is_null($order->customer) && !is_null($order->customer->email)) {
// else if is registered, get email from customer profile
$fields['customer_email'] = $order->customer->email;
}
$this->fireSystemEvent('payregister.stripecheckout.extendFields', [&$fields, $order, $data]);
return $fields;
}