Unlock Savings: Deleting Stripe Coupons in Laravel (PHP)

How to use Stripe API's to create coupons in Laravel

Unlock-Savings-Deleting-Stripe-Coupons-in-Laravel-(PHP)

When it comes to integrating payment solution on a project Stripe comes with great solutions. Stripe provides lots of services to provide solution to our complex requirements. One of its service is coupon. coupon is one of the great ways to acquire customer in your product.

In this article we will learn how to delete coupon using Stripe API's in Laravel , you can follow the same steps for a PHP project also. you can checkout to our article how to create coupon in stripe.

You can read our other articles of how to integrate stripe payment gateway , How can you save cards etc.

Let's see how can we delete coupon in stripe.


Create a route :

Route::get('payment/deletecoupon', [paymentController::class,'deleteCoupon'])->name('delete-coupon');

Paymentcontroller.php :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade as PDF;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

class paymentController extends Controller
{
    public function deleteCoupon(){
      try{
        // Connect to your stripe account

        $stripe_account = Config('constants.Stripe_account');
        $stripe_secret = $stripe_account['secret_key'];

        $stripe = new \Stripe\StripeClient(
          $stripe_secret
        );
        // create coupon
        $coupon = $stripe->coupons->delete(
          'XbC9tMrf',
          []
        );

        return $coupon;
      }
      catch(\Exception $e){
        Log::error(
          'Failed to delete coupon',
          ['message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]
        );
        return false;
      }
    }
}

Output response :

{
    "id": "XbC9tMrf",
    "object": "coupon",
    "deleted": true
}


Previous Post Next Post

Contact Form