StripeApi
in package
Table of Contents
Properties
- $client : Client
- $container : ContainerInterface
Methods
- __construct() : mixed
- StripeApi constructor.
- createRefund() : array<string|int, mixed>
- Creates a refund based on the provided parameters.
- eurosToCents() : int
- Converts a monetary value in euros to its equivalent value in cents.
- processStripeRefund() : array<string|int, mixed>
- Processes a Stripe refund request.
- refundByPaymentIntent() : mixed
- Processes a refund for a given payment intent.
- setApiKey() : bool
- Initializes and configures the API client with the appropriate Stripe API key and settings based on the provided source and store identifier.
- makeRequest() : mixed
- Sends an HTTP request to a specified API endpoint with configurable options.
Properties
$client
private
Client
$client
$container
private
ContainerInterface
$container
Methods
__construct()
StripeApi constructor.
public
__construct(ContainerInterface $container) : mixed
Parameters
- $container : ContainerInterface
createRefund()
Creates a refund based on the provided parameters.
public
createRefund(array<string|int, mixed> $parameters) : array<string|int, mixed>
Parameters
- $parameters : array<string|int, mixed>
-
An associative array of parameters for the refund. It must include the 'payment_intent'. Optionally, it can include:
- 'amount' (int): The amount to refund, in the smallest currency unit.
- 'reason' (string): The reason for the refund, such as 'duplicate', 'fraudulent', or 'requested_by_customer'.
- 'metadata' (array): An associative array of metadata to associate with the refund.
Return values
array<string|int, mixed> —An array containing the result of the refund operation, including keys such as:
- 'success' (bool): Indicates if the operation was successful.
- 'refund' (array|null): The refund object on success, or null on failure.
- 'id' (string|null): The refund ID on success, or null on failure.
- 'amount' (int|null): The refunded amount on success, or null on failure.
- 'status' (string|null): The refund status on success, or null on failure.
- 'charge' (string|null): The charge ID associated with the refund, if available.
- 'payment_intent' (string|null): The payment intent ID associated with the refund, if available.
- 'reason' (string|null): The reason for the refund, if available.
- 'error' (string|null): The error message on failure, or null on success.
- 'error_code' (string|null): The error code on failure.
- 'error_type' (string|null): The type of error on failure.
eurosToCents()
Converts a monetary value in euros to its equivalent value in cents.
public
eurosToCents(float $euros) : int
Parameters
- $euros : float
-
The monetary value in euros to be converted.
Return values
int —The equivalent monetary value in cents as an integer.
processStripeRefund()
Processes a Stripe refund request.
public
processStripeRefund(object $refund) : array<string|int, mixed>
Parameters
- $refund : object
-
The refund object containing refund details, including sale and amount information.
Tags
Return values
array<string|int, mixed> —Returns an array with the success status and other relevant response details. On failure, an error message is included.
refundByPaymentIntent()
Processes a refund for a given payment intent.
public
refundByPaymentIntent(string $paymentIntentId[, int|null $amount = null ][, string|null $reason = null ][, array<string|int, mixed> $metadata = [] ]) : mixed
Parameters
- $paymentIntentId : string
-
The unique identifier for the payment intent to be refunded.
- $amount : int|null = null
-
The amount to refund, in the smallest currency unit. If null, the entire payment is refunded.
- $reason : string|null = null
-
The reason for the refund, such as 'duplicate', 'fraudulent', or 'requested_by_customer'.
- $metadata : array<string|int, mixed> = []
-
An optional associative array of metadata to associate with the refund.
Return values
mixed —The result of the refund creation process, typically a response object or status.
setApiKey()
Initializes and configures the API client with the appropriate Stripe API key and settings based on the provided source and store identifier.
public
setApiKey(string $source, string|null $storeId) : bool
Parameters
- $source : string
-
The source from which the API key is retrieved, e.g., 'Menzzo' or 'MeublePromo'.
- $storeId : string|null
-
The unique identifier for the store, required for sources that use store-specific API keys.
Return values
bool —True if the API client was successfully configured, false otherwise.
makeRequest()
Sends an HTTP request to a specified API endpoint with configurable options.
private
makeRequest(string $method, string $endpoint[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $method : string
-
The HTTP method to use for the request (e.g., 'GET', 'POST').
- $endpoint : string
-
The target API endpoint for the request.
- $data : array<string|int, mixed> = []
-
Optional data payload to include in the request. For POST requests, this will be sent as form parameters; for GET requests, it will be included as query parameters.
Tags
Return values
mixed —The decoded JSON response from the API in array format, or null if the response cannot be decoded.