### Getting Started: Create a Customer with StripeClient Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Create a Stripe client with a test secret key and create a customer with a description, email, and payment method. The resulting customer object is echoed. ```php $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $customer = $stripe->customers->create([ 'description' => 'example customer', 'email' => 'email@example.com', 'payment_method' => 'pm_card_visa', ]); echo $customer; ``` -------------------------------- ### Install dependencies with just or composer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Installs project dependencies. The `just install` command is a shortcut for `composer install`. ```bash just install # or: composer install ``` -------------------------------- ### Install public preview SDK with composer require Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Install a public preview SDK version by replacing the placeholder with the exact version (e.g., 15.0.0-beta.1). Pin the version in composer.json to avoid breaking changes between preview releases. ```bash composer require stripe/stripe-php:v ``` -------------------------------- ### Install Stripe PHP bindings with Composer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Run this command in your terminal to install the Stripe PHP library via Composer. Requires Composer to be installed. ```bash composer require stripe/stripe-php ``` -------------------------------- ### Manual Installation: Include init.php Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Include the Stripe PHP bindings manually when not using Composer. Place this line at the top of your script to load the library. ```php require_once '/path/to/stripe-php/init.php'; ``` -------------------------------- ### Quick Start: Create a Braintree Transaction Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Shows how to instantiate a Braintree gateway using either the legacy Braintree_Gateway class or the PSR-4 Braintree\Gateway with a Braintree_Configuration object, then create a sale transaction. Requires PHP >= 5.4.0 and the curl, dom, hash, openssl, and xmlwriter extensions. The example uses sandbox credentials and a nonce from the client; the result handling prints success, processor response, or validation errors. ```php 'sandbox', 'merchantId' => 'your_merchant_id', 'publicKey' => 'your_public_key', 'privateKey' => 'your_private_key' ]); // or like this: $config = new Braintree_Configuration([ 'environment' => 'sandbox', 'merchantId' => 'your_merchant_id', 'publicKey' => 'your_public_key', 'privateKey' => 'your_private_key' ]); $gateway = new Braintree\Gateway($config) // Then, create a transaction: $result = $gateway->transaction()->sale([ 'amount' => '1000.00', 'paymentMethodNonce' => 'nonceFromTheClient', 'options' => [ 'submitForSettlement' => true ] ]); if ($result->success) { print_r("success!: " . $result->transaction->id); } else if ($result->transaction) { print_r("Error processing transaction:"); print_r("\n code: " . $result->transaction->processorResponseCode); print_r("\n text: " . $result->transaction->processorResponseText); } else { print_r("Validation errors: \n"); print_r($result->errors->deepAll()); } ``` -------------------------------- ### Install Composer on Mac OS Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Installs Composer using Homebrew on macOS. Required before installing dependencies. ```bash brew install composer ``` -------------------------------- ### Fetch and run stripe-mock Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Installs and runs stripe-mock from a background terminal. Required for the test suite. ```bash go install github.com/stripe/stripe-mock@latest stripe-mock ``` -------------------------------- ### Use Composer autoload to load Stripe PHP bindings Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Include this line in your PHP script to load the Stripe library via Composer's autoloader. Place it after installing the package. ```php require_once 'vendor/autoload.php'; ``` -------------------------------- ### Set per-request key and account for Stripe Connect Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Sets a per-request API key and Stripe account for apps that use multiple keys during a process, such as with Stripe Connect. The example shows both a list and a retrieve call. ```php $customers = $stripe->customers->all([],[ 'api_key' => 'sk_test_...', 'stripe_account' => 'acct_...']); $stripe->customers->retrieve('cus_123456789', [], [ 'api_key' => 'sk_test_...', 'stripe_account' => 'acct_...']); ``` -------------------------------- ### composer.json require for mtdowling/cron-expression Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/action-scheduler/lib/cron-expression/README.md Add this to your project's composer.json to install the cron-expression package version 1.0.*. ```javascript { "require": { "mtdowling/cron-expression": "1.0.*" } } ``` -------------------------------- ### Usage of Cron\CronExpression::factory Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/action-scheduler/lib/cron-expression/README.md Shows how to use the Cron\CronExpression class to check if a cron expression is due, get the next and previous run dates, and calculate future run dates relative to a specific time. Requires PHP 5.3+ and the Composer autoloader. ```php isDue(); echo $cron->getNextRunDate()->format('Y-m-d H:i:s'); echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s'); // Works with complex expressions $cron = Cron\CronExpression::factory('3-59/15 2,6-12 */15 1 2-5'); echo $cron->getNextRunDate()->format('Y-m-d H:i:s'); // Calculate a run date two iterations into the future $cron = Cron\CronExpression::factory('@daily'); echo $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s'); // Calculate a run date relative to a specific time $cron = Cron\CronExpression::factory('@monthly'); echo $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s'); ``` -------------------------------- ### Send custom request with rawRequest Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use rawRequest to call undocumented endpoints or bypass method definitions. For POST, pass params and options; for GET, params must be null and the query string must be explicit. The response body is a string; deserialize it to a StripeObject. ```php $stripe = new \Stripe\StripeClient('sk_test_xyz'); $response = $stripe->rawRequest('post', '/v1/beta_endpoint', [ "caveat": "emptor" ], [ "stripe_version" => "2022-11_15", ]); // $response->body is a string, you can call $stripe->deserialize to get a \Stripe\StripeObject. $obj = $stripe->deserialize($response->body); // For GET requests, the params argument must be null, and you should write the query string explicitly. $get_response = $stripe->rawRequest('get', '/v1/beta_endpoint?caveat=emptor', null, [ "stripe_version" => "2022-11_15", ]); ``` -------------------------------- ### Access last response data with getLastResponse() Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Accesses the last API response data on any object via getLastResponse(). The example prints the Request-Id header from the response. ```php $customer = $stripe->customers->create([ 'description' => 'example customer', ]); echo $customer->getLastResponse()->headers['Request-Id']; ``` -------------------------------- ### Run the test suite Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Runs the full test suite using PHPUnit. The `just test` command is a shortcut for `./vendor/bin/phpunit`. ```bash just test # or: ./vendor/bin/phpunit ``` -------------------------------- ### Build Docker Development Environment Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Builds a Docker image with dependencies and drops you to a terminal where you can run tests. ```bash make ``` -------------------------------- ### Run an individual test file Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Runs a specific test file, e.g., tests/Stripe/UtilTest.php. The `just test` command is a shortcut for `./vendor/bin/phpunit`. ```bash just test tests/Stripe/UtilTest.php # or: ./vendor/bin/phpunit tests/Stripe/UtilTest.php ``` -------------------------------- ### PSR-4 Namespacing for Braintree Gateway Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Shows PSR-4 namespacing for instantiating the gateway, required when using Composer with --classmap-authoritative or --optimize-autoloader. Both direct configuration and a Braintree\Configuration object are shown. ```php $gateway = new Braintree\Gateway([ 'environment' => 'sandbox', 'merchantId' => 'your_merchant_id', 'publicKey' => 'your_public_key', 'privateKey' => 'your_private_key' ]); // or $config = new Braintree\Configuration([ 'environment' => 'sandbox', 'merchantId' => 'your_merchant_id', 'publicKey' => 'your_public_key', 'privateKey' => 'your_private_key' ]); $gateway = new Braintree\Gateway($config) ``` -------------------------------- ### Identify your plugin with setAppInfo Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Call this method once before any API request to identify your plugin. The second and third parameters are optional. ```php \Stripe\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info"); ``` -------------------------------- ### Run Unit Tests with PHPUnit Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Runs the unit tests manually. The integration specs are not meant for public consumption and will likely fail if run on your system. ```bash phpunit tests/unit/ ``` -------------------------------- ### Configure a PSR-3 logger with Stripe::setLogger Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Configures a PSR-3 compatible logger so that library messages go there instead of error_log. ```php \Stripe\Stripe::setLogger($logger); ``` -------------------------------- ### Configure custom CA bundle with Stripe::setCABundlePath Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Configures a custom CA bundle path instead of the library's internal bundle of known CA certificates. ```php \Stripe\Stripe::setCABundlePath("path/to/ca/bundle"); ``` -------------------------------- ### Set beta version header with addBetaVersion Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Required for preview features that need a name and version in the Stripe-Version header (e.g., feature_beta=v3). Only available in public preview SDKs. ```php Stripe::addBetaVersion("feature_beta", "v3"); ``` -------------------------------- ### Format code with PHP CS Fixer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Formats code using PHP CS Fixer. Code must be formatted before PRs are submitted, otherwise CI will fail. The `just format` command is a shortcut for `./vendor/bin/php-cs-fixer fix -v .`. ```bash just format # or: ./vendor/bin/php-cs-fixer fix -v . ``` -------------------------------- ### Google App Engine: Enable curl Extension Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Add this to your php.ini file when using Google App Engine to include the curl extension, as noted in issue #190. ```ini extension = "curl.so" ``` -------------------------------- ### Set custom cURL options (e.g. proxy) with CurlClient Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Sets a default proxy for all Stripe API requests by passing a CURLOPT_* array to the CurlClient constructor. The client overrides many common options like timeouts even if set here. ```php $curl = new \Stripe\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']); \Stripe\ApiRequestor::setHttpClient($curl); ``` -------------------------------- ### CRON expression field layout Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/action-scheduler/lib/cron-expression/README.md Diagram showing the six fields of a CRON expression: minute, hour, day of month, month, day of week, and optional year. The day of week uses 0-7 where Sunday is 0 or 7. ```text * * * * * * - - - - - - | | | | | | | | | | | +---- year [optional] | | | | +----- day of week (0 - 7) (Sunday=0 or 7) | | | +---------- month (1 - 12) | | +--------------- day of month (1 - 31) | +-------------------- hour (0 - 23) +------------------------- min (0 - 59) ``` -------------------------------- ### Set automatic network retries with Stripe::setMaxNetworkRetries Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Configures automatic retries for requests that fail due to intermittent network problems. Idempotency keys are added to guarantee retries are safe. ```php \Stripe\Stripe::setMaxNetworkRetries(2); ``` -------------------------------- ### Customize Stripe request timeouts with CurlClient Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Sets up a custom CurlClient to modify connect and total timeouts, then tells the Stripe API client to use it. Defaults are defined by CurlClient::DEFAULT_TIMEOUT and DEFAULT_CONNECT_TIMEOUT. Note: decreasing timeouts for non-read-only calls is not recommended; use idempotency tokens to avoid duplicate transactions. ```php // set up your tweaked Curl client $curl = new \Stripe\HttpClient\CurlClient(); $curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT $curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT echo $curl->getTimeout(); // 10 echo $curl->getConnectTimeout(); // 5 // tell Stripe to use the tweaked client \Stripe\ApiRequestor::setHttpClient($curl); // use the Stripe API client as you normally would ``` -------------------------------- ### Update bundled CA certificates Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Updates the bundled CA certificates from the Mozilla cURL release. ```bash ./update_certs.php ``` -------------------------------- ### Google App Engine: Disable Gzip Encoding Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md When using Google App Engine, turn off accepting gzip responses by setting 'acceptGzipEncoding' to false in the gateway configuration. ```php $gateway = new Braintree\Gateway([ 'environment' => 'sandbox', // ... 'acceptGzipEncoding' => false, ]); ``` -------------------------------- ### Set CURLOPT_SSLVERSION for TLS compatibility Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Forces TLS 1.0 or 1.1 for Stripe requests when upgrading cURL/OpenSSL is not possible. This may resolve the 'Stripe no longer supports API requests made with TLS 1.0' error. ```php $curl = new \Stripe\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]); \Stripe\ApiRequestor::setHttpClient($curl); ``` -------------------------------- ### Disable telemetry with Stripe::setEnableTelemetry Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Disables telemetry sent to Stripe regarding request latency and feature usage. Telemetry is enabled by default. ```php \Stripe\Stripe::setEnableTelemetry(false); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.