[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: StripeRepository.php
<?php /** -------------------------------------------------------------------------------- * This repository class manages all the data absctration for payment gateways * * @package Grow CRM * @author NextLoop *----------------------------------------------------------------------------------*/ namespace App\Repositories; use Log; class StripeRepository { /** * Inject dependecies */ public function __construct() { } /** * check if Stripe gateway is configured correctly * @return mixed error message or true */ public function validateStripe() { //check if we have settings for stripe in the database if (config('system.settings_stripe_secret_key') == '' || config('system.settings_stripe_public_key') == '' || config('system.settings_stripe_currency') == '') { return __('lang.stripe_authentication_error'); } //check if we have settings for stripe in the database if (config('system.settings_stripe_status') != 'enabled') { return __('lang.stripe_not_enabled'); } //test api connection (validate the key) try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); //make asimple request to check key is valide $stripe->webhookEndpoints->all(['limit' => 3]); } catch (\Stripe\Exception\AuthenticationException$e) { return __('lang.stripe_authentication_error'); } catch (\Stripe\Exception\ApiConnectionException$e) { return __('lang.stripe_network_error'); } catch (Exception $e) { return __('lang.stripe_generic_error'); } //all is ok return true; } /** * get aan array of all the products in Stripe * @param string $product_di the unique stripe product id * @return mixed error message or true */ public function getProducts() { Log::info("getting products from stripe - started", ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); //get all products try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); $products = $stripe->products->all(); } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("Stripe Error - Unable to authenticate with Stripe. Check your API keys", ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); return false; } catch (\Stripe\Exception\ApiConnectionException$e) { Log::error("Stripe Network Error - Your server was unable to connect to api.stripe.com", ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); return false; } catch (Exception $e) { Log::error($e->getMessage(), ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); return false; } //final check if (!is_object($products)) { Log::error("unable to retrieve your products from stripe", ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); return false; } Log::info("getting products from stripe - completed", ['process' => '[stripe-get-products]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'products' => $products]); //return array of the products return $products; } /** * get an array of all the prices for a product in Stripe * @return mixed error message or true */ public function getProductsPrices($product_id = '') { Log::info("getting product prices from stripe - started", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__]); //validate if ($product_id == '') { Log::error('no product id was specifid', ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } //get all products try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); $prices = $stripe->prices->all(['product' => $product_id]); } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("Stripe Error - Unable to authenticate with Stripe. Check your API keys", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } catch (\Stripe\Exception\ApiConnectionException$e) { Log::error("Stripe Network Error - Your server was unable to connect to api.stripe.com", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } catch (Exception $e) { Log::error($e->getMessage(), ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } //final check if (!is_object($prices)) { Log::error("unable to retrieve your products from stripe", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } Log::info("getting product prices from stripe - completed", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'prices' => $prices]); //return array of the products return $prices; } /** * get a specific product * @param string $product_di the unique stripe product id * @return mixed error message or true */ public function getProduct($product_id = '') { //validate if ($product_id == '') { Log::error('no product id was specifid', ['process' => '[stripe-get-product]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } //get all products try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); $product = $stripe->products->retrieve($product_id, []); } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("Stripe Error - Unable to authenticate with Stripe. Check your API keys", ['process' => '[stripe-get-product]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } catch (\Stripe\Exception\ApiConnectionException$e) { Log::error("Stripe Network Error - Your server was unable to connect to api.stripe.com", ['process' => '[stripe-get-product]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } catch (Exception $e) { Log::error($e->getMessage(), ['process' => '[stripe-get-product]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } //final check if (!is_object($product)) { Log::error("unable to retrieve your products from stripe", ['process' => '[stripe-get-product]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'product_id' => $product_id]); return false; } //return array of the products return $product; } /** * get a specific price * @param string $price_id the unique stripe price id * @return mixed error message or true */ public function getPrice($price_id = '') { //validate if ($price_id == '') { Log::error('no stripe price_id was specifid', ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'price_id' => $price_id]); return false; } //get all products try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); $price = $stripe->prices->retrieve($price_id, []); } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("Stripe Error - Unable to authenticate with Stripe. Check your API keys", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'price_id' => $price_id]); return false; } catch (\Stripe\Exception\ApiConnectionException$e) { Log::error("Stripe Network Error - Your server was unable to connect to api.stripe.com", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'price_id' => $price_id]); return false; } catch (Exception $e) { Log::error($e->getMessage(), ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'price_id' => $price_id]); return false; } //final check if (!is_object($price)) { Log::error("unable to retrieve your products from stripe", ['process' => '[stripe-get-products-prices]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'price_id' => $price_id]); return false; } //return array of the products return $price; } /** * get a subscription from stripe * @param string $subscription_stripe_id the unique stripe id * @return mixed error message or true */ public function getSubscription($subscription_stripe_id = '') { //validation if ($subscription_stripe_id == '') { Log::error("Stripe Error - a subscription id was not provided", ['process' => '[stripe-get-subscription]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'subscription_stripe_id' => $subscription_stripe_id]); return false; } //get the subscription try { $stripe = new \Stripe\StripeClient(config('system.settings_stripe_secret_key')); $subscription = $stripe->subscriptions->retrieve( $subscription_stripe_id, [] ); } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("Stripe Error - Unable to authenticate with Stripe. Check your API keys", ['process' => '[stripe-get-subscription]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'subscription_stripe_id' => $subscription_stripe_id]); return false; } catch (\Stripe\Exception\ApiConnectionException$e) { Log::error("Stripe Network Error - Your server was unable to connect to api.stripe.com", ['process' => '[stripe-get-subscription]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'subscription_stripe_id' => $subscription_stripe_id]); return false; } catch (Exception $e) { Log::error($e->getMessage(), ['process' => '[stripe-get-subscription]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'subscription_stripe_id' => $subscription_stripe_id]); return false; } //final check if (!is_object($subscription)) { Log::error("unable to retrieve the subscription from stripe", ['process' => '[stripe-get-subscription]', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'path' => __file__, 'subscription_stripe_id' => $subscription_stripe_id]); return false; } //return the subscription return $subscription; } /** * get a subscription from stripe * @param string $subscription_stripe_id the unique stripe id * @return mixed error message or true */ public function cancelSubscription($subscription_id) { Log::info("attempting to cancel stripe subscription", ['process' => 'stripe.cancel', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'subscription_id' => $subscription_id]); try { //set stripe key \Stripe\Stripe::setApiKey(config('system.settings_stripe_secret_key')); //cancel the subscription $subscription = \Stripe\Subscription::retrieve($subscription_id); $subscription->cancel(); Log::info("stripe subscription was cancelled successfully", ['process' => 'stripe.cancel', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'subscription_id' => $subscription_id]); return true; } catch (\Stripe\Exception\InvalidRequestException$e) { Log::error("stripe subscription cancellation failed - invalid request", ['process' => 'stripe.cancel', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'subscription_id' => $subscription_id, 'error' => $e->getMessage()]); return false; } catch (\Stripe\Exception\AuthenticationException$e) { Log::error("stripe subscription cancellation failed - authentication error", ['process' => 'stripe.cancel', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'subscription_id' => $subscription_id, 'error' => $e->getMessage()]); return false; } catch (\Exception$e) { Log::error("stripe subscription cancellation failed - general error", ['process' => 'stripe.cancel', config('app.debug_ref'), 'function' => __function__, 'file' => basename(__FILE__), 'line' => __line__, 'subscription_id' => $subscription_id, 'error' => $e->getMessage()]); return false; } } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.71 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002