#SatriaRizali

1 messages · Page 1 of 1 (latest)

buoyant owlBOT
autumn crater
#

Let's head over your Dashboard request log and find the failed request, then inspect its error message

worthy bronze
#

i cant found any error message

#

$discountvalue = 8;
if ($discountvalue > 0) {
$discount = $stripe->coupons->create([
'percent_off' => $discountvalue
]);
$iddiscount = $discount['id'];
$discountcond = "'discounts' => [[
'coupon' => $iddiscount,
]],";
// print_r($discountcond);
// die;
}

    $payment = $stripe->checkout->sessions->create([
      'success_url' => 'https://example.com/success',
      'cancel_url' => 'https://example.com/cancel',
      'line_items' => [
        [
          'price_data' => [
              'unit_amount' => 25000,
              'currency' => 'jpy',
                'tax_behavior' => 'exclusive',
              'product_data' => [
                  'name' => 'Prefecture custom',
                ],
            ],
          'quantity' => 1,
        ],
      ],
      'automatic_tax' => [
        'enabled' => true,
      ],
      'mode' => 'payment',
      **$discountcond**
    ]);
#

i try to make this variable $discountcond , but keep get parameter 0 error

autumn crater
#

I think it's some syntax issue

worthy bronze
#

yup it syntax , the $discountcond variable turn to zero

autumn crater
#

Can you find the request id? req_xxx

#

I see you have

'discounts' => [[...]]

This double brackets look problematic

worthy bronze
#

i think for double brackets is ok

#

$payment = $stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'line_items' => [
[
'price_data' => [
'unit_amount' => 25000,
'currency' => 'jpy',
'tax_behavior' => 'exclusive',
'product_data' => [
'name' => 'Prefecture custom',
],
],
'quantity' => 1,
],
],
'automatic_tax' => [
'enabled' => true,
],
'mode' => 'payment',
'discounts' => [[
'coupon' => $iddiscount,
]]
]);

#

if i code like this , it can work

#

but i need dynamic stripecheckout , so if the user not apply any discount then we can apply with no discount syntax

autumn crater
#

Yeah it's an array of hashes and I suspect it's something with PHP syntax for the type

#

Hi I am stepping down for the day. If you need further help please ask in the channel!

#

Generally I think the solution in above link looks promising. You create an array first then push in hash into it.