Last Updated: Sep. 02, 2022 at 03:05am UTC

External Developer Documentation for Ninja Forms Stripe

Stripe SDK and API

Prior to 2022/09, the plugin used the "stripe/stripe-php": "^7" library. In NF Stripe v3.2.0, the library was updated to "stripe/stripe-php": "^9".

Around this same time, Stripe's API version 2022-08 was released and the previous line item construct would no longer work. The new 'price/product' construct worked with the new API version and also as far back as the 2015-01 version. Because the API version is controlled by the end user, we wanted to ensure that we had enough backwards compatibility, so we changed our code structure to accomodate both data constructs and we'll discuss that in the Code Structure section.

Code Structure

During the upgrade to Stripe's SDK v9, we changed the plugin to use a collection of adapter classes implementing newly added interfaces. The PaymentGateway class, which is dependent on both Ninja Forms and WordPress functionality, was cleared of any direct references to the Stripe SDK library and instead was coded to an interface specifying the required public methods. At runtime, an adapter factory class provides specific adapters, which implement the interface using the Stripe SDK library from within. If we need any future changes to the libary, we now need only change adapters to match the new library and as long as we honor the interface specifications, the new code is interchangeable with existing code.

The folder Common\Adapters\StripeCheckout contain the new classes. The Interfaces folder contains the interfaces to which the PaymentGateway class is programmed. When changes are required to the underlying Stripe SDK, we need only change the classes in the Adapters folder; so long as the interfaces stay the same, the code stays isolated.

The data construct change that happened in API 2022-08 is addressed with this new structure. The PaymentFactory method responsible for creating the Payment object, receives an optional boolean argument that when set to true, provides the class with the older construct. If the argument is omitted or set to false, the class with the new standard construct is provided.