#Muhammad-Coupon

1 messages · Page 1 of 1 (latest)

shy garnet
atomic delta
#

It's giving error

#

invalid array

#

Can you look at the syntex of how I need to provide the discounts array?

shy garnet
#

Can you copy and paste the whole code? part of the code is missing in the screenshot.

atomic delta
#
$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();
}
shy garnet
#

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'] ]]
]
);
atomic delta
#

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"
}```
shy garnet
#

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?

atomic delta
#

req_evmC3fIP9Y8Q9M

#
$stripe = new \Stripe\StripeClient(
  'sk_test_VyAgO5qOWXohSyYcWWFM83P7006boyIOae'
);
$stripe->coupons->create([
  'percent_off' => 25.5,
  'duration' => 'repeating',
  'duration_in_months' => 3,
]);
shy garnet
#

req_evmC3fIP9Y8Q9M is successful

#

can you send the request that gives you the error?

atomic delta
#

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',
          ]);
shy garnet
#

OK, you are using Coupon API, not Discount API.

atomic delta
#

Can we use coupon on invoice?

shy garnet
#
$stripe->invoices->update(
  'in_123',
  ['metadata' => ['order_id' => '6735'],
  ['discounts' => [ ['coupon' => 'YOUR_COUPON_ID'] ]]
]
);
#

Yup, something like this/

atomic delta
#

"The resource ID cannot be null or whitespace."

shy garnet
#

request ID?

atomic delta
#

req_RmUfNRzv9hqXFm

shy garnet
#

Not this one, the request that returns "The resource ID cannot be null or whitespace."

atomic delta
#

let me check please wait..

#

I am not sure where is error is coming from... can you make a guess?

shy garnet
#

Hmm, seems like an empty resource ID was passed to Stripe API. Can you check if the invoice->payment_intent is null?

atomic delta
#

$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

shy garnet
#

Hi @atomic delta My shrift is ending, my colleague will join this thread to help you.

atomic delta
#

ok no problem and thank you help

pallid osprey
#

Hi @atomic delta , I'll be taking over from @shy garnet but I will need a couple of minutes to get back to you

shy garnet
#

The invoice's payment_intent will be null if no payment needed.

atomic delta
#

ok so i think it solves the problem

shy garnet
#

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.

atomic delta
#

ok thank you again..

shy garnet
#

no problem, feel free to let us know if you need any help!