#Muhammad-Coupon
1 messages · Page 1 of 1 (latest)
Hi! Can you share the request ID (req_xxx)? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
It's giving error
invalid array
Can you look at the syntex of how I need to provide the discounts array?
Can you copy and paste the whole code? part of the code is missing in the screenshot.
$options = [];
if(isDeveloper()){
$options['discounts'] = [
'discount'=>'100free'
];
}
$invoice = $user->invoiceFor("Order Charges", $amount * 100, [
'metadata' => [
'orderId' => $order->id,
'userId' => $user->id,
'invoiceFor' => 'memberOrderCharges',
'hasRecordOrder' => isset($recordOrder->id),
'recordOrderData' => json_encode($metaData)
]
] + $options);
$this->updatePaymentIntent($invoice->payment_intent, [
'description' => $order->testType . " order Charges"
]);
if ($invoice->status == "paid") {
$order->isPaid = 1;
$order->save();
}
What does $user->invoiceFor( do?
If you are updating the invoice there, you code should look something like
$stripe->invoices->update(
'in_123',
['metadata' => ['order_id' => '6735'],
['discounts' => [ ['discount' => '100free'] ]]
]
);
I have created a coupon
Now i am trying to create an invoice and use that coupon
I am getting this error
No such discount: '100free'
{
"customer": "cus_LZVvqtiPiaStQz",
"currency": "usd",
"description": "Order Charges",
"metadata": {
"orderId": "5688",
"userId": "1578",
"invoiceFor": "memberOrderCharges",
"hasRecordOrder": "false",
"recordOrderData": "{\"single\":true}"
},
"discounts": {
"0": {
"coupon": "100free"
}
},
"amount": "5900"
}```
OK, at least the request is accepted. the error tells you that the discount object is not available, How did you create the 100free discount?
req_evmC3fIP9Y8Q9M
$stripe = new \Stripe\StripeClient(
'sk_test_VyAgO5qOWXohSyYcWWFM83P7006boyIOae'
);
$stripe->coupons->create([
'percent_off' => 25.5,
'duration' => 'repeating',
'duration_in_months' => 3,
]);
req_RmUfNRzv9hqXFm
This is how i created coupon. which I have tried to apply on invoice.
$this->stripeClient()->coupons->create([
'percent_off' => 100,
'duration' => 'forever',
'name' => '100free',
'id' => '100free',
]);
OK, you are using Coupon API, not Discount API.
Can we use coupon on invoice?
$stripe->invoices->update(
'in_123',
['metadata' => ['order_id' => '6735'],
['discounts' => [ ['coupon' => 'YOUR_COUPON_ID'] ]]
]
);
Yup, something like this/
"The resource ID cannot be null or whitespace."
request ID?
req_RmUfNRzv9hqXFm
Not this one, the request that returns "The resource ID cannot be null or whitespace."
let me check please wait..
I am not sure where is error is coming from... can you make a guess?
Hmm, seems like an empty resource ID was passed to Stripe API. Can you check if the invoice->payment_intent is null?
$options = [];
if(isDeveloper()){
$options['discounts'] = [
['coupon'=>'100free']
];
}
$invoice = $user->invoiceFor("Order Charges", $amount * 100, [
'metadata' => [
'orderId' => $order->id,
'userId' => $user->id,
'invoiceFor' => 'memberOrderCharges',
'hasRecordOrder' => isset($recordOrder->id),
'recordOrderData' => json_encode($metaData)
]
] + $options);
$this->updatePaymentIntent($invoice->payment_intent, [
'description' => $order->testType . " order Charges"
]);
if ($invoice->status == "paid") {
$order->isPaid = 1;
$order->save();
}
I am updating the invoice after the invoice is paid.
$this->updatePaymentIntent($invoice->payment_intent, [
Now coupon is being applied but I don't know why the payment_intent is null?
is it because of coupon?
coupon has 100 discount
Hi @atomic delta My shrift is ending, my colleague will join this thread to help you.
ok no problem and thank you help
Hi @atomic delta , I'll be taking over from @shy garnet but I will need a couple of minutes to get back to you
The invoice's payment_intent will be null if no payment needed.
ok so i think it solves the problem
so if the coupon is to make the invoice free, then the payment_intent will be null since there's no need to make any payment.
ok thank you again..
no problem, feel free to let us know if you need any help!