### Install and Run stripe-mock Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Install the stripe-mock tool using 'go install' and run it from a background terminal to simulate Stripe API responses during testing. ```bash go install github.com/stripe/stripe-mock@latest ``` ```bash stripe-mock ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Install project dependencies using either the 'just' command or Composer directly. ```bash just install ``` ```bash composer install ``` -------------------------------- ### Install Public Preview SDK Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use this command to install a specific public preview version of the Stripe PHP SDK. Pinning the version in composer.json is recommended to avoid breaking changes. ```bash composer require stripe/stripe-php:v ``` -------------------------------- ### Include Stripe PHP Library Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Include the `init.php` file to use the Stripe PHP bindings when installing manually. ```php require_once '/path/to/stripe-php/init.php'; ``` -------------------------------- ### Install Composer on macOS Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use Homebrew to install Composer, a dependency manager for PHP. ```bash brew install composer ``` -------------------------------- ### Install Stripe PHP Bindings with Composer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use Composer to install the Stripe PHP library. This is the recommended method for managing dependencies. ```bash composer require stripe/stripe-php ``` -------------------------------- ### Install Cron Expression Library via Composer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/action-scheduler/lib/cron-expression/README.md Add the mtdowling/cron-expression package to your project's composer.json file for installation. ```javascript { "require": { "mtdowling/cron-expression": "1.0.*" } } ``` -------------------------------- ### Example of Allowing Weak Passwords Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/CHANGELOG.txt Demonstrates how to allow weak passwords using a Gist link, which can be applied via the `pmpro_allow_weak_passwords` filter. ```php https://gist.github.com/ideadude/5a12119b9ce1c2aad87b2d69cb8f9505 ``` -------------------------------- ### Instantiate Braintree Gateway with PSR-4 Namespacing (PHP) Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Shows how to instantiate the Braintree Gateway using PSR-4 namespacing, which is required when using composer with specific optimization flags. This is an alternative to the direct instantiation shown in the quick start. ```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) ``` -------------------------------- ### Example of Sending Additional Activity Emails Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/CHANGELOG.txt Illustrates how to send additional activity emails by adding the `$recipient` parameter to the `sendAdminActivity()` function. ```php https://gist.github.com/dparker1005/6bf650370a12aef44adf8c8c26d3e906 ``` -------------------------------- ### Basic Cron Expression Usage Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/action-scheduler/lib/cron-expression/README.md Instantiate a cron expression using factory, check if it's due, and get the next and previous run dates. ```php isDue(); echo $cron->getNextRunDate()->format('Y-m-d H:i:s'); echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s'); ``` -------------------------------- ### Run the Test Suite Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Execute the project's test suite using the 'just test' command or by directly invoking PHPUnit. ```bash just test ``` ```bash ./vendor/bin/phpunit ``` -------------------------------- ### Instantiate Braintree Gateway and Process Transaction (PHP) Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Demonstrates how to instantiate the Braintree Gateway and process a sale transaction. Includes error handling for validation and processing failures. Ensure you have the Braintree library included. ```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()); } ``` -------------------------------- ### Get Last Order by Status - MemberOrder Class Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/CHANGELOG.txt Retrieve the last order for a user, with an option to specify the order status. Defaults to 'success'. ```php getLastMemberOrder($user_id, "cancelled"); getLastMemberOrder($user_id, false); ``` -------------------------------- ### Include Stripe PHP Autoloader Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md After installing via Composer, include the autoloader file to make the Stripe library classes available in your PHP project. ```php require_once 'vendor/autoload.php'; ``` -------------------------------- ### Create a Stripe Customer Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Instantiate the Stripe client with your secret key and create a new customer with specified details. Ensure you have the necessary API keys and that the `curl`, `json`, and `mbstring` PHP extensions are enabled. ```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; ``` -------------------------------- ### Set SSL Version for cURL Client Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md If encountering TLS compatibility issues, you can explicitly set the SSL version for the cURL client. This example sets it to TLS 1.0. ```php $curl = new \Stripe\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]); \Stripe\ApiRequestor::setHttpClient($curl); ``` -------------------------------- ### Add Beta Version Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use the `addBetaVersion` function to set a name and version for preview features that require it in the `Stripe-Version` header. ```APIDOC ## Add Beta Version ### Description Use the `addBetaVersion` function to set a name and version for preview features that require it in the `Stripe-Version` header. This function is only available in public preview SDKs. ### Method `Stripe::addBetaVersion(string $name, string $version)` ### Parameters - **name** (string) - Required - The name of the beta feature. - **version** (string) - Required - The version of the beta feature. ### Example ```php Stripe::addBetaVersion("feature_beta", "v3"); ``` ``` -------------------------------- ### Run an Individual Test File Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Execute a specific test file within the suite using 'just test' with the file path or by directly invoking PHPUnit. ```bash just test tests/Stripe/UtilTest.php ``` ```bash ./vendor/bin/phpunit tests/Stripe/UtilTest.php ``` -------------------------------- ### Make Custom API Requests Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Use the `rawRequest` method on `StripeClient` to send requests to undocumented APIs or bypass library method definitions. For POST requests, provide parameters and headers. For GET requests, include query parameters in the URL and set params to null. ```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", ]); ``` -------------------------------- ### Set Custom CA Bundle Path Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Stripe/README.md Configure the library to use a custom CA certificate bundle instead of the internal one. Provide the path to your CA bundle file. ```php \Stripe\Stripe::setCABundlePath("path/to/ca/bundle"); ``` -------------------------------- ### Build and Run Docker Image (CLI) Source: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/lib/Braintree/README.md Command to build and run the Docker image for developing the Braintree PHP library. This command will drop you into a terminal within the container. ```bash make ```