seedproject-web/api/app/Gateways/Stripe.php
Carlos Arias 1559ce017d chore: scaffold SeedProject base (Phase 1)
Clean-room copy of the reusable engines from comiida, with all
instance data, secrets, dependencies, and build output excluded:
- app/         Astro theme skeleton (no comiida blog posts; hero image -> placeholder)
- api/         SeedProject PHP framework (no vendor/.env/config.php)
- content-pipeline/  engine only (scripts/admin/prompts; empty runtime state)
- astroagent.config.json + app/.astroagent/skills

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SYHWLHihq3v9nxNwoPCKSn
2026-07-04 22:53:10 +00:00

152 lines
3.8 KiB
PHP

<?php namespace App\Gateways;
use Model as Model;
class Stripe extends Model
{
public function __construct($key) {
parent::__construct();
\Stripe\Stripe::setApiKey($key);
}
# This is just to create a customer with a card verification
// Token is Required to create a customer into stripe.
public function CreateAccount($token, $name, $email, $description){
try {
$Customer = \Stripe\Customer::create(array(
"description" => $description,
"name" => $name,
"source" => $token,
"email" => $email
));
return ($Customer);
} catch (\Stripe\Error\Card $e){
return ($e->getMessage());
}
}
# Retrieve Subscription Information
public function RetrieveSubscription($str){
try {
$subscription = \Stripe\Subscription::retrieve($str);
return($subscription);
} catch (\Stripe\Error\Base $e) {
return ($e->getMessage());
}
}
#Create Subscription
# https://stripe.com/docs/api/subscriptions/create
// a Customer ID is required - this is retrieve from the CreateAccount method.
// a PlanID is required. This is grabbed from stripe plans (https://dashboard.stripe.com/subscriptions/products)
// My Recommendation is to use Method ($this->getPlans) to get the plans. Stripe doesn't make it easy to get the planid
public function CreateSubscription($CustID, $PlanID){
$CustomerSubscription = \Stripe\Subscription::create(array(
"customer" => $CustID,
"items" => array(
array(
"plan" => $PlanID,
"quantity" => 1,
)
)
));
return ($CustomerSubscription);
}
# Cancels Subscription
// Subscription ID is required
// https://stripe.com/docs/api/subscriptions/cancel
public function CancelSubscription($str){
try {
$subscription = \Stripe\Subscription::retrieve($str);
$subscription->cancel();
return($subscription);
} catch (\Stripe\Error\Base $e) {
return ($e->getMessage());
}
}
# Update Subscription.
# subscription code required from stripe.
// Provide with a new PlanID
// https://stripe.com/docs/api/subscriptions/update
public function UpdateSubscription($SubID, $PlanID){
$subscription = \Stripe\Subscription::retrieve($SubID);
try {
$UpdateSubscription = \Stripe\Subscription::update($SubID, [
'cancel_at_period_end' => false,
'proration_behavior' => 'always_invoice',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'plan' => $PlanID,
],
]
]);
return($UpdateSubscription);
} catch (\Stripe\Error\Base $e) {
return ($e->getMessage());
}
}
#This get customer information everything about the customer from Stripe
// Just Need Customer id which looks like cust_348398439
// https://stripe.com/docs/api/customers/retrieve
public function getCustomerInfo($str){
$Return = \Stripe\Customer::retrieve($str);
return $Return;
}
#Retrieve a list of plans
public function getPlans($limit = 10){
$Return = \Stripe\Plan::all(["limit" => $limit]);
return $Return;
}
# Retrieves the Plans detail information
public function ProductInfo($planId){
$Return = \Stripe\Plan::retrieve($planId);
return $Return;
}
# Update Credit Card Info
// Coming Soon
public function UpdateCard($token, $custID){
try {
$cu = \Stripe\Customer::update(
$custID, // stored in your application
[
'source' => $token // obtained with Checkout
]
);
return $cu;
//$Message['Success'] = "Your card details have been updated!";
}
catch(\Stripe\Error\Card $e) {
return ($e->getMessage());
// $e->getJsonBody(); // show fulll error message
}
}
} // End Class