Stripe SDK Migrator
The sdk-migrator
is a tool that can modify Java and Python codebases that use the Stripe SDK. It will take code using older integration styles and output the same code but in the newer style.
Eg. In Stripe Java SDK v29.5.0 we introduced new v1
namespace in StripeClient. Running the v1-namespace
migration would convert all your StripeClient calls to support the newer code path.
class AcmeBusinessApp {
public StripeCollection<Customer> fetchCustomerList(StripeClient client) {
- return client.customers().list();
+ return client.v1().customers().list();
}
}
[!WARNING]
sdk-migrator
makes its best effort to migrate your code (especially with dynamic languages). Make sure you have all your code checked in a version control system (e.g. Git) before using this tool. Always review and test your code before deploying.
Installation
sdk-migrator
is a Node.js-based package and can be installed globally as a CLI:
npm i -g @stripe/sdk-migrator
or used directly with npx
(which comes pre-installed with npm
):
npx @stripe/sdk-migrator
If you need Node.js installed, you can follow these instructions for your platform.
Usage
[!WARNING]
SDK Migrator can modify files in your codebase. Make sure you have all your code checked in a version control system (e.g. Git) before using this tool. Always review and test your code before deploying.
npx @stripe/sdk-migrator --language java -d ~/stripe-integration --migration v1-namespace
Command Line Options
-h, --help
: Show help message
-v, --version
: Show version information
-d, --directory
: Code directory to process
-l, --language
: Programming language (java, python)
-m, --migration
: Migration name (e.g., v1-namespace)
-x, --execute
: Execute mode will modify files in your codebase
-u, --untyped
: Untyped mode for codebases that are not fully typed. Currently only available for Python (optional)
Examples
npx @stripe/sdk-migrator --help
npx @stripe/sdk-migrator --version
npx @stripe/sdk-migrator --language python -d ~/stripe-integration --migration v1-namespace
npx @stripe/sdk-migrator --language python -d ~/stripe-integration --migration v1-namespace --execute
npx @stripe/sdk-migrator --language python -d ~/stripe-integration --migration v1-namespace --untyped --execute
npx @stripe/sdk-migrator --language java -d ~/stripe-integration --migration v1-namespace --execute
Customization
If you extend/implement your own StripeClient in your codebase, you can change the regex in src/{lang}/{migration}/configure.ts
to use the tool.
Development
Contribution guidelines for this project