Using the API of WP Full Pay

Documentation of the API that lets developers configure forms, and access Stripe objects and the Stripe API easily.

Introduction

WP Full Pay has an API which provides functionality to expose the internal state of the plugin, and also provides shortcuts to manipulate Stripe objects.

This article documents every function of the API.

How to use the API

Invoking API functions

API functions are exposed as static methods of the WPFS_API_v2 PHP class.

For example, you can query the plugin version by the following method call: 

WPFS_API_v2::getPluginVersion()

Versioning

The API version is added as a postfix of the API class name, hence the WPFS_API_v2 class name.

Future API versions will raise the version number, so the next one will be WPFS_API_v3.

Compatibility

A new API version extends the functionality of the previous API version, without breaking compatibility, unless noted otherwise.

Let’s say that the cancelSubscription() function is added in v2. This function can be used without any modification also in v3, so any of the following method calls would work:

  • WPFS_API_v2::cancelSubscription( ‘sub_ev4yBy78Ybn’ );
  • WPFS_API_v3::cancelSubscription( ‘sub_ev4yBy78Ybn’ );

Namespacing of the Stripe PHP client

WP Full Pay uses the PHP library for the Stripe API.

In order to avoid conflicts caused by other plugins also using the Stripe PHP client, WP Full Pay uses the Stripe PHP client in its own namespace.

In the Stripe PHP client, all resources and API calls are available in the Stripe namespace. In WP Full Pay, all resources and API calls are available in the StripeWPFS namespace.

As an example, instead of using the \Stripe\Subscription class, one would use the \StripeWPFS\Subscription class.

You won’t need to specify or use the namespace often, but please be aware of this difference.

Error handling

The API functions might throw exceptions, and you should deal with them properly.

The documentation contains the exceptions that functions can throw.

API functionality

Table of contents for the API functions, click on a link to jump to the selected function:

getPluginVersion()

Returns the semantic version number of WP Full Pay.

Parameters and return value:

Name Description
Return value Plugin version number in the v[MM].[mm].[pp] format (see below)

The v[MM].[mm].[pp] format, where:

  • MM is the major version
  • mm is the minor version
  • pp is the patch version

As an example, the return value can be: 

v6.3.0

getStripeClient()

Returns the Stripe PHP client of the plugin in the indicated API mode.

Parameters and return value:

Name Description
$apiMode

The API mode for which the Stripe API client should be returned.


Possible values:

WPFS_API_v2::STRIPE_API_MODE_LIVE

WPFS_API_v2::STRIPE_API_MODE_TEST

WPFS_API_v2::STRIPE_API_MODE_CURRENT


You can omit this parameter, and it will default to the current API mode.

   
Return value An instance of \StripeWPFS\StripeClient
Throws

Exception


Generic exception when unknown API mode is provided.

getStripeSubscriptionPlans()

Returns the subscription plans (recurring prices) from Stripe in the current Stripe API mode.

Parameters and return value:

Name Description
Return value

A \StripeWPFS\Collection of \StripeWPFS\Price objects.


An empty array if an error occured.

getStripeSubscripion()

Returns a Stripe subscription in the current Stripe API mode.

Parameters and return value:

Name Description
$subscriptionId Identifier of the subscription
   
Return value An instance of \StripeWPFS\Subscription
Throws \StripeWPFS\Exception\ApiErrorException

getStripeSubscripionWithParams()

Returns a Stripe subscription in the current Stripe API mode, with additional parameters used to control the returned object.

Parameters and return value:

Name Description
$subscriptionId Identifier of the subscription
$params Associative array of additional parameters passed to Stripe.
   
Return value An instance of \StripeWPFS\Subscription
Throws \StripeWPFS\Exception\ApiErrorException

getStripeCustomer()

Returns a Stripe customer in the current Stripe API mode.

Parameters and return value:

Name Description
$customerId Identifier of the customer
   
Return value An instance of \StripeWPFS\Customer
Throws

Exception


Generic exception when something goes wrong.

getStripeCustomerWithParams()

Returns a Stripe customer in the current Stripe API mode, with additional parameters used to control the returned object.

Parameters and return value:

Name Description
$customerId Identifier of the customer
$params Associative array of additional parameters passed to Stripe.
   
Return value An instance of \StripeWPFS\Customer
Throws

Exception


Generic exception when something goes wrong.

getStripePlan()

Returns a Stripe price in the current Stripe API mode.

Parameters and return value:

Name Description
$planId Identifier of the price
   
Return value An instance of \StripeWPFS\Price or null if the plan is not found.

changeSubscriptionPlan()

Updates the plan associated with a Stripe subscription in the current Stripe API mode.

Parameters and return value:

Name Description
$customerId Identifier of the Stripe customer the subscription belongs to
$subscriptionId Identifier of the Stripe subscription
$planId Identifier of the Stripe price
   
Throws \StripeWPFS\Exception\ApiErrorException

cancelSubscription()

Cancels a Stripe subscription in the current Stripe API mode.

Parameters and return value:

Name Description
$customerId Identifier of the Stripe customer the subscription belongs to
$subscriptionId Identifier of the Stripe subscription
   
Return value Boolean value indicating whether the cancellation was successful.
Throws \StripeWPFS\Exception\ApiErrorException

cancelSubscriptionById()

Cancels a Stripe subscription in the current Stripe API mode.

Parameters and return value:

Name Description
$subscriptionId Identifier of the Stripe subscription
   
Return value Boolean value indicating whether the cancellation was successful.
Throws \StripeWPFS\Exception\ApiErrorException

getCurrencySymbolFor()

Returns the currency symbol of the provided currency. For example, for ‘usd’ the ‘$’ string is returned.

Parameters and return value:

Name Description
$currency Three-letter, lowercase currency identifier to get the symbol for
   
Return value Symbol of the currency, or null if the currency is not found.

isDemoMode()

Tells whether the plugin is in demo mode.

Parameters and return value:

Name Description
Return value Boolean value indicating whether the plugin is in demo mode.

setIsFormFieldConfigurable()

Sets whether the given form field can be pre-filled via URL parameters.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field that is about to be configured.
$isConfigurable boolean value of whether this field can be pre-filled.
   
Return value Array containing the modified form field configuration.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

isFormFieldConfigurable()

Returns whether the given form field can be pre-filled via URL parameters.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field.
   
Return value Boolean value indicating whether the form field is set to be pre-filled by an URL parameter, or false if the form field doesn’t exist.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

setFormFieldValue()

Sets the value of a form field.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field.
$value New value of the form field.
   
Return value Array containing the modified form field configuration.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

getFormFieldValue()

Returns the value of a form field.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field.
   
Return value Value of the form field.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

setIsFormFieldReadonly()

Sets whether the given form field should be read-only if it’s pre-filled via a URL parameter.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field that is about to be configured.
$isReadonly boolean value of whether this field should be read-only.
   
Return value Array containing the modified form field configuration.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

isFormFieldReadonly()

Returns whether the given form field should be read-only if it’s pre-filled via a URL parameter.

Parameters and return value:

Name Description
$config A field configuration array of the form that is about to be rendered.
$fieldName Name of the form field.
   
Return value Boolean value indicating whether the form field should be read-only if it’s pre-filled by an URL parameter, or false if the form field doesn’t exist.

This function is useful only in the context of the fullstripe_form_field_configuration filter.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us