Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/www/dev-test/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/www/dev-test/app/Stripe.php
<?php

namespace App;

require_once __DIR__ . '/../vendor/stripe-php/init.php';

// use Illuminate\Support\Facades\Http;
use Stripe\Stripe as StripeClient;
// use Stripe\Price as StripePrice;

class Stripe
{
    public function __construct($apiKey)
    {
        StripeClient::setApiKey($apiKey);
        // Stripe::setApiKey($apiKey);
    }

    public function charge($params)
    {
        return \Stripe\Charge::create($params);
    }

    public function createSubscription($customerId, $planId, $options = [])
    {
        $subscription = \Stripe\Subscription::create(array_merge([
            'customer' => $customerId,
            'items' => [
                ['plan' => $planId],
            ],
        ], $options));
        return $subscription;
    }

    public function createCustomer($params = [])
    {
        $customer = \Stripe\Customer::create($params);
        return $customer;
    }

    public function createProduct($params = [])
    {
        $product = \Stripe\Product::create($params);
        return $product;
    }

    public function createPrice($params = []){

        $product = \Stripe\Product::create([
            'name' => 'Dummy product',
            'type' => 'service',  // Adjust the type if necessary
        ]);

        $product->update([
            'metadata' => [
                'price' => 1000,      // The price in the smallest currency unit (e.g., cents)
                'currency' => 'usd',  // The three-letter ISO code of the currency
                'interval' => 'month',  // The interval at which the price will be charged
            ],
        ]);

        return $product;
        // $response = Http::withHeaders([
        //     'Authorization' => 'Bearer ' . $stripeSecretKey,
        // ])->post('https://api.stripe.com/v1/prices', $params);

        // if ($response->failed()) {
        //     // Handle error response
        //     return null;
        // }

        // $price = $response->json();

        // // Handle the price response as needed
        // return response()->json(['price' => $price]);

        $price = \Stripe\Price::create($params);
        return $price;

    }

    public function createPlan($params = [])
    {
        $plan = \Stripe\Plan::create($params);
        return $plan;
    }

    public function retrievePlan($planId)
    {
        $plan = \Stripe\Plan::retrieve($planId);
        return $plan;
    }

    public function retrieveProduct($productId)
    {
        // $product = \Stripe\Product::retrieve($productId);
        $product = \Stripe\Product::retrieve($productId, [
            'expand' => ['data.plans'],
        ]);
        return $product;
        $products = \Stripe\Product::all(['include[]' => ['plans']]);
  
        foreach ($products->data as $product) {
            if ($product->id === $productId) {
                return $product;
            }
        }
      
        return null;
    }

    public function retrievePlanByProductId($productId)
    {
        $plans = \Stripe\Plan::all(['product' => $productId]);
      
        return $plans->data;
    }

    public function deleteProduct($productId) {
        // Delete the product
        \Stripe\Product::retrieve($productId)->delete();

        // Handle the response as needed
        // For example, you can return true if the deletion was successful
        return true;
    }

}

ZeroDay Forums Mini