Appearance
<div style="display: none;" hidden="true" aria-hidden="true">Are you an LLM? You can read better optimized documentation at /guides/Stripe.md for this page in Markdown format</div>
Stripe Docs
Stripe Api Docs
Stripe Api Keys
About Library
Stripe Objects :
- Every object class extends base StripeObjectAbstract class and needs to fill out the tasks: 'prepareResource', 'updateExistingResource' and 'createNewResource. - Every object class implements StripeOptionalObject Interface having public methods : 'setup' and 'resolve'.
StripeObjectAbstract (abstract class)
prepareResource :
params : ApiResource $resource, int $orderId
return : Void
info : Sets the ApiResource class var (can also handle $resource object and manipulate data).
(Example) : protected function prepareResource($resource, int $orderId): void { $resource->metadata = ['order_id' => $orderId]; $this->customer = $resource; }updateExistingResource :
- params : None
- return : Void
- info : Stripe Api call to update existing resource (first retrieves data and then updates).
createNewResource :
- params : None
- return : Void
- info : Stripe Api call to create new resource.
StripeOptionalObject (interface):
setup :
- params : ApiResource $resource, int $orderId, string $currency
- return : Void
- info : In most cases calls the prepareResource abstract method and sets the base StripeCRUDInput for the ApiResource object.
(Example) : public function setup($resource, int $orderId, string $currency): void { $this->prepareResource($resource, $orderId); $this->customerInput = new CustomerInput($this->customer); }
resolve :
- params : None
- return : ApiResource|ApiResource[]|null
- info : Trying to retrieve and update current resource or create new one.
(Example): public function resolve(): ?Customer { try { $this->updateExistingResource(); } catch (ApiErrorException $ex) { $this->createNewResource(); } return $this->customer; }
Helper Classes :
StripeHelper:
- Helper class for Stripe Every method in this class is static and can be called directly from the class.
- Each Stripe Object class has a helper class that extends the StripeHelper class.
(Example): StripeHelper::arrayFilterToEachSubArrayRecursively()
Transformer :
Base class with methods that transforming data from one format (Ecommercen Checkout) to Stripe Objects.
This class methods just calls new StripeApiResourceAbstract type class and returns the transformed stripe object or array of transformed objects using Resource class for the required object.
(Example): public function transformCustomer(array $checkoutCustomer): Customer { $resource = new CustomerResource($checkoutCustomer); return $resource->transform(); }StripeApiResourceAbstract (abstract class)
- Abstract class that every Resource type class extends.
transform :
- params : None
- return : ApiResource|null
- info : Transforms the data from one format (Ecommercen Checkout) to Stripe Objects.
StripeApiResourceTransformable (interface)
- Interface that every Resource type class implements.
transform :
- params : None
- return : ApiResource|null
- info : Transforms the data from one format (Ecommercen Checkout) to Stripe Objects.
- Abstract class that every Resource type class extends.
Inputs :
Input classes for base Stripe Api CRUD operations (Create, Retrieve, Update, Delete).
Each Resource has its own 'ApiResourceInput' type class that implements 'StripeCRUDInput' interface.
Inputs are partial data DTO's of the Stripe Api Resource object.
Each Input DTO Class extends 'StripeInputAbstract' class.
StripeCRUDInput (interface)
- Interface that every 'Api Resource Input' type class implements.
create :
- params : None
- return : object(ApiResource)
- info : Stripe Api input to create new resource.
retrieve :
- params : None
- return : object(ApiResource)
- info : Stripe Api input to retrieve existing resource.
update :
- params : None
- return : object(ApiResource)
- info : Stripe Api input to update existing resource.
delete :
- params : None
- return : object(ApiResource)
- info : Stripe Api input to delete existing resource.
StripeInputAbstract (abstract class)
- Abstract class that every 'Partial Input' type DTO class extends.
- This class extends 'ApiResource' abstract class from Stripe Library.
- (https://github.com/stripe/stripe-php/blob/master/lib/ApiResource.php)
setValues :
- params : None
- return : Void
- info : Fills out the '_values' array for Stripe Object. (https://github.com/stripe/stripe-php/blob/master/lib/StripeObject.php)
(Example): protected function setValues(): void { $this->_values['id'] = $this->id; }
createFromStripeObject :
- params : ApiResource $resource
- return : ApiResource Partial Input DTO
- info : Creates new CRUD Partial ApiResource type object from Stripe Object to use as input for Stripe required operation.
(Example): public static function createFromStripeObject($resource): CustomerInputUpdateDTO { return new CustomerInputUpdateDTO( $resource->address, $resource->description, $resource->email, $resource->metadata, $resource->name, $resource->phone, $resource->shipping, ); }
StripeConfig :
- Class that holds the Stripe config like Api Keys and other required data.
Ecommercen Admin Panel :
Stripe Pay Way Settings :
Publishable key:
On the client-side. Can be publicly-accessible in your web or mobile app’s client-side code (such as checkout.js) to tokenize payment information such as with Stripe Elements. By default, Stripe Checkout tokenizes payment information.Secret key:
On the server-side. Must be secret and stored securely in your web or mobile app’s server-side code (such as in an environment variable or credential management system) to call Stripe APIs.Enable Product Prices API:
When this setting is enable, makes calls to Stripe Api to create/update Products and Prices for Stripe (this feature is not required, when disabled StripeCheckout just pass the required 'line_items' as 'price_data' with products as 'product_data' and does not generate the products and prices to stripe).Enable Customers API:
When this setting is enable, makes calls to Stripe Api to create/update Customers for Stripe (this feature is not required, when disabled StripeCheckout generates new random Stripe Customer **if disabled customer has to re enter his email and phone at Stripe Checkout).