From f7ba23b3bbdbc015b7cee861dd161a29ea2d570b Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Sat, 7 Oct 2017 20:24:28 +0100 Subject: [PATCH] Load stripe-php via composer. Always load stripe.js when on a payment processor page (recommended by stripe for fraud detection). --- CRM/Core/Payment/Stripe.php | 3 +- CRM/Stripe/Page/Webhook.php | 1 - CRM/Stripe/Upgrader.php | 1 - composer.json | 5 + composer.lock | 73 +++ info.xml | 1 + js/civicrm_stripe.js | 22 +- packages/stripe-php/.travis.yml | 17 - packages/stripe-php/VERSION | 1 - packages/stripe-php/lib/Source.php | 58 --- .../stripe-php/tests/ApiRequestorTest.php | 68 --- .../stripe-php/tests/BitcoinReceiverTest.php | 120 ----- packages/stripe-php/tests/SourceTest.php | 78 ---- .../stripe-php/tests/TransferReversalTest.php | 15 - packages/stripe-php/tests/TransferTest.php | 110 ----- packages/stripe-php/tests/UtilTest.php | 45 -- stripe.civix.php | 197 ++++++-- stripe.php | 7 +- vendor/autoload.php | 7 + vendor/composer/ClassLoader.php | 441 ++++++++++++++++++ vendor/composer/LICENSE | 21 + vendor/composer/autoload_classmap.php | 9 + vendor/composer/autoload_namespaces.php | 9 + vendor/composer/autoload_psr4.php | 10 + vendor/composer/autoload_real.php | 52 +++ vendor/composer/autoload_static.php | 31 ++ vendor/composer/installed.json | 59 +++ .../stripe}/stripe-php/.coveralls.yml | 0 .../stripe-php/.github/ISSUE_TEMPLATE.md | 0 .../stripe}/stripe-php/.gitignore | 0 vendor/stripe/stripe-php/.travis.yml | 42 ++ .../stripe}/stripe-php/CHANGELOG.md | 96 ++++ .../stripe}/stripe-php/LICENSE | 0 .../stripe}/stripe-php/README.md | 22 +- vendor/stripe/stripe-php/VERSION | 1 + .../stripe}/stripe-php/build.php | 0 .../stripe}/stripe-php/composer.json | 0 .../stripe-php/data/ca-certificates.crt | 0 .../stripe}/stripe-php/data/test.png | Bin vendor/stripe/stripe-php/examples/oauth.php | 55 +++ .../stripe}/stripe-php/init.php | 23 + .../stripe}/stripe-php/lib/Account.php | 17 +- .../stripe}/stripe-php/lib/AlipayAccount.php | 0 .../stripe}/stripe-php/lib/ApiRequestor.php | 91 +++- .../stripe}/stripe-php/lib/ApiResource.php | 7 +- .../stripe}/stripe-php/lib/ApiResponse.php | 0 .../stripe}/stripe-php/lib/ApplePayDomain.php | 3 +- .../stripe}/stripe-php/lib/ApplicationFee.php | 3 +- .../stripe-php/lib/ApplicationFeeRefund.php | 0 .../stripe}/stripe-php/lib/AttachedObject.php | 14 +- .../stripe}/stripe-php/lib/Balance.php | 0 .../stripe-php/lib/BalanceTransaction.php | 3 +- .../stripe}/stripe-php/lib/BankAccount.php | 0 .../stripe-php/lib/BitcoinReceiver.php | 19 +- .../stripe-php/lib/BitcoinTransaction.php | 0 vendor/stripe/stripe-php/lib/Card.php | 37 ++ .../stripe}/stripe-php/lib/Charge.php | 5 +- .../stripe}/stripe-php/lib/Collection.php | 2 +- .../stripe}/stripe-php/lib/CountrySpec.php | 4 +- .../stripe}/stripe-php/lib/Coupon.php | 3 +- .../stripe}/stripe-php/lib/Customer.php | 3 +- .../stripe}/stripe-php/lib/Dispute.php | 3 +- vendor/stripe/stripe-php/lib/EphemeralKey.php | 55 +++ .../stripe}/stripe-php/lib/Error/Api.php | 0 .../stripe-php/lib/Error/ApiConnection.php | 0 .../stripe-php/lib/Error/Authentication.php | 0 .../stripe}/stripe-php/lib/Error/Base.php | 0 .../stripe}/stripe-php/lib/Error/Card.php | 0 .../stripe-php/lib/Error/InvalidRequest.php | 0 .../lib/Error/OAuth/InvalidClient.php | 10 + .../lib/Error/OAuth/InvalidGrant.php | 13 + .../lib/Error/OAuth/InvalidRequest.php | 11 + .../lib/Error/OAuth/InvalidScope.php | 10 + .../stripe-php/lib/Error/OAuth/OAuthBase.php | 23 + .../lib/Error/OAuth/UnsupportedGrantType.php | 11 + .../Error/OAuth/UnsupportedResponseType.php | 11 + .../stripe-php/lib/Error/Permission.php | 0 .../stripe-php/lib/Error/RateLimit.php | 0 .../lib/Error/SignatureVerification.php | 20 + .../stripe}/stripe-php/lib/Event.php | 3 +- .../stripe-php/lib/ExternalAccount.php | 0 .../stripe}/stripe-php/lib/FileUpload.php | 3 +- .../lib/HttpClient/ClientInterface.php | 2 +- .../stripe-php/lib/HttpClient/CurlClient.php | 64 +-- .../stripe}/stripe-php/lib/Invoice.php | 7 +- .../stripe}/stripe-php/lib/InvoiceItem.php | 3 +- .../stripe-php/lib/JsonSerializable.php | 0 .../stripe/stripe-php/lib/LoginLink.php | 4 +- vendor/stripe/stripe-php/lib/OAuth.php | 98 ++++ .../stripe}/stripe-php/lib/Order.php | 3 +- .../stripe}/stripe-php/lib/OrderReturn.php | 14 +- vendor/stripe/stripe-php/lib/Payout.php | 98 ++++ .../stripe}/stripe-php/lib/Plan.php | 3 +- .../stripe}/stripe-php/lib/Product.php | 3 +- .../stripe}/stripe-php/lib/Recipient.php | 3 +- .../stripe-php/lib/RecipientTransfer.php | 38 ++ .../stripe}/stripe-php/lib/Refund.php | 3 +- .../stripe}/stripe-php/lib/SKU.php | 3 +- .../stripe-php/lib/SingletonApiResource.php | 0 vendor/stripe/stripe-php/lib/Source.php | 116 +++++ .../stripe}/stripe-php/lib/Stripe.php | 51 +- .../stripe}/stripe-php/lib/StripeObject.php | 11 +- .../stripe}/stripe-php/lib/Subscription.php | 3 +- .../stripe-php/lib/SubscriptionItem.php | 3 +- .../stripe}/stripe-php/lib/ThreeDSecure.php | 3 +- .../stripe}/stripe-php/lib/Token.php | 3 +- .../stripe}/stripe-php/lib/Transfer.php | 14 +- .../stripe-php/lib/TransferReversal.php | 0 .../lib/Util/AutoPagingIterator.php | 0 .../stripe-php/lib/Util/DefaultLogger.php | 18 + .../stripe-php/lib/Util/LoggerInterface.php | 36 ++ .../stripe-php/lib/Util/RequestOptions.php | 0 .../stripe}/stripe-php/lib/Util/Set.php | 0 .../stripe}/stripe-php/lib/Util/Util.php | 75 ++- vendor/stripe/stripe-php/lib/Webhook.php | 40 ++ .../stripe-php/lib/WebhookSignature.php | 132 ++++++ .../stripe-php/phpunit.no_autoload.xml | 0 .../stripe}/stripe-php/phpunit.xml | 0 .../stripe}/stripe-php/tests/AccountTest.php | 63 +++ .../stripe-php/tests/ApiRequestorTest.php | 228 +++++++++ .../stripe-php/tests/ApplePayDomainTest.php | 0 .../tests/ApplicationFeeRefundTest.php | 0 .../stripe-php/tests/ApplicationFeeTest.php | 0 .../stripe-php/tests/AttachedObjectTest.php | 18 + .../tests/AuthenticationErrorTest.php | 0 .../stripe}/stripe-php/tests/BalanceTest.php | 0 .../tests/BalanceTransactionTest.php | 0 .../stripe-php/tests/BankAccountTest.php | 0 .../stripe-php/tests/BitcoinReceiverTest.php | 26 ++ .../stripe-php/tests/CardErrorTest.php | 9 +- .../stripe}/stripe-php/tests/ChargeTest.php | 76 +-- .../stripe-php/tests/CollectionTest.php | 0 .../stripe-php/tests/CountrySpecTest.php | 0 .../stripe}/stripe-php/tests/CouponTest.php | 0 .../stripe-php/tests/CurlClientTest.php | 51 +- .../stripe}/stripe-php/tests/CustomerTest.php | 51 +- .../stripe}/stripe-php/tests/DiscountTest.php | 0 .../stripe}/stripe-php/tests/DisputeTest.php | 23 +- .../stripe-php/tests/EphemeralKeyTest.php | 117 +++++ .../stripe}/stripe-php/tests/ErrorTest.php | 0 .../stripe-php/tests/ExternalAccountTest.php | 0 .../stripe-php/tests/FileUploadTest.php | 1 + .../tests/InvalidRequestErrorTest.php | 0 .../stripe}/stripe-php/tests/InvoiceTest.php | 29 +- vendor/stripe/stripe-php/tests/OAuthTest.php | 99 ++++ vendor/stripe/stripe-php/tests/PayoutTest.php | 89 ++++ .../stripe-php/tests/PermissionsErrorTest.php | 0 .../stripe}/stripe-php/tests/PlanTest.php | 0 .../stripe}/stripe-php/tests/ProductTest.php | 9 +- .../stripe-php/tests/RateLimitErrorTest.php | 0 .../stripe-php/tests/RecipientTest.php | 33 +- .../stripe}/stripe-php/tests/RefundTest.php | 51 -- .../stripe-php/tests/RequestOptionsTest.php | 0 vendor/stripe/stripe-php/tests/SourceTest.php | 218 +++++++++ .../stripe-php/tests/StripeObjectTest.php | 0 .../stripe-php/tests/SubscriptionItemTest.php | 13 +- .../stripe-php/tests/SubscriptionTest.php | 17 +- .../stripe}/stripe-php/tests/TestCase.php | 79 +++- .../stripe-php/tests/ThreeDSecureTest.php | 0 .../stripe}/stripe-php/tests/TokenTest.php | 0 .../stripe-php/tests/TransferReversalTest.php | 19 + .../stripe/stripe-php/tests/TransferTest.php | 46 ++ .../tests/UtilDefaultLoggerTest.php | 28 ++ vendor/stripe/stripe-php/tests/UtilTest.php | 87 ++++ .../stripe/stripe-php/tests/WebhookTest.php | 110 +++++ .../tests/bootstrap.no_autoload.php | 0 .../stripe}/stripe-php/tests/bootstrap.php | 0 167 files changed, 3533 insertions(+), 992 deletions(-) create mode 100644 composer.json create mode 100644 composer.lock delete mode 100644 packages/stripe-php/.travis.yml delete mode 100644 packages/stripe-php/VERSION delete mode 100644 packages/stripe-php/lib/Source.php delete mode 100644 packages/stripe-php/tests/ApiRequestorTest.php delete mode 100644 packages/stripe-php/tests/BitcoinReceiverTest.php delete mode 100644 packages/stripe-php/tests/SourceTest.php delete mode 100644 packages/stripe-php/tests/TransferReversalTest.php delete mode 100644 packages/stripe-php/tests/TransferTest.php delete mode 100644 packages/stripe-php/tests/UtilTest.php create mode 100644 vendor/autoload.php create mode 100644 vendor/composer/ClassLoader.php create mode 100644 vendor/composer/LICENSE create mode 100644 vendor/composer/autoload_classmap.php create mode 100644 vendor/composer/autoload_namespaces.php create mode 100644 vendor/composer/autoload_psr4.php create mode 100644 vendor/composer/autoload_real.php create mode 100644 vendor/composer/autoload_static.php create mode 100644 vendor/composer/installed.json rename {packages => vendor/stripe}/stripe-php/.coveralls.yml (100%) rename {packages => vendor/stripe}/stripe-php/.github/ISSUE_TEMPLATE.md (100%) rename {packages => vendor/stripe}/stripe-php/.gitignore (100%) create mode 100644 vendor/stripe/stripe-php/.travis.yml rename {packages => vendor/stripe}/stripe-php/CHANGELOG.md (85%) rename {packages => vendor/stripe}/stripe-php/LICENSE (100%) rename {packages => vendor/stripe}/stripe-php/README.md (91%) create mode 100644 vendor/stripe/stripe-php/VERSION rename {packages => vendor/stripe}/stripe-php/build.php (100%) rename {packages => vendor/stripe}/stripe-php/composer.json (100%) rename {packages => vendor/stripe}/stripe-php/data/ca-certificates.crt (100%) rename {packages => vendor/stripe}/stripe-php/data/test.png (100%) create mode 100644 vendor/stripe/stripe-php/examples/oauth.php rename {packages => vendor/stripe}/stripe-php/init.php (74%) rename {packages => vendor/stripe}/stripe-php/lib/Account.php (86%) rename {packages => vendor/stripe}/stripe-php/lib/AlipayAccount.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/ApiRequestor.php (68%) rename {packages => vendor/stripe}/stripe-php/lib/ApiResource.php (95%) rename {packages => vendor/stripe}/stripe-php/lib/ApiResponse.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/ApplePayDomain.php (91%) rename {packages => vendor/stripe}/stripe-php/lib/ApplicationFee.php (92%) rename {packages => vendor/stripe}/stripe-php/lib/ApplicationFeeRefund.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/AttachedObject.php (68%) rename {packages => vendor/stripe}/stripe-php/lib/Balance.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/BalanceTransaction.php (90%) rename {packages => vendor/stripe}/stripe-php/lib/BankAccount.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/BitcoinReceiver.php (80%) rename {packages => vendor/stripe}/stripe-php/lib/BitcoinTransaction.php (100%) create mode 100644 vendor/stripe/stripe-php/lib/Card.php rename {packages => vendor/stripe}/stripe-php/lib/Charge.php (96%) rename {packages => vendor/stripe}/stripe-php/lib/Collection.php (96%) rename {packages => vendor/stripe}/stripe-php/lib/CountrySpec.php (81%) rename {packages => vendor/stripe}/stripe-php/lib/Coupon.php (92%) rename {packages => vendor/stripe}/stripe-php/lib/Customer.php (97%) rename {packages => vendor/stripe}/stripe-php/lib/Dispute.php (94%) create mode 100644 vendor/stripe/stripe-php/lib/EphemeralKey.php rename {packages => vendor/stripe}/stripe-php/lib/Error/Api.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/ApiConnection.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/Authentication.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/Base.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/Card.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/InvalidRequest.php (100%) create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/InvalidClient.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/InvalidGrant.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/InvalidRequest.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/InvalidScope.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/OAuthBase.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedGrantType.php create mode 100644 vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedResponseType.php rename {packages => vendor/stripe}/stripe-php/lib/Error/Permission.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Error/RateLimit.php (100%) create mode 100644 vendor/stripe/stripe-php/lib/Error/SignatureVerification.php rename {packages => vendor/stripe}/stripe-php/lib/Event.php (87%) rename {packages => vendor/stripe}/stripe-php/lib/ExternalAccount.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/FileUpload.php (90%) rename {packages => vendor/stripe}/stripe-php/lib/HttpClient/ClientInterface.php (91%) rename {packages => vendor/stripe}/stripe-php/lib/HttpClient/CurlClient.php (87%) rename {packages => vendor/stripe}/stripe-php/lib/Invoice.php (88%) rename {packages => vendor/stripe}/stripe-php/lib/InvoiceItem.php (92%) rename {packages => vendor/stripe}/stripe-php/lib/JsonSerializable.php (100%) rename packages/stripe-php/lib/Card.php => vendor/stripe/stripe-php/lib/LoginLink.php (52%) create mode 100644 vendor/stripe/stripe-php/lib/OAuth.php rename {packages => vendor/stripe}/stripe-php/lib/Order.php (94%) rename {packages => vendor/stripe}/stripe-php/lib/OrderReturn.php (56%) create mode 100644 vendor/stripe/stripe-php/lib/Payout.php rename {packages => vendor/stripe}/stripe-php/lib/Plan.php (94%) rename {packages => vendor/stripe}/stripe-php/lib/Product.php (92%) rename {packages => vendor/stripe}/stripe-php/lib/Recipient.php (94%) create mode 100644 vendor/stripe/stripe-php/lib/RecipientTransfer.php rename {packages => vendor/stripe}/stripe-php/lib/Refund.php (93%) rename {packages => vendor/stripe}/stripe-php/lib/SKU.php (92%) rename {packages => vendor/stripe}/stripe-php/lib/SingletonApiResource.php (100%) create mode 100644 vendor/stripe/stripe-php/lib/Source.php rename {packages => vendor/stripe}/stripe-php/lib/Stripe.php (69%) rename {packages => vendor/stripe}/stripe-php/lib/StripeObject.php (95%) rename {packages => vendor/stripe}/stripe-php/lib/Subscription.php (94%) rename {packages => vendor/stripe}/stripe-php/lib/SubscriptionItem.php (93%) rename {packages => vendor/stripe}/stripe-php/lib/ThreeDSecure.php (85%) rename {packages => vendor/stripe}/stripe-php/lib/Token.php (87%) rename {packages => vendor/stripe}/stripe-php/lib/Transfer.php (85%) rename {packages => vendor/stripe}/stripe-php/lib/TransferReversal.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Util/AutoPagingIterator.php (100%) create mode 100644 vendor/stripe/stripe-php/lib/Util/DefaultLogger.php create mode 100644 vendor/stripe/stripe-php/lib/Util/LoggerInterface.php rename {packages => vendor/stripe}/stripe-php/lib/Util/RequestOptions.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Util/Set.php (100%) rename {packages => vendor/stripe}/stripe-php/lib/Util/Util.php (69%) create mode 100644 vendor/stripe/stripe-php/lib/Webhook.php create mode 100644 vendor/stripe/stripe-php/lib/WebhookSignature.php rename {packages => vendor/stripe}/stripe-php/phpunit.no_autoload.xml (100%) rename {packages => vendor/stripe}/stripe-php/phpunit.xml (100%) rename {packages => vendor/stripe}/stripe-php/tests/AccountTest.php (84%) create mode 100644 vendor/stripe/stripe-php/tests/ApiRequestorTest.php rename {packages => vendor/stripe}/stripe-php/tests/ApplePayDomainTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/ApplicationFeeRefundTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/ApplicationFeeTest.php (100%) create mode 100644 vendor/stripe/stripe-php/tests/AttachedObjectTest.php rename {packages => vendor/stripe}/stripe-php/tests/AuthenticationErrorTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/BalanceTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/BalanceTransactionTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/BankAccountTest.php (100%) create mode 100644 vendor/stripe/stripe-php/tests/BitcoinReceiverTest.php rename {packages => vendor/stripe}/stripe-php/tests/CardErrorTest.php (83%) rename {packages => vendor/stripe}/stripe-php/tests/ChargeTest.php (62%) rename {packages => vendor/stripe}/stripe-php/tests/CollectionTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/CountrySpecTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/CouponTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/CurlClientTest.php (62%) rename {packages => vendor/stripe}/stripe-php/tests/CustomerTest.php (85%) rename {packages => vendor/stripe}/stripe-php/tests/DiscountTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/DisputeTest.php (81%) create mode 100644 vendor/stripe/stripe-php/tests/EphemeralKeyTest.php rename {packages => vendor/stripe}/stripe-php/tests/ErrorTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/ExternalAccountTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/FileUploadTest.php (95%) rename {packages => vendor/stripe}/stripe-php/tests/InvalidRequestErrorTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/InvoiceTest.php (66%) create mode 100644 vendor/stripe/stripe-php/tests/OAuthTest.php create mode 100644 vendor/stripe/stripe-php/tests/PayoutTest.php rename {packages => vendor/stripe}/stripe-php/tests/PermissionsErrorTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/PlanTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/ProductTest.php (95%) rename {packages => vendor/stripe}/stripe-php/tests/RateLimitErrorTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/RecipientTest.php (76%) rename {packages => vendor/stripe}/stripe-php/tests/RefundTest.php (63%) rename {packages => vendor/stripe}/stripe-php/tests/RequestOptionsTest.php (100%) create mode 100644 vendor/stripe/stripe-php/tests/SourceTest.php rename {packages => vendor/stripe}/stripe-php/tests/StripeObjectTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/SubscriptionItemTest.php (69%) rename {packages => vendor/stripe}/stripe-php/tests/SubscriptionTest.php (88%) rename {packages => vendor/stripe}/stripe-php/tests/TestCase.php (68%) rename {packages => vendor/stripe}/stripe-php/tests/ThreeDSecureTest.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/TokenTest.php (100%) create mode 100644 vendor/stripe/stripe-php/tests/TransferReversalTest.php create mode 100644 vendor/stripe/stripe-php/tests/TransferTest.php create mode 100644 vendor/stripe/stripe-php/tests/UtilDefaultLoggerTest.php create mode 100644 vendor/stripe/stripe-php/tests/UtilTest.php create mode 100644 vendor/stripe/stripe-php/tests/WebhookTest.php rename {packages => vendor/stripe}/stripe-php/tests/bootstrap.no_autoload.php (100%) rename {packages => vendor/stripe}/stripe-php/tests/bootstrap.php (100%) diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php index c833f4e7..f938097b 100644 --- a/CRM/Core/Payment/Stripe.php +++ b/CRM/Core/Payment/Stripe.php @@ -333,8 +333,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { $parsed_url['query'] . "&_qf_Main_display=1&qfKey={$qfKey}", FALSE, NULL, FALSE); } - // Include Stripe library then set plugin info and API credentials. - require_once('stripe-php/init.php'); + // Set plugin info and API credentials. \Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL()); \Stripe\Stripe::setApiKey($this->_paymentProcessor['user_name']); diff --git a/CRM/Stripe/Page/Webhook.php b/CRM/Stripe/Page/Webhook.php index a5f45d5e..ed454eb7 100644 --- a/CRM/Stripe/Page/Webhook.php +++ b/CRM/Stripe/Page/Webhook.php @@ -111,7 +111,6 @@ class CRM_Stripe_Page_Webhook extends CRM_Core_Page { CRM_Utils_System::civiExit(); } - require_once ("packages/stripe-php/init.php"); \Stripe\Stripe::setAppInfo('CiviCRM', CRM_Utils_System::version(), CRM_Utils_System::baseURL()); \Stripe\Stripe::setApiKey($stripe_key); diff --git a/CRM/Stripe/Upgrader.php b/CRM/Stripe/Upgrader.php index 26edd63c..ceb12794 100644 --- a/CRM/Stripe/Upgrader.php +++ b/CRM/Stripe/Upgrader.php @@ -1,5 +1,4 @@ <?php -require_once('packages/stripe-php/init.php'); /** * Collection of upgrade steps. * DO NOT USE a naming scheme other than upgrade_N, where N is an integer. diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..4be7dfa3 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "stripe/stripe-php": "^5.2" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..0a5cc024 --- /dev/null +++ b/composer.lock @@ -0,0 +1,73 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "2c17a82c0fb79b31818993eeb2df574d", + "packages": [ + { + "name": "stripe/stripe-php", + "version": "v5.2.3", + "source": { + "type": "git", + "url": "https://github.com/stripe/stripe-php.git", + "reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/9e8d565e991ca82c91d708b281063cefd69d7b2c", + "reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Stripe\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stripe and contributors", + "homepage": "https://github.com/stripe/stripe-php/contributors" + } + ], + "description": "Stripe PHP Library", + "homepage": "https://stripe.com/", + "keywords": [ + "api", + "payment processing", + "stripe" + ], + "time": "2017-09-27T20:35:23+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/info.xml b/info.xml index 020abf50..f4b0b273 100644 --- a/info.xml +++ b/info.xml @@ -5,6 +5,7 @@ <description>Stripe Payment Processor</description> <urls> <url desc="Main Extension Page">http://drastikbydesign.com</url> + <url desc="Support">https://www.mjwconsult.co.uk</url> </urls> <license>AGPL</license> <maintainer> diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index 8cb587dc..f8552e91 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -17,11 +17,11 @@ $(".messages.crm-error.stripe-message:first").remove(); } $form.prepend('<div class="messages crm-error stripe-message">' - + '<strong>Payment Error Response:</strong>' - + '<ul id="errorList">' - + '<li>Error: ' + response.error.message + '</li>' - + '</ul>' - + '</div>'); + + '<strong>Payment Error Response:</strong>' + + '<ul id="errorList">' + + '<li>Error: ' + response.error.message + '</li>' + + '</ul>' + + '</div>'); $submit.removeAttr('disabled').attr('value', buttonText); @@ -40,9 +40,7 @@ // Prepare the form. $(document).ready(function() { - $.getScript('https://js.stripe.com/v2/', function () { - Stripe.setPublishableKey($('#stripe-pub-key').val()); - }); + Stripe.setPublishableKey($('#stripe-pub-key').val()); // Check for form marked as a stripe-payment-form by the server. if (!($('form.stripe-payment-form').length)) { @@ -55,7 +53,7 @@ $('#crm-container > form').addClass('stripe-payment-form'); } } - + $form = $('form.stripe-payment-form'); if (isWebform) { $submit = $form.find('.button-primary'); @@ -183,7 +181,7 @@ } } else { - debugging('debug: qlmvy (Stripe is the only payprocessor here)'); + debugging('debug: qlmvy (Stripe is the only payprocessor here)'); } // Handle reuse of existing token @@ -229,7 +227,7 @@ }(cj, CRM)); function debugging (errorCode) { -// Uncomment the following to debug unexpected returns. -// console.log(errorCode); + // Uncomment the following to debug unexpected returns. + // console.log(errorCode); } diff --git a/packages/stripe-php/.travis.yml b/packages/stripe-php/.travis.yml deleted file mode 100644 index e46e1f37..00000000 --- a/packages/stripe-php/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: php - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - hhvm - -env: - - AUTOLOAD=1 - - AUTOLOAD=0 - -script: ./build.php ${AUTOLOAD} -after_script: ./vendor/bin/coveralls -v -sudo: false diff --git a/packages/stripe-php/VERSION b/packages/stripe-php/VERSION deleted file mode 100644 index 80895903..00000000 --- a/packages/stripe-php/VERSION +++ /dev/null @@ -1 +0,0 @@ -4.3.0 diff --git a/packages/stripe-php/lib/Source.php b/packages/stripe-php/lib/Source.php deleted file mode 100644 index 1637333c..00000000 --- a/packages/stripe-php/lib/Source.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Stripe; - -/** - * Class Source - * - * @package Stripe - */ -class Source extends ApiResource -{ - /** - * @param string $id The ID of the Source to retrieve. - * @param array|string|null $opts - * - * @return Source - */ - public static function retrieve($id, $opts = null) - { - return self::_retrieve($id, $opts); - } - - /** - * @param array|null $params - * @param array|string|null $opts - * - * @return Collection of Sources - */ - public static function all($params = null, $opts = null) - { - return self::_all($params, $opts); - } - - /** - * @param array|null $params - * @param array|string|null $opts - * - * @return Source The created Source. - */ - public static function create($params = null, $opts = null) - { - return self::_create($params, $opts); - } - - /** - * @param array|null $params - * @param array|string|null $options - * - * @return BankAccount The verified bank account. - */ - public function verify($params = null, $options = null) - { - $url = $this->instanceUrl() . '/verify'; - list($response, $opts) = $this->_request('post', $url, $params, $options); - $this->refreshFrom($response, $opts); - return $this; - } -} diff --git a/packages/stripe-php/tests/ApiRequestorTest.php b/packages/stripe-php/tests/ApiRequestorTest.php deleted file mode 100644 index 859fb63a..00000000 --- a/packages/stripe-php/tests/ApiRequestorTest.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -namespace Stripe; - -use Stripe\HttpClient\CurlClient; - -class ApiRequestorTest extends TestCase -{ - public function testEncodeObjects() - { - $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); - $method = $reflector->getMethod('_encodeObjects'); - $method->setAccessible(true); - - $a = array('customer' => new Customer('abcd')); - $enc = $method->invoke(null, $a); - $this->assertSame($enc, array('customer' => 'abcd')); - - // Preserves UTF-8 - $v = array('customer' => "☃"); - $enc = $method->invoke(null, $v); - $this->assertSame($enc, $v); - - // Encodes latin-1 -> UTF-8 - $v = array('customer' => "\xe9"); - $enc = $method->invoke(null, $v); - $this->assertSame($enc, array('customer' => "\xc3\xa9")); - } - - public function testHttpClientInjection() - { - $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); - $method = $reflector->getMethod('httpClient'); - $method->setAccessible(true); - - $curl = new CurlClient(); - $curl->setTimeout(10); - ApiRequestor::setHttpClient($curl); - - $injectedCurl = $method->invoke(new ApiRequestor()); - $this->assertSame($injectedCurl, $curl); - } - - public function testDefaultHeaders() - { - $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); - $method = $reflector->getMethod('_defaultHeaders'); - $method->setAccessible(true); - - // no way to stub static methods with PHPUnit 4.x :( - Stripe::setAppInfo('MyTestApp', '1.2.34', 'https://mytestapp.example'); - $apiKey = 'sk_test_notarealkey'; - - $headers = $method->invoke(null, $apiKey); - - $ua = json_decode($headers['X-Stripe-Client-User-Agent']); - $this->assertSame($ua->application->name, 'MyTestApp'); - $this->assertSame($ua->application->version, '1.2.34'); - $this->assertSame($ua->application->url, 'https://mytestapp.example'); - - $this->assertSame( - $headers['User-Agent'], - 'Stripe/v1 PhpBindings/' . Stripe::VERSION . ' MyTestApp/1.2.34 (https://mytestapp.example)' - ); - - $this->assertSame($headers['Authorization'], 'Bearer ' . $apiKey); - } -} diff --git a/packages/stripe-php/tests/BitcoinReceiverTest.php b/packages/stripe-php/tests/BitcoinReceiverTest.php deleted file mode 100644 index 49fb88f6..00000000 --- a/packages/stripe-php/tests/BitcoinReceiverTest.php +++ /dev/null @@ -1,120 +0,0 @@ -<?php - -namespace Stripe; - -class BitcoinReceiverTest extends TestCase -{ - public function testUrls() - { - $classUrl = BitcoinReceiver::classUrl('Stripe_BitcoinReceiver'); - $this->assertSame($classUrl, '/v1/bitcoin/receivers'); - $receiver = new BitcoinReceiver('abcd/efgh'); - $instanceUrl = $receiver->instanceUrl(); - $this->assertSame($instanceUrl, '/v1/bitcoin/receivers/abcd%2Fefgh'); - } - - public function testCreate() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $this->assertSame(100, $receiver->amount); - $this->assertNotNull($receiver->id); - } - - public function testRetrieve() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $r = BitcoinReceiver::retrieve($receiver->id); - $this->assertSame($receiver->id, $r->id); - - $this->assertInstanceOf('Stripe\\BitcoinTransaction', $r->transactions->data[0]); - } - - public function testList() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $receivers = BitcoinReceiver::all(); - $this->assertTrue(count($receivers->data) > 0); - } - - public function testListTransactions() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - $this->assertSame(0, count($receiver->transactions->data)); - - $transactions = $receiver->transactions->all(array("limit" => 1)); - $this->assertSame(1, count($transactions->data)); - } - - public function testDeleteWithCustomer() - { - self::authorizeFromEnv(); - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - $customer = Customer::create(array("source" => $receiver->id)); - $charge = Charge::create(array( - "customer" => $customer->id, - "amount" => $receiver->amount, - "currency" => $receiver->currency - )); - $receiver = BitcoinReceiver::retrieve($receiver->id); - $response = $receiver->delete(); - $this->assertTrue($response->deleted); - } - - public function testUpdateWithCustomer() - { - self::authorizeFromEnv(); - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - $customer = Customer::create(array("source" => $receiver->id)); - $receiver = BitcoinReceiver::retrieve($receiver->id); - - $receiver->description = "a new description"; - $receiver->save(); - - $base = Customer::classUrl(); - $parentExtn = $receiver['customer']; - $extn = $receiver['id']; - $this->assertEquals("$base/$parentExtn/sources/$extn", $receiver->instanceUrl()); - - $updatedReceiver = BitcoinReceiver::retrieve($receiver->id); - $this->assertEquals($receiver["description"], $updatedReceiver["description"]); - } - - public function testUpdateWithoutCustomer() - { - self::authorizeFromEnv(); - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $receiver->description = "a new description"; - $receiver->save(); - - $this->assertEquals(BitcoinReceiver::classUrl() . "/" . $receiver['id'], $receiver->instanceUrl()); - - $updatedReceiver = BitcoinReceiver::retrieve($receiver->id); - $this->assertEquals($receiver["description"], $updatedReceiver["description"]); - } - - public function testRefund() - { - self::authorizeFromEnv(); - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $receiver = BitcoinReceiver::retrieve($receiver->id); - $this->assertNull($receiver->refund_address); - - $refundAddress = "REFUNDHERE"; - $receiver->refund(array("refund_address" => $refundAddress)); - - $this->assertSame($refundAddress, $receiver->refund_address); - } -} diff --git a/packages/stripe-php/tests/SourceTest.php b/packages/stripe-php/tests/SourceTest.php deleted file mode 100644 index bd292c8c..00000000 --- a/packages/stripe-php/tests/SourceTest.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -namespace Stripe; - -class SourceTest extends TestCase -{ - public function testRetrieve() - { - $this->mockRequest( - 'GET', - '/v1/sources/src_foo', - array(), - array( - 'id' => 'src_foo', - 'object' => 'source', - ) - ); - $source = Source::retrieve('src_foo'); - $this->assertSame($source->id, 'src_foo'); - } - - public function testCreate() - { - $this->mockRequest( - 'POST', - '/v1/sources', - array( - 'type' => 'bitcoin', - 'amount' => 1000, - 'currency' => 'usd', - 'owner' => array('email' => 'jenny.rosen@example.com'), - ), - array( - 'id' => 'src_foo', - 'object' => 'source' - ) - ); - $source = Source::create(array( - 'type' => 'bitcoin', - 'amount' => 1000, - 'currency' => 'usd', - 'owner' => array('email' => 'jenny.rosen@example.com'), - )); - $this->assertSame($source->id, 'src_foo'); - } - - public function testVerify() - { - $response = array( - 'id' => 'src_foo', - 'object' => 'source', - 'verification' => array('status' => 'pending'), - ); - $this->mockRequest( - 'GET', - '/v1/sources/src_foo', - array(), - $response - ); - - $response['verification']['status'] = 'succeeded'; - $this->mockRequest( - 'POST', - '/v1/sources/src_foo/verify', - array( - 'values' => array(32, 45), - ), - $response - ); - - $source = Source::retrieve('src_foo'); - $this->assertSame($source->verification->status, 'pending'); - $source->verify(array( - 'values' => array(32, 45), - )); - $this->assertSame($source->verification->status, 'succeeded'); - } -} diff --git a/packages/stripe-php/tests/TransferReversalTest.php b/packages/stripe-php/tests/TransferReversalTest.php deleted file mode 100644 index 414f8168..00000000 --- a/packages/stripe-php/tests/TransferReversalTest.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -namespace Stripe; - -class TransferReversalTest extends TestCase -{ - - public function testList() - { - $transfer = self::createTestTransfer(); - $all = $transfer->reversals->all(); - $this->assertSame(false, $all['has_more']); - $this->assertSame(0, count($all->data)); - } -} diff --git a/packages/stripe-php/tests/TransferTest.php b/packages/stripe-php/tests/TransferTest.php deleted file mode 100644 index b6412a51..00000000 --- a/packages/stripe-php/tests/TransferTest.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php - -namespace Stripe; - -class TransferTest extends TestCase -{ - public function testCreate() - { - $recipient = self::createTestRecipient(); - - self::authorizeFromEnv(); - $transfer = Transfer::create(array( - 'amount' => 100, - 'currency' => 'usd', - 'recipient' => $recipient->id - )); - $this->assertSame('pending', $transfer->status); - } - - public function testRetrieve() - { - $recipient = self::createTestRecipient(); - - self::authorizeFromEnv(); - $transfer = Transfer::create(array( - 'amount' => 100, - 'currency' => 'usd', - 'recipient' => $recipient->id - )); - $reloaded = Transfer::retrieve($transfer->id); - $this->assertSame($reloaded->id, $transfer->id); - } - - /** - * @expectedException Stripe\Error\InvalidRequest - */ - public function testCancel() - { - $recipient = self::createTestRecipient(); - - self::authorizeFromEnv(); - $transfer = Transfer::create(array( - 'amount' => 100, - 'currency' => 'usd', - 'recipient' => $recipient->id - )); - $reloaded = Transfer::retrieve($transfer->id); - $this->assertSame($reloaded->id, $transfer->id); - - $reloaded->cancel(); - } - - public function testTransferUpdateMetadata() - { - $recipient = self::createTestRecipient(); - - self::authorizeFromEnv(); - $transfer = Transfer::create(array( - 'amount' => 100, - 'currency' => 'usd', - 'recipient' => $recipient->id - )); - - $transfer->metadata['test'] = 'foo bar'; - $transfer->save(); - - $updatedTransfer = Transfer::retrieve($transfer->id); - $this->assertSame('foo bar', $updatedTransfer->metadata['test']); - } - - public function testTransferUpdateMetadataAll() - { - $recipient = self::createTestRecipient(); - - self::authorizeFromEnv(); - $transfer = Transfer::create(array( - 'amount' => 100, - 'currency' => 'usd', - 'recipient' => $recipient->id - )); - - $transfer->metadata = array('test' => 'foo bar'); - $transfer->save(); - - $updatedTransfer = Transfer::retrieve($transfer->id); - $this->assertSame('foo bar', $updatedTransfer->metadata['test']); - } - - public function testRecipientUpdateMetadata() - { - $recipient = self::createTestRecipient(); - - $recipient->metadata['test'] = 'foo bar'; - $recipient->save(); - - $updatedRecipient = Recipient::retrieve($recipient->id); - $this->assertSame('foo bar', $updatedRecipient->metadata['test']); - } - - public function testRecipientUpdateMetadataAll() - { - $recipient = self::createTestRecipient(); - - $recipient->metadata = array('test' => 'foo bar'); - $recipient->save(); - - $updatedRecipient = Recipient::retrieve($recipient->id); - $this->assertSame('foo bar', $updatedRecipient->metadata['test']); - } -} diff --git a/packages/stripe-php/tests/UtilTest.php b/packages/stripe-php/tests/UtilTest.php deleted file mode 100644 index a1206d69..00000000 --- a/packages/stripe-php/tests/UtilTest.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace Stripe; - -class UtilTest extends TestCase -{ - public function testIsList() - { - $list = array(5, 'nstaoush', array()); - $this->assertTrue(Util\Util::isList($list)); - - $notlist = array(5, 'nstaoush', array(), 'bar' => 'baz'); - $this->assertFalse(Util\Util::isList($notlist)); - } - - public function testThatPHPHasValueSemanticsForArrays() - { - $original = array('php-arrays' => 'value-semantics'); - $derived = $original; - $derived['php-arrays'] = 'reference-semantics'; - - $this->assertSame('value-semantics', $original['php-arrays']); - } - - public function testConvertStripeObjectToArrayIncludesId() - { - $customer = self::createTestCustomer(); - $this->assertTrue(array_key_exists("id", $customer->__toArray(true))); - } - - public function testUtf8() - { - // UTF-8 string - $x = "\xc3\xa9"; - $this->assertSame(Util\Util::utf8($x), $x); - - // Latin-1 string - $x = "\xe9"; - $this->assertSame(Util\Util::utf8($x), "\xc3\xa9"); - - // Not a string - $x = true; - $this->assertSame(Util\Util::utf8($x), $x); - } -} diff --git a/stripe.civix.php b/stripe.civix.php index 5eaebca0..56ca975e 100644 --- a/stripe.civix.php +++ b/stripe.civix.php @@ -2,6 +2,83 @@ // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file +/** + * The ExtensionUtil class provides small stubs for accessing resources of this + * extension. + */ +class CRM_Stripe_ExtensionUtil { + const SHORT_NAME = "stripe"; + const LONG_NAME = "com.drastikbydesign.stripe"; + const CLASS_PREFIX = "CRM_Stripe"; + + /** + * Translate a string using the extension's domain. + * + * If the extension doesn't have a specific translation + * for the string, fallback to the default translations. + * + * @param string $text + * Canonical message text (generally en_US). + * @param array $params + * @return string + * Translated text. + * @see ts + */ + public static function ts($text, $params = array()) { + if (!array_key_exists('domain', $params)) { + $params['domain'] = array(self::LONG_NAME, NULL); + } + return ts($text, $params); + } + + /** + * Get the URL of a resource file (in this extension). + * + * @param string|NULL $file + * Ex: NULL. + * Ex: 'css/foo.css'. + * @return string + * Ex: 'http://example.org/sites/default/ext/org.example.foo'. + * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'. + */ + public static function url($file = NULL) { + if ($file === NULL) { + return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/'); + } + return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file); + } + + /** + * Get the path of a resource file (in this extension). + * + * @param string|NULL $file + * Ex: NULL. + * Ex: 'css/foo.css'. + * @return string + * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'. + * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'. + */ + public static function path($file = NULL) { + // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file); + return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file)); + } + + /** + * Get the name of a class within this extension. + * + * @param string $suffix + * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'. + * @return string + * Ex: 'CRM_Foo_Page_HelloWorld'. + */ + public static function findClass($suffix) { + return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix); + } + +} + +use CRM_Stripe_ExtensionUtil as E; + /** * (Delegated) Implements hook_civicrm_config(). * @@ -19,14 +96,14 @@ function _stripe_civix_civicrm_config(&$config = NULL) { $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; $extDir = $extRoot . 'templates'; - if ( is_array( $template->template_dir ) ) { - array_unshift( $template->template_dir, $extDir ); + if (is_array($template->template_dir)) { + array_unshift($template->template_dir, $extDir); } else { - $template->template_dir = array( $extDir, $template->template_dir ); + $template->template_dir = array($extDir, $template->template_dir); } - $include_path = $extRoot . PATH_SEPARATOR . get_include_path( ); + $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); } @@ -55,6 +132,20 @@ function _stripe_civix_civicrm_install() { } } +/** + * Implements hook_civicrm_postInstall(). + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall + */ +function _stripe_civix_civicrm_postInstall() { + _stripe_civix_civicrm_config(); + if ($upgrader = _stripe_civix_upgrader()) { + if (is_callable(array($upgrader, 'onPostInstall'))) { + $upgrader->onPostInstall(); + } + } +} + /** * Implements hook_civicrm_uninstall(). * @@ -117,7 +208,7 @@ function _stripe_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { * @return CRM_Stripe_Upgrader */ function _stripe_civix_upgrader() { - if (!file_exists(__DIR__.'/CRM/Stripe/Upgrader.php')) { + if (!file_exists(__DIR__ . '/CRM/Stripe/Upgrader.php')) { return NULL; } else { @@ -153,7 +244,8 @@ function _stripe_civix_find_files($dir, $pattern) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry{0} == '.') { - } elseif (is_dir($path)) { + } + elseif (is_dir($path)) { $todos[] = $path; } } @@ -175,9 +267,12 @@ function _stripe_civix_civicrm_managed(&$entities) { $es = include $file; foreach ($es as $e) { if (empty($e['module'])) { - $e['module'] = 'com.drastikbydesign.stripe'; + $e['module'] = E::LONG_NAME; } $entities[] = $e; + if (empty($e['params']['version'])) { + $e['params']['version'] = '3'; + } } } } @@ -204,7 +299,7 @@ function _stripe_civix_civicrm_caseTypes(&$caseTypes) { // throw new CRM_Core_Exception($errorMessage); } $caseTypes[$name] = array( - 'module' => 'com.drastikbydesign.stripe', + 'module' => E::LONG_NAME, 'name' => $name, 'file' => $file, ); @@ -212,14 +307,14 @@ function _stripe_civix_civicrm_caseTypes(&$caseTypes) { } /** -* (Delegated) Implements hook_civicrm_angularModules(). -* -* Find any and return any files matching "ang/*.ang.php" -* -* Note: This hook only runs in CiviCRM 4.5+. -* -* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules -*/ + * (Delegated) Implements hook_civicrm_angularModules(). + * + * Find any and return any files matching "ang/*.ang.php" + * + * Note: This hook only runs in CiviCRM 4.5+. + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules + */ function _stripe_civix_civicrm_angularModules(&$angularModules) { if (!is_dir(__DIR__ . '/ang')) { return; @@ -230,7 +325,7 @@ function _stripe_civix_civicrm_angularModules(&$angularModules) { $name = preg_replace(':\.ang\.php$:', '', basename($file)); $module = include $file; if (empty($module['ext'])) { - $module['ext'] = 'com.drastikbydesign.stripe'; + $module['ext'] = E::LONG_NAME; } $angularModules[$name] = $module; } @@ -259,33 +354,28 @@ function _stripe_civix_glob($pattern) { * @param array $menu - menu hierarchy * @param string $path - path where insertion should happen (ie. Administer/System Settings) * @param array $item - menu you need to insert (parent/child attributes will be filled for you) - * @param int $parentId - used internally to recurse in the menu structure */ -function _stripe_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) { - static $navId; - +function _stripe_civix_insert_navigation_menu(&$menu, $path, $item) { // If we are done going down the path, insert menu if (empty($path)) { - if (!$navId) $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation"); - $navId ++; - $menu[$navId] = array ( - 'attributes' => array_merge($item, array( + $menu[] = array( + 'attributes' => array_merge(array( 'label' => CRM_Utils_Array::value('name', $item), 'active' => 1, - 'parentID' => $parentId, - 'navID' => $navId, - )) + ), $item), ); - return true; + return TRUE; } else { // Find an recurse into the next level down - $found = false; + $found = FALSE; $path = explode('/', $path); $first = array_shift($path); foreach ($menu as $key => &$entry) { if ($entry['attributes']['name'] == $first) { - if (!$entry['child']) $entry['child'] = array(); + if (!isset($entry['child'])) { + $entry['child'] = array(); + } $found = _stripe_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key); } } @@ -293,6 +383,49 @@ function _stripe_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = } } +/** + * (Delegated) Implements hook_civicrm_navigationMenu(). + */ +function _stripe_civix_navigationMenu(&$nodes) { + if (!is_callable(array('CRM_Core_BAO_Navigation', 'fixNavigationMenu'))) { + _stripe_civix_fixNavigationMenu($nodes); + } +} + +/** + * Given a navigation menu, generate navIDs for any items which are + * missing them. + */ +function _stripe_civix_fixNavigationMenu(&$nodes) { + $maxNavID = 1; + array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) { + if ($key === 'navID') { + $maxNavID = max($maxNavID, $item); + } + }); + _stripe_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL); +} + +function _stripe_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) { + $origKeys = array_keys($nodes); + foreach ($origKeys as $origKey) { + if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) { + $nodes[$origKey]['attributes']['parentID'] = $parentID; + } + // If no navID, then assign navID and fix key. + if (!isset($nodes[$origKey]['attributes']['navID'])) { + $newKey = ++$maxNavID; + $nodes[$origKey]['attributes']['navID'] = $newKey; + $nodes[$newKey] = $nodes[$origKey]; + unset($nodes[$origKey]); + $origKey = $newKey; + } + if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) { + _stripe_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']); + } + } +} + /** * (Delegated) Implements hook_civicrm_alterSettingsFolders(). * @@ -306,7 +439,7 @@ function _stripe_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { $configured = TRUE; $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings'; - if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) { + if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) { $metaDataFolders[] = $settingsDir; } } diff --git a/stripe.php b/stripe.php index e766e9fc..6568e7b1 100644 --- a/stripe.php +++ b/stripe.php @@ -1,15 +1,13 @@ <?php require_once 'stripe.civix.php'; +require_once __DIR__.'/vendor/autoload.php'; /** * Implementation of hook_civicrm_config(). */ function stripe_civicrm_config(&$config) { _stripe_civix_civicrm_config($config); - $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR; - $include_path = $extRoot . PATH_SEPARATOR . get_include_path( ); - set_include_path( $include_path ); } /** @@ -210,6 +208,9 @@ function stripe_civicrm_managed(&$entities) { * @param $form */ function stripe_civicrm_buildForm($formName, &$form) { + if (!empty($form->_paymentProcessor['class_name'])) { + CRM_Core_Resources::singleton()->addScriptUrl('https://js.stripe.com/v2/'); + } if (($formName == 'CRM_Member_Form_MembershipRenewal') && !empty($form->_paymentProcessor['class_name'])) { // civicrm_stripe.js is not included on backend form renewal unless we add it here. CRM_Core_Resources::singleton()->addScriptFile('com.drastikbydesign.stripe', 'js/civicrm_stripe.js'); diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 00000000..626a39aa --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,7 @@ +<?php + +// autoload.php @generated by Composer + +require_once __DIR__ . '/composer/autoload_real.php'; + +return ComposerAutoloaderInit616f9d8b2edf40af77874da14d0fe64f::getLoader(); diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php new file mode 100644 index 00000000..4626994f --- /dev/null +++ b/vendor/composer/ClassLoader.php @@ -0,0 +1,441 @@ +<?php + +/* + * This file is part of Composer. + * + * (c) Nils Adermann <naderman@naderman.de> + * Jordi Boggiano <j.boggiano@seld.be> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier <fabien@symfony.com> + * @author Jordi Boggiano <j.boggiano@seld.be> + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE new file mode 100644 index 00000000..1a281248 --- /dev/null +++ b/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) 2016 Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..7a91153b --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ +<?php + +// autoload_classmap.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 00000000..b7fc0125 --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ +<?php + +// autoload_namespaces.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( +); diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php new file mode 100644 index 00000000..b7971032 --- /dev/null +++ b/vendor/composer/autoload_psr4.php @@ -0,0 +1,10 @@ +<?php + +// autoload_psr4.php @generated by Composer + +$vendorDir = dirname(dirname(__FILE__)); +$baseDir = dirname($vendorDir); + +return array( + 'Stripe\\' => array($vendorDir . '/stripe/stripe-php/lib'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 00000000..8d850a99 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,52 @@ +<?php + +// autoload_real.php @generated by Composer + +class ComposerAutoloaderInit616f9d8b2edf40af77874da14d0fe64f +{ + private static $loader; + + public static function loadClassLoader($class) + { + if ('Composer\Autoload\ClassLoader' === $class) { + require __DIR__ . '/ClassLoader.php'; + } + } + + public static function getLoader() + { + if (null !== self::$loader) { + return self::$loader; + } + + spl_autoload_register(array('ComposerAutoloaderInit616f9d8b2edf40af77874da14d0fe64f', 'loadClassLoader'), true, true); + self::$loader = $loader = new \Composer\Autoload\ClassLoader(); + spl_autoload_unregister(array('ComposerAutoloaderInit616f9d8b2edf40af77874da14d0fe64f', 'loadClassLoader')); + + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit616f9d8b2edf40af77874da14d0fe64f::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 00000000..2435ff94 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,31 @@ +<?php + +// autoload_static.php @generated by Composer + +namespace Composer\Autoload; + +class ComposerStaticInit616f9d8b2edf40af77874da14d0fe64f +{ + public static $prefixLengthsPsr4 = array ( + 'S' => + array ( + 'Stripe\\' => 7, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Stripe\\' => + array ( + 0 => __DIR__ . '/..' . '/stripe/stripe-php/lib', + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit616f9d8b2edf40af77874da14d0fe64f::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit616f9d8b2edf40af77874da14d0fe64f::$prefixDirsPsr4; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 00000000..77c30812 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,59 @@ +[ + { + "name": "stripe/stripe-php", + "version": "v5.2.3", + "version_normalized": "5.2.3.0", + "source": { + "type": "git", + "url": "https://github.com/stripe/stripe-php.git", + "reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/9e8d565e991ca82c91d708b281063cefd69d7b2c", + "reference": "9e8d565e991ca82c91d708b281063cefd69d7b2c", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "time": "2017-09-27T20:35:23+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Stripe\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stripe and contributors", + "homepage": "https://github.com/stripe/stripe-php/contributors" + } + ], + "description": "Stripe PHP Library", + "homepage": "https://stripe.com/", + "keywords": [ + "api", + "payment processing", + "stripe" + ] + } +] diff --git a/packages/stripe-php/.coveralls.yml b/vendor/stripe/stripe-php/.coveralls.yml similarity index 100% rename from packages/stripe-php/.coveralls.yml rename to vendor/stripe/stripe-php/.coveralls.yml diff --git a/packages/stripe-php/.github/ISSUE_TEMPLATE.md b/vendor/stripe/stripe-php/.github/ISSUE_TEMPLATE.md similarity index 100% rename from packages/stripe-php/.github/ISSUE_TEMPLATE.md rename to vendor/stripe/stripe-php/.github/ISSUE_TEMPLATE.md diff --git a/packages/stripe-php/.gitignore b/vendor/stripe/stripe-php/.gitignore similarity index 100% rename from packages/stripe-php/.gitignore rename to vendor/stripe/stripe-php/.gitignore diff --git a/vendor/stripe/stripe-php/.travis.yml b/vendor/stripe/stripe-php/.travis.yml new file mode 100644 index 00000000..8e6dbab1 --- /dev/null +++ b/vendor/stripe/stripe-php/.travis.yml @@ -0,0 +1,42 @@ +language: php +sudo: false + +matrix: + include: + - php: 5.3 + env: AUTOLOAD=1 + dist: precise + - php: 5.3 + env: AUTOLOAD=0 + dist: precise + - php: 5.4 + env: AUTOLOAD=1 + - php: 5.4 + env: AUTOLOAD=0 + - php: 5.5 + env: AUTOLOAD=1 + - php: 5.5 + env: AUTOLOAD=0 + - php: 5.6 + env: AUTOLOAD=1 + - php: 5.6 + env: AUTOLOAD=0 + - php: 7.0 + env: AUTOLOAD=1 + - php: 7.0 + env: AUTOLOAD=0 + - php: 7.1 + env: AUTOLOAD=1 + - php: 7.1 + env: AUTOLOAD=0 + - php: hhvm + env: AUTOLOAD=1 + - php: hhvm + env: AUTOLOAD=0 + +cache: + directories: + - $HOME/.composer/cache/files + +script: ./build.php ${AUTOLOAD} +after_script: ./vendor/bin/coveralls -v diff --git a/packages/stripe-php/CHANGELOG.md b/vendor/stripe/stripe-php/CHANGELOG.md similarity index 85% rename from packages/stripe-php/CHANGELOG.md rename to vendor/stripe/stripe-php/CHANGELOG.md index f1ef0b2e..6d174153 100644 --- a/packages/stripe-php/CHANGELOG.md +++ b/vendor/stripe/stripe-php/CHANGELOG.md @@ -1,3 +1,99 @@ +### 5.2.3 2017-09-27 + +* Add PHPDoc for `Card` + +### 5.2.2 2017-09-20 + +* Fix deserialization mapping of `FileUpload` objects + +### 5.2.1 2017-09-14 + +* Serialized `shipping` nested attribute + +### 5.2.0 2017-08-29 + +* Add support for `InvalidClient` OAuth error + +### 5.1.3 2017-08-14 + +* Allow `address_kana` and `address_kanji` to be updated for custom accounts + +### 5.1.2 2017-08-01 + +* Fix documented return type of `autoPagingIterator()` (was missing namespace) + +### 5.1.1 2017-07-03 + +* Fix order returns to use the right URL `/v1/order_returns` + +### 5.1.0 2017-06-30 + +* Add support for OAuth + +### 5.0.0 2017-06-27 + +* `pay` on invoice now takes params as well as opts + +### 4.13.0 2017-06-19 + +* Add support for ephemeral keys + +### 4.12.0 2017-06-05 + +* Clients can implement `getUserAgentInfo()` to add additional user agent information + +### 4.11.0 2017-06-05 + +* Implement `Countable` for `AttachedObject` (`metadata` and `additional_owners`) + +### 4.10.0 2017-05-25 + +* Add support for login links + +### 4.9.1 2017-05-10 + +* Fix docs to include arrays on `$id` parameter for retrieve methods + +### 4.9.0 2017-04-28 + +* Support for checking webhook signatures + +### 4.8.1 2017-04-24 + +* Allow nested field `payout_schedule` to be updated + +### 4.8.0 2017-04-20 + +* Add `\Stripe\Stripe::setLogger()` to support an external PSR-3 compatible logger + +### 4.7.0 2017-04-10 + +* Add support for payouts and recipient transfers + +### 4.6.0 2017-04-06 + +* Please see 4.7.0 instead (no-op release) + +### 4.5.1 2017-03-22 + +* Remove hard dependency on cURL + +### 4.5.0 2017-03-20 + +* Support for detaching sources from customers + +### 4.4.2 2017-02-27 + +* Correct handling of `owner` parameter when updating sources + +### 4.4.1 2017-02-24 + +* Correct the error check on a bad JSON decoding + +### 4.4.0 2017-01-18 + +* Add support for updating sources + ### 4.3.0 2016-11-30 * Add support for verifying sources diff --git a/packages/stripe-php/LICENSE b/vendor/stripe/stripe-php/LICENSE similarity index 100% rename from packages/stripe-php/LICENSE rename to vendor/stripe/stripe-php/LICENSE diff --git a/packages/stripe-php/README.md b/vendor/stripe/stripe-php/README.md similarity index 91% rename from packages/stripe-php/README.md rename to vendor/stripe/stripe-php/README.md index af40226a..009b5568 100644 --- a/packages/stripe-php/README.md +++ b/vendor/stripe/stripe-php/README.md @@ -49,9 +49,8 @@ If you use Composer, these dependencies should be handled automatically. If you Simple usage looks like: ```php -\Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249'); -$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018); -$charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd')); +\Stripe\Stripe::setApiKey('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); +$charge = \Stripe\Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => 'tok_189fqt2eZvKYlo2CTGBeg6Uq' )); echo $charge; ``` @@ -67,8 +66,7 @@ This legacy version may be included via `require_once("/path/to/stripe-php/lib/S ```php Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249'); -$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018); -$charge = Stripe_Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd')); +$charge = Stripe_Charge::create(array('source' => 'tok_XXXXXXXX', 'amount' => 2000, 'currency' => 'usd')); echo $charge; ``` @@ -106,9 +104,19 @@ $curl = new \Stripe\HttpClient\CurlClient(array(CURLOPT_PROXY => 'proxy.local:80 Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See `testDefaultOptions()` in `tests/CurlClientTest.php` for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent. +### Configuring a Logger + +The library does minimal logging, but it can be configured +with a [`PSR-3` compatible logger][psr3] so that messages +end up there instead of `error_log`: + +```php +\Stripe\Stripe::setLogger($logger); +``` + ### SSL / TLS compatibility issues -Stripe's API now requires that [all connections use TLS 1.2](https://stripe.com/blog/upgrading-tls). Some systems (most notably some older CentOS and RHEL versions) are capable of using TLS 1.2 but will use TLS 1.0 or 1.1 by default. In this case, you'd get an `invalid_request_error` with the following error message: "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.". +Stripe's API now requires that [all connections use TLS 1.2](https://stripe.com/blog/upgrading-tls). Some systems (most notably some older CentOS and RHEL versions) are capable of using TLS 1.2 but will use TLS 1.0 or 1.1 by default. In this case, you'd get an `invalid_request_error` with the following error message: "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at [https://stripe.com/blog/upgrading-tls](https://stripe.com/blog/upgrading-tls).". The recommended course of action is to [upgrade your cURL and OpenSSL packages](https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php) so that TLS 1.2 is used by default, but if that is not possible, you might be able to solve the issue by setting the `CURLOPT_SSLVERSION` option to either `CURL_SSLVERSION_TLSv1` or `CURL_SSLVERSION_TLSv1_2`: @@ -152,3 +160,5 @@ The method should be called once, before any request is sent to the API. The sec ### SSL / TLS configuration option See the "SSL / TLS compatibility issues" paragraph above for full context. If you want to ensure that your plugin can be used on all systems, you should add a configuration option to let your users choose between different values for `CURLOPT_SSLVERSION`: none (default), `CURL_SSLVERSION_TLSv1` and `CURL_SSLVERSION_TLSv1_2`. + +[psr3]: http://www.php-fig.org/psr/psr-3/ diff --git a/vendor/stripe/stripe-php/VERSION b/vendor/stripe/stripe-php/VERSION new file mode 100644 index 00000000..c0baecba --- /dev/null +++ b/vendor/stripe/stripe-php/VERSION @@ -0,0 +1 @@ +5.2.3 diff --git a/packages/stripe-php/build.php b/vendor/stripe/stripe-php/build.php similarity index 100% rename from packages/stripe-php/build.php rename to vendor/stripe/stripe-php/build.php diff --git a/packages/stripe-php/composer.json b/vendor/stripe/stripe-php/composer.json similarity index 100% rename from packages/stripe-php/composer.json rename to vendor/stripe/stripe-php/composer.json diff --git a/packages/stripe-php/data/ca-certificates.crt b/vendor/stripe/stripe-php/data/ca-certificates.crt similarity index 100% rename from packages/stripe-php/data/ca-certificates.crt rename to vendor/stripe/stripe-php/data/ca-certificates.crt diff --git a/packages/stripe-php/data/test.png b/vendor/stripe/stripe-php/data/test.png similarity index 100% rename from packages/stripe-php/data/test.png rename to vendor/stripe/stripe-php/data/test.png diff --git a/vendor/stripe/stripe-php/examples/oauth.php b/vendor/stripe/stripe-php/examples/oauth.php new file mode 100644 index 00000000..5018a633 --- /dev/null +++ b/vendor/stripe/stripe-php/examples/oauth.php @@ -0,0 +1,55 @@ +<?php + +require('../init.php'); + +\Stripe\Stripe::setApiKey(getenv('STRIPE_SECRET_KEY')); +\Stripe\Stripe::setClientId(getenv('STRIPE_CLIENT_ID')); + + +if (isset($_GET['code'])) { + // The user was redirected back from the OAuth form with an authorization code. + $code = $_GET['code']; + + try { + $resp = \Stripe\OAuth::token(array( + 'grant_type' => 'authorization_code', + 'code' => $code, + )); + } catch (\Stripe\Error\OAuth\OAuthBase $e) { + exit("Error: " . $e->getMessage()); + } + + $accountId = $resp->stripe_user_id; + + echo "<p>Success! Account <code>$accountId</code> is connected.</p>\n"; + echo "<p>Click <a href=\"?deauth=$accountId\">here</a> to disconnect the account.</p>\n"; + +} elseif (isset($_GET['error'])) { + // The user was redirect back from the OAuth form with an error. + $error = $_GET['error']; + $error_description = $_GET['error_description']; + + echo "<p>Error: code=$error, description=$error_description</p>\n"; + echo "<p>Click <a href=\"?\">here</a> to restart the OAuth flow.</p>\n"; + +} elseif (isset($_GET['deauth'])) { + // Deauthorization request + $accountId = $_GET['deauth']; + + try { + \Stripe\OAuth::deauthorize(array( + 'stripe_user_id' => $accountId, + )); + } catch (\Stripe\Error\OAuth\OAuthBase $e) { + exit("Error: " . $e->getMessage()); + } + + echo "<p>Success! Account <code>$accountId</code> is disonnected.</p>\n"; + echo "<p>Click <a href=\"?\">here</a> to restart the OAuth flow.</p>\n"; + +} else { + $url = \Stripe\OAuth::authorizeUrl(array( + 'scope' => 'read_only', + )); + echo "<a href=\"$url\">Connect with Stripe</a>\n"; +} diff --git a/packages/stripe-php/init.php b/vendor/stripe/stripe-php/init.php similarity index 74% rename from packages/stripe-php/init.php rename to vendor/stripe/stripe-php/init.php index 246dc364..cd2e023e 100644 --- a/packages/stripe-php/init.php +++ b/vendor/stripe/stripe-php/init.php @@ -5,6 +5,8 @@ require(dirname(__FILE__) . '/lib/Stripe.php'); // Utilities require(dirname(__FILE__) . '/lib/Util/AutoPagingIterator.php'); +require(dirname(__FILE__) . '/lib/Util/LoggerInterface.php'); +require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php'); require(dirname(__FILE__) . '/lib/Util/RequestOptions.php'); require(dirname(__FILE__) . '/lib/Util/Set.php'); require(dirname(__FILE__) . '/lib/Util/Util.php'); @@ -22,6 +24,16 @@ require(dirname(__FILE__) . '/lib/Error/Card.php'); require(dirname(__FILE__) . '/lib/Error/InvalidRequest.php'); require(dirname(__FILE__) . '/lib/Error/Permission.php'); require(dirname(__FILE__) . '/lib/Error/RateLimit.php'); +require(dirname(__FILE__) . '/lib/Error/SignatureVerification.php'); + +// OAuth errors +require(dirname(__FILE__) . '/lib/Error/OAuth/OAuthBase.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/InvalidClient.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/InvalidGrant.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/InvalidRequest.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/InvalidScope.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/UnsupportedGrantType.php'); +require(dirname(__FILE__) . '/lib/Error/OAuth/UnsupportedResponseType.php'); // Plumbing require(dirname(__FILE__) . '/lib/ApiResponse.php'); @@ -51,15 +63,19 @@ require(dirname(__FILE__) . '/lib/CountrySpec.php'); require(dirname(__FILE__) . '/lib/Coupon.php'); require(dirname(__FILE__) . '/lib/Customer.php'); require(dirname(__FILE__) . '/lib/Dispute.php'); +require(dirname(__FILE__) . '/lib/EphemeralKey.php'); require(dirname(__FILE__) . '/lib/Event.php'); require(dirname(__FILE__) . '/lib/FileUpload.php'); require(dirname(__FILE__) . '/lib/Invoice.php'); require(dirname(__FILE__) . '/lib/InvoiceItem.php'); +require(dirname(__FILE__) . '/lib/LoginLink.php'); require(dirname(__FILE__) . '/lib/Order.php'); require(dirname(__FILE__) . '/lib/OrderReturn.php'); +require(dirname(__FILE__) . '/lib/Payout.php'); require(dirname(__FILE__) . '/lib/Plan.php'); require(dirname(__FILE__) . '/lib/Product.php'); require(dirname(__FILE__) . '/lib/Recipient.php'); +require(dirname(__FILE__) . '/lib/RecipientTransfer.php'); require(dirname(__FILE__) . '/lib/Refund.php'); require(dirname(__FILE__) . '/lib/SKU.php'); require(dirname(__FILE__) . '/lib/Source.php'); @@ -69,3 +85,10 @@ require(dirname(__FILE__) . '/lib/ThreeDSecure.php'); require(dirname(__FILE__) . '/lib/Token.php'); require(dirname(__FILE__) . '/lib/Transfer.php'); require(dirname(__FILE__) . '/lib/TransferReversal.php'); + +// OAuth +require(dirname(__FILE__) . '/lib/OAuth.php'); + +// Webhooks +require(dirname(__FILE__) . '/lib/Webhook.php'); +require(dirname(__FILE__) . '/lib/WebhookSignature.php'); diff --git a/packages/stripe-php/lib/Account.php b/vendor/stripe/stripe-php/lib/Account.php similarity index 86% rename from packages/stripe-php/lib/Account.php rename to vendor/stripe/stripe-php/lib/Account.php index e46f42d6..da3f5b5f 100644 --- a/packages/stripe-php/lib/Account.php +++ b/vendor/stripe/stripe-php/lib/Account.php @@ -21,14 +21,15 @@ namespace Stripe; * @property mixed $external_accounts * @property mixed $legal_entity * @property bool $managed + * @property mixed $payout_schedule + * @property mixed $payout_statement_descriptor + * @property bool $payouts_enabled * @property mixed $product_description * @property mixed $statement_descriptor * @property mixed $support_email * @property mixed $support_phone * @property string $timezone * @property mixed $tos_acceptance - * @property mixed $transfer_schedule - * @property bool $transfers_enabled * @property mixed $verification * @property mixed $keys * @@ -46,7 +47,8 @@ class Account extends ApiResource } /** - * @param string|null $id + * @param array|string|null $id The ID of the account to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return Account @@ -128,4 +130,13 @@ class Account extends ApiResource { return self::_all($params, $opts); } + + public function deauthorize($clientId = null, $opts = null) + { + $params = array( + 'client_id' => $clientId, + 'stripe_user_id' => $this->id, + ); + OAuth::deauthorize($params, $opts); + } } diff --git a/packages/stripe-php/lib/AlipayAccount.php b/vendor/stripe/stripe-php/lib/AlipayAccount.php similarity index 100% rename from packages/stripe-php/lib/AlipayAccount.php rename to vendor/stripe/stripe-php/lib/AlipayAccount.php diff --git a/packages/stripe-php/lib/ApiRequestor.php b/vendor/stripe/stripe-php/lib/ApiRequestor.php similarity index 68% rename from packages/stripe-php/lib/ApiRequestor.php rename to vendor/stripe/stripe-php/lib/ApiRequestor.php index d47b1970..770a03f3 100644 --- a/packages/stripe-php/lib/ApiRequestor.php +++ b/vendor/stripe/stripe-php/lib/ApiRequestor.php @@ -84,7 +84,7 @@ class ApiRequestor * hitting the API. * @throws Error\Api otherwise. */ - public function handleApiError($rbody, $rcode, $rheaders, $resp) + public function handleErrorResponse($rbody, $rcode, $rheaders, $resp) { if (!is_array($resp) || !isset($resp['error'])) { $msg = "Invalid response object from API: $rbody " @@ -92,35 +92,71 @@ class ApiRequestor throw new Error\Api($msg, $rcode, $rbody, $resp, $rheaders); } - $error = $resp['error']; - $msg = isset($error['message']) ? $error['message'] : null; - $param = isset($error['param']) ? $error['param'] : null; - $code = isset($error['code']) ? $error['code'] : null; + $errorData = $resp['error']; + + $error = null; + if (is_string($errorData)) { + $error = self::_specificOAuthError($rbody, $rcode, $rheaders, $resp, $errorData); + } + if (!$error) { + $error = self::_specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData); + } + + throw $error; + } + + private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData) + { + $msg = isset($errorData['message']) ? $errorData['message'] : null; + $param = isset($errorData['param']) ? $errorData['param'] : null; + $code = isset($errorData['code']) ? $errorData['code'] : null; switch ($rcode) { case 400: // 'rate_limit' code is deprecated, but left here for backwards compatibility // for API versions earlier than 2015-09-08 if ($code == 'rate_limit') { - throw new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders); + return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders); } // intentional fall-through case 404: - throw new Error\InvalidRequest($msg, $param, $rcode, $rbody, $resp, $rheaders); + return new Error\InvalidRequest($msg, $param, $rcode, $rbody, $resp, $rheaders); case 401: - throw new Error\Authentication($msg, $rcode, $rbody, $resp, $rheaders); + return new Error\Authentication($msg, $rcode, $rbody, $resp, $rheaders); case 402: - throw new Error\Card($msg, $param, $code, $rcode, $rbody, $resp, $rheaders); + return new Error\Card($msg, $param, $code, $rcode, $rbody, $resp, $rheaders); case 403: - throw new Error\Permission($msg, $rcode, $rbody, $resp, $rheaders); + return new Error\Permission($msg, $rcode, $rbody, $resp, $rheaders); case 429: - throw new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders); + return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders); default: - throw new Error\Api($msg, $rcode, $rbody, $resp, $rheaders); + return new Error\Api($msg, $rcode, $rbody, $resp, $rheaders); } } + private static function _specificOAuthError($rbody, $rcode, $rheaders, $resp, $errorCode) + { + $description = isset($resp['error_description']) ? $resp['error_description'] : $errorCode; + + switch ($errorCode) { + case 'invalid_client': + return new Error\OAuth\InvalidClient($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + case 'invalid_grant': + return new Error\OAuth\InvalidGrant($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + case 'invalid_request': + return new Error\OAuth\InvalidRequest($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + case 'invalid_scope': + return new Error\OAuth\InvalidScope($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + case 'unsupported_grant_type': + return new Error\OAuth\UnsupportedGrantType($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + case 'unsupported_response_type': + return new Error\OAuth\UnsupportedResponseType($errorCode, $description, $rcode, $rbody, $resp, $rheaders); + } + + return null; + } + private static function _formatAppInfo($appInfo) { if ($appInfo !== null) { @@ -137,15 +173,13 @@ class ApiRequestor } } - private static function _defaultHeaders($apiKey) + private static function _defaultHeaders($apiKey, $clientInfo = null) { - $appInfo = Stripe::getAppInfo(); - $uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION; $langVersion = phpversion(); $uname = php_uname(); - $curlVersion = curl_version(); + $appInfo = Stripe::getAppInfo(); $ua = array( 'bindings_version' => Stripe::VERSION, @@ -153,9 +187,10 @@ class ApiRequestor 'lang_version' => $langVersion, 'publisher' => 'stripe', 'uname' => $uname, - 'httplib' => 'curl ' . $curlVersion['version'], - 'ssllib' => $curlVersion['ssl_version'], ); + if ($clientInfo) { + $ua = array_merge($clientInfo, $ua); + } if ($appInfo !== null) { $uaString .= ' ' . self::_formatAppInfo($appInfo); $ua['application'] = $appInfo; @@ -184,9 +219,17 @@ class ApiRequestor throw new Error\Authentication($msg); } + // Clients can supply arbitrary additional keys to be included in the + // X-Stripe-Client-User-Agent header via the optional getUserAgentInfo() + // method + $clientUAInfo = null; + if (method_exists($this->httpClient(), 'getUserAgentInfo')) { + $clientUAInfo = $this->httpClient()->getUserAgentInfo(); + } + $absUrl = $this->_apiBase.$url; $params = self::_encodeObjects($params); - $defaultHeaders = $this->_defaultHeaders($myApiKey); + $defaultHeaders = $this->_defaultHeaders($myApiKey, $clientUAInfo); if (Stripe::$apiVersion) { $defaultHeaders['Stripe-Version'] = Stripe::$apiVersion; } @@ -254,16 +297,16 @@ class ApiRequestor private function _interpretResponse($rbody, $rcode, $rheaders) { - try { - $resp = json_decode($rbody, true); - } catch (Exception $e) { + $resp = json_decode($rbody, true); + $jsonError = json_last_error(); + if ($resp === null && $jsonError !== JSON_ERROR_NONE) { $msg = "Invalid response body from API: $rbody " - . "(HTTP response code was $rcode)"; + . "(HTTP response code was $rcode, json_last_error() was $jsonError)"; throw new Error\Api($msg, $rcode, $rbody); } if ($rcode < 200 || $rcode >= 300) { - $this->handleApiError($rbody, $rcode, $rheaders, $resp); + $this->handleErrorResponse($rbody, $rcode, $rheaders, $resp); } return $resp; } diff --git a/packages/stripe-php/lib/ApiResource.php b/vendor/stripe/stripe-php/lib/ApiResource.php similarity index 95% rename from packages/stripe-php/lib/ApiResource.php rename to vendor/stripe/stripe-php/lib/ApiResource.php index f10b948f..95480711 100644 --- a/packages/stripe-php/lib/ApiResource.php +++ b/vendor/stripe/stripe-php/lib/ApiResource.php @@ -93,14 +93,13 @@ abstract class ApiResource extends StripeObject return static::resourceUrl($this['id']); } - private static function _validateParams($params = null) + protected static function _validateParams($params = null) { if ($params && !is_array($params)) { $message = "You must pass an array as the first argument to Stripe API " . "method calls. (HINT: an example call to create a charge " . "would be: \"Stripe\\Charge::create(array('amount' => 100, " - . "'currency' => 'usd', 'card' => array('number' => " - . "4242424242424242, 'exp_month' => 5, 'exp_year' => 2015)))\")"; + . "'currency' => 'usd', 'source' => 'tok_1234'))\")"; throw new Error\Api($message); } } @@ -154,7 +153,6 @@ abstract class ApiResource extends StripeObject protected static function _create($params = null, $options = null) { self::_validateParams($params); - $base = static::baseUrl(); $url = static::classUrl(); list($response, $opts) = static::_staticRequest('post', $url, $params, $options); @@ -173,7 +171,6 @@ abstract class ApiResource extends StripeObject protected static function _update($id, $params = null, $options = null) { self::_validateParams($params); - $base = static::baseUrl(); $url = static::resourceUrl($id); list($response, $opts) = static::_staticRequest('post', $url, $params, $options); diff --git a/packages/stripe-php/lib/ApiResponse.php b/vendor/stripe/stripe-php/lib/ApiResponse.php similarity index 100% rename from packages/stripe-php/lib/ApiResponse.php rename to vendor/stripe/stripe-php/lib/ApiResponse.php diff --git a/packages/stripe-php/lib/ApplePayDomain.php b/vendor/stripe/stripe-php/lib/ApplePayDomain.php similarity index 91% rename from packages/stripe-php/lib/ApplePayDomain.php rename to vendor/stripe/stripe-php/lib/ApplePayDomain.php index 8c522c8b..99beb703 100644 --- a/packages/stripe-php/lib/ApplePayDomain.php +++ b/vendor/stripe/stripe-php/lib/ApplePayDomain.php @@ -20,7 +20,8 @@ class ApplePayDomain extends ApiResource } /** - * @param string $id The ID of the domain to retrieve. + * @param array|string $id The ID of the domain to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return ApplePayDomain diff --git a/packages/stripe-php/lib/ApplicationFee.php b/vendor/stripe/stripe-php/lib/ApplicationFee.php similarity index 92% rename from packages/stripe-php/lib/ApplicationFee.php rename to vendor/stripe/stripe-php/lib/ApplicationFee.php index 8145541c..fb545320 100644 --- a/packages/stripe-php/lib/ApplicationFee.php +++ b/vendor/stripe/stripe-php/lib/ApplicationFee.php @@ -21,7 +21,8 @@ class ApplicationFee extends ApiResource } /** - * @param string $id The ID of the application fee to retrieve. + * @param array|string $id The ID of the application fee to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return ApplicationFee diff --git a/packages/stripe-php/lib/ApplicationFeeRefund.php b/vendor/stripe/stripe-php/lib/ApplicationFeeRefund.php similarity index 100% rename from packages/stripe-php/lib/ApplicationFeeRefund.php rename to vendor/stripe/stripe-php/lib/ApplicationFeeRefund.php diff --git a/packages/stripe-php/lib/AttachedObject.php b/vendor/stripe/stripe-php/lib/AttachedObject.php similarity index 68% rename from packages/stripe-php/lib/AttachedObject.php rename to vendor/stripe/stripe-php/lib/AttachedObject.php index 489517d6..6a895178 100644 --- a/packages/stripe-php/lib/AttachedObject.php +++ b/vendor/stripe/stripe-php/lib/AttachedObject.php @@ -2,6 +2,8 @@ namespace Stripe; +use Countable; + /** * Class AttachedObject * @@ -9,7 +11,7 @@ namespace Stripe; * * @package Stripe */ -class AttachedObject extends StripeObject +class AttachedObject extends StripeObject implements Countable { /** * Updates this object. @@ -28,4 +30,14 @@ class AttachedObject extends StripeObject $this->$k = $v; } } + + /** + * Counts the number of elements in the AttachedObject instance. + * + * @return int the number of elements + */ + public function count() + { + return count($this->_values); + } } diff --git a/packages/stripe-php/lib/Balance.php b/vendor/stripe/stripe-php/lib/Balance.php similarity index 100% rename from packages/stripe-php/lib/Balance.php rename to vendor/stripe/stripe-php/lib/Balance.php diff --git a/packages/stripe-php/lib/BalanceTransaction.php b/vendor/stripe/stripe-php/lib/BalanceTransaction.php similarity index 90% rename from packages/stripe-php/lib/BalanceTransaction.php rename to vendor/stripe/stripe-php/lib/BalanceTransaction.php index b84619ec..4799b69b 100644 --- a/packages/stripe-php/lib/BalanceTransaction.php +++ b/vendor/stripe/stripe-php/lib/BalanceTransaction.php @@ -34,7 +34,8 @@ class BalanceTransaction extends ApiResource } /** - * @param string $id The ID of the balance transaction to retrieve. + * @param array|string $id The ID of the balance transaction to retrieve, + * or an options array containing an `id` key. * @param array|string|null $opts * * @return BalanceTransaction diff --git a/packages/stripe-php/lib/BankAccount.php b/vendor/stripe/stripe-php/lib/BankAccount.php similarity index 100% rename from packages/stripe-php/lib/BankAccount.php rename to vendor/stripe/stripe-php/lib/BankAccount.php diff --git a/packages/stripe-php/lib/BitcoinReceiver.php b/vendor/stripe/stripe-php/lib/BitcoinReceiver.php similarity index 80% rename from packages/stripe-php/lib/BitcoinReceiver.php rename to vendor/stripe/stripe-php/lib/BitcoinReceiver.php index 3f2c835b..52bbed12 100644 --- a/packages/stripe-php/lib/BitcoinReceiver.php +++ b/vendor/stripe/stripe-php/lib/BitcoinReceiver.php @@ -4,14 +4,16 @@ namespace Stripe; /** * Class BitcoinReceiver - * - * @package Stripe + + * @deprecated Please use sources instead. */ class BitcoinReceiver extends ExternalAccount { /** * @return string The class URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. + * + * @deprecated Please use sources instead. */ public static function classUrl() { @@ -21,6 +23,8 @@ class BitcoinReceiver extends ExternalAccount /** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. + * + * @deprecated Please use sources instead. */ public function instanceUrl() { @@ -37,10 +41,13 @@ class BitcoinReceiver extends ExternalAccount } /** - * @param string $id The ID of the Bitcoin Receiver to retrieve. + * @param array|string $id The ID of the bitcoin receiver to retrieve, or + * an options array containing an `id` key. * @param array|string|null $opts * * @return BitcoinReceiver + * + * @deprecated Please use sources instead. */ public static function retrieve($id, $opts = null) { @@ -52,6 +59,8 @@ class BitcoinReceiver extends ExternalAccount * @param array|string|null $opts * * @return Collection of BitcoinReceivers + * + * @deprecated Please use sources instead. */ public static function all($params = null, $opts = null) { @@ -63,6 +72,8 @@ class BitcoinReceiver extends ExternalAccount * @param array|string|null $opts * * @return BitcoinReceiver The created Bitcoin Receiver item. + * + * @deprecated Please use sources instead. */ public static function create($params = null, $opts = null) { @@ -74,6 +85,8 @@ class BitcoinReceiver extends ExternalAccount * @param array|string|null $options * * @return BitcoinReceiver The refunded Bitcoin Receiver item. + * + * @deprecated Please use sources instead. */ public function refund($params = null, $options = null) { diff --git a/packages/stripe-php/lib/BitcoinTransaction.php b/vendor/stripe/stripe-php/lib/BitcoinTransaction.php similarity index 100% rename from packages/stripe-php/lib/BitcoinTransaction.php rename to vendor/stripe/stripe-php/lib/BitcoinTransaction.php diff --git a/vendor/stripe/stripe-php/lib/Card.php b/vendor/stripe/stripe-php/lib/Card.php new file mode 100644 index 00000000..01ad2784 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Card.php @@ -0,0 +1,37 @@ +<?php + +namespace Stripe; + +/** + * Class Card + * + * @property string $id + * @property string $object + * @property string $address_city + * @property string $address_country + * @property string $address_line1 + * @property string $address_line1_check + * @property string $address_line2 + * @property string $address_state + * @property string $address_zip + * @property string $address_zip_check + * @property string $brand + * @property string $country + * @property string $customer + * @property string $cvc_check + * @property string $dynamic_last4": null, + * @property int $exp_month + * @property int $exp_year + * @property string $fingerprint + * @property string $funding + * @property string $last4 + * @property mixed $metadata + * @property string $name + * @property string $tokenization_method + * + * @package Stripe + */ +class Card extends ExternalAccount +{ + +} diff --git a/packages/stripe-php/lib/Charge.php b/vendor/stripe/stripe-php/lib/Charge.php similarity index 96% rename from packages/stripe-php/lib/Charge.php rename to vendor/stripe/stripe-php/lib/Charge.php index a4ff4531..d3881c33 100644 --- a/packages/stripe-php/lib/Charge.php +++ b/vendor/stripe/stripe-php/lib/Charge.php @@ -17,7 +17,7 @@ namespace Stripe; * @property string $customer * @property mixed $description * @property mixed $destination - * @property mixed $dispute + * @property string|null $dispute * @property mixed $failure_code * @property mixed $failure_message * @property mixed $fraud_details @@ -41,7 +41,8 @@ namespace Stripe; class Charge extends ApiResource { /** - * @param string $id The ID of the charge to retrieve. + * @param array|string $id The ID of the charge to retrieve, or an options + * array containing an `id` key. * @param array|string|null $options * * @return Charge diff --git a/packages/stripe-php/lib/Collection.php b/vendor/stripe/stripe-php/lib/Collection.php similarity index 96% rename from packages/stripe-php/lib/Collection.php rename to vendor/stripe/stripe-php/lib/Collection.php index 0beb3a18..a46e09cf 100644 --- a/packages/stripe-php/lib/Collection.php +++ b/vendor/stripe/stripe-php/lib/Collection.php @@ -56,7 +56,7 @@ class Collection extends ApiResource } /** - * @return AutoPagingIterator An iterator that can be used to iterate + * @return Util\AutoPagingIterator An iterator that can be used to iterate * across all objects across all pages. As page boundaries are * encountered, the next page will be fetched automatically for * continued iteration. diff --git a/packages/stripe-php/lib/CountrySpec.php b/vendor/stripe/stripe-php/lib/CountrySpec.php similarity index 81% rename from packages/stripe-php/lib/CountrySpec.php rename to vendor/stripe/stripe-php/lib/CountrySpec.php index dabb88b4..81bf54b9 100644 --- a/packages/stripe-php/lib/CountrySpec.php +++ b/vendor/stripe/stripe-php/lib/CountrySpec.php @@ -21,7 +21,9 @@ class CountrySpec extends ApiResource } /** - * @param string $country The ISO country code of the country we retrieve the CountrySpec for. + * @param array|string $country The ISO country code of the country we + * retrieve the country specfication for, or an options array + * containing an `id` containing that code. * @param array|string|null $opts * * @return CountrySpec diff --git a/packages/stripe-php/lib/Coupon.php b/vendor/stripe/stripe-php/lib/Coupon.php similarity index 92% rename from packages/stripe-php/lib/Coupon.php rename to vendor/stripe/stripe-php/lib/Coupon.php index 079cc10b..803d7c81 100644 --- a/packages/stripe-php/lib/Coupon.php +++ b/vendor/stripe/stripe-php/lib/Coupon.php @@ -10,7 +10,8 @@ namespace Stripe; class Coupon extends ApiResource { /** - * @param string $id The ID of the coupon to retrieve. + * @param array|string $id The ID of the coupon to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Coupon diff --git a/packages/stripe-php/lib/Customer.php b/vendor/stripe/stripe-php/lib/Customer.php similarity index 97% rename from packages/stripe-php/lib/Customer.php rename to vendor/stripe/stripe-php/lib/Customer.php index 1dfbfc6a..9f928f2b 100644 --- a/packages/stripe-php/lib/Customer.php +++ b/vendor/stripe/stripe-php/lib/Customer.php @@ -27,7 +27,8 @@ namespace Stripe; class Customer extends ApiResource { /** - * @param string $id The ID of the customer to retrieve. + * @param array|string $id The ID of the customer to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return Customer diff --git a/packages/stripe-php/lib/Dispute.php b/vendor/stripe/stripe-php/lib/Dispute.php similarity index 94% rename from packages/stripe-php/lib/Dispute.php rename to vendor/stripe/stripe-php/lib/Dispute.php index ce70d499..3b7c8835 100644 --- a/packages/stripe-php/lib/Dispute.php +++ b/vendor/stripe/stripe-php/lib/Dispute.php @@ -25,7 +25,8 @@ namespace Stripe; class Dispute extends ApiResource { /** - * @param string $id The ID of the dispute to retrieve. + * @param array|string $id The ID of the dispute to retrieve, or an options + * array containing an `id` key. * @param array|string|null $options * * @return Dispute diff --git a/vendor/stripe/stripe-php/lib/EphemeralKey.php b/vendor/stripe/stripe-php/lib/EphemeralKey.php new file mode 100644 index 00000000..cd3afd13 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/EphemeralKey.php @@ -0,0 +1,55 @@ +<?php + +namespace Stripe; + +/** + * Class EphemeralKey + * + * @property string $id + * @property string $object + * @property int $created + * @property int $expires + * @property bool $livemode + * @property string $secret + * @property array $associated_objects + * + * @package Stripe + */ +class EphemeralKey extends ApiResource +{ + /** + * This is a special case because the ephemeral key endpoint has an + * underscore in it. The parent `className` function strips underscores. + * + * @return string The name of the class. + */ + public static function className() + { + return 'ephemeral_key'; + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return EphemeralKey The created key. + */ + public static function create($params = null, $opts = null) + { + if (!$opts['stripe_version']) { + throw new \InvalidArgumentException('stripe_version must be specified to create an ephemeral key'); + } + return self::_create($params, $opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return EphemeralKey The deleted key. + */ + public function delete($params = null, $opts = null) + { + return $this->_delete($params, $opts); + } +} diff --git a/packages/stripe-php/lib/Error/Api.php b/vendor/stripe/stripe-php/lib/Error/Api.php similarity index 100% rename from packages/stripe-php/lib/Error/Api.php rename to vendor/stripe/stripe-php/lib/Error/Api.php diff --git a/packages/stripe-php/lib/Error/ApiConnection.php b/vendor/stripe/stripe-php/lib/Error/ApiConnection.php similarity index 100% rename from packages/stripe-php/lib/Error/ApiConnection.php rename to vendor/stripe/stripe-php/lib/Error/ApiConnection.php diff --git a/packages/stripe-php/lib/Error/Authentication.php b/vendor/stripe/stripe-php/lib/Error/Authentication.php similarity index 100% rename from packages/stripe-php/lib/Error/Authentication.php rename to vendor/stripe/stripe-php/lib/Error/Authentication.php diff --git a/packages/stripe-php/lib/Error/Base.php b/vendor/stripe/stripe-php/lib/Error/Base.php similarity index 100% rename from packages/stripe-php/lib/Error/Base.php rename to vendor/stripe/stripe-php/lib/Error/Base.php diff --git a/packages/stripe-php/lib/Error/Card.php b/vendor/stripe/stripe-php/lib/Error/Card.php similarity index 100% rename from packages/stripe-php/lib/Error/Card.php rename to vendor/stripe/stripe-php/lib/Error/Card.php diff --git a/packages/stripe-php/lib/Error/InvalidRequest.php b/vendor/stripe/stripe-php/lib/Error/InvalidRequest.php similarity index 100% rename from packages/stripe-php/lib/Error/InvalidRequest.php rename to vendor/stripe/stripe-php/lib/Error/InvalidRequest.php diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidClient.php b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidClient.php new file mode 100644 index 00000000..b47346cd --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidClient.php @@ -0,0 +1,10 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * InvalidClient is raised when authentication fails. + */ +class InvalidClient extends OAuthBase +{ +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidGrant.php b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidGrant.php new file mode 100644 index 00000000..62df56c2 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidGrant.php @@ -0,0 +1,13 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * InvalidGrant is raised when a specified code doesn't exist, is + * expired, has been used, or doesn't belong to you; a refresh token doesn't + * exist, or doesn't belong to you; or if an API key's mode (live or test) + * doesn't match the mode of a code or refresh token. + */ +class InvalidGrant extends OAuthBase +{ +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidRequest.php b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidRequest.php new file mode 100644 index 00000000..7f0e8b4e --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidRequest.php @@ -0,0 +1,11 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * InvalidRequest is raised when a code, refresh token, or grant type + * parameter is not provided, but was required. + */ +class InvalidRequest extends OAuthBase +{ +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidScope.php b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidScope.php new file mode 100644 index 00000000..03cc67e6 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/InvalidScope.php @@ -0,0 +1,10 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * InvalidScope is raised when an invalid scope parameter is provided. + */ +class InvalidScope extends OAuthBase +{ +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/OAuthBase.php b/vendor/stripe/stripe-php/lib/Error/OAuth/OAuthBase.php new file mode 100644 index 00000000..2f172133 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/OAuthBase.php @@ -0,0 +1,23 @@ +<?php + +namespace Stripe\Error\OAuth; + +class OAuthBase extends \Stripe\Error\Base +{ + public function __construct( + $code, + $description, + $httpStatus = null, + $httpBody = null, + $jsonBody = null, + $httpHeaders = null + ) { + parent::__construct($description, $httpStatus, $httpBody, $jsonBody, $httpHeaders); + $this->code = $code; + } + + public function getErrorCode() + { + return $this->code; + } +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedGrantType.php b/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedGrantType.php new file mode 100644 index 00000000..421adc99 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedGrantType.php @@ -0,0 +1,11 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * UnsupportedGrantType is raised when an unuspported grant type + * parameter is specified. + */ +class UnsupportedGrantType extends OAuthBase +{ +} diff --git a/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedResponseType.php b/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedResponseType.php new file mode 100644 index 00000000..ed148789 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/OAuth/UnsupportedResponseType.php @@ -0,0 +1,11 @@ +<?php + +namespace Stripe\Error\OAuth; + +/** + * UnsupportedResponseType is raised when an unsupported response type + * parameter is specified. + */ +class UnsupportedResponseType extends OAuthBase +{ +} diff --git a/packages/stripe-php/lib/Error/Permission.php b/vendor/stripe/stripe-php/lib/Error/Permission.php similarity index 100% rename from packages/stripe-php/lib/Error/Permission.php rename to vendor/stripe/stripe-php/lib/Error/Permission.php diff --git a/packages/stripe-php/lib/Error/RateLimit.php b/vendor/stripe/stripe-php/lib/Error/RateLimit.php similarity index 100% rename from packages/stripe-php/lib/Error/RateLimit.php rename to vendor/stripe/stripe-php/lib/Error/RateLimit.php diff --git a/vendor/stripe/stripe-php/lib/Error/SignatureVerification.php b/vendor/stripe/stripe-php/lib/Error/SignatureVerification.php new file mode 100644 index 00000000..98ddd3b0 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Error/SignatureVerification.php @@ -0,0 +1,20 @@ +<?php + +namespace Stripe\Error; + +class SignatureVerification extends Base +{ + public function __construct( + $message, + $sigHeader, + $httpBody = null + ) { + parent::__construct($message, null, $httpBody, null, null); + $this->sigHeader = $sigHeader; + } + + public function getSigHeader() + { + return $this->sigHeader; + } +} diff --git a/packages/stripe-php/lib/Event.php b/vendor/stripe/stripe-php/lib/Event.php similarity index 87% rename from packages/stripe-php/lib/Event.php rename to vendor/stripe/stripe-php/lib/Event.php index 6a1ed6c4..06009f48 100644 --- a/packages/stripe-php/lib/Event.php +++ b/vendor/stripe/stripe-php/lib/Event.php @@ -20,7 +20,8 @@ namespace Stripe; class Event extends ApiResource { /** - * @param string $id The ID of the event to retrieve. + * @param array|string $id The ID of the event to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Event diff --git a/packages/stripe-php/lib/ExternalAccount.php b/vendor/stripe/stripe-php/lib/ExternalAccount.php similarity index 100% rename from packages/stripe-php/lib/ExternalAccount.php rename to vendor/stripe/stripe-php/lib/ExternalAccount.php diff --git a/packages/stripe-php/lib/FileUpload.php b/vendor/stripe/stripe-php/lib/FileUpload.php similarity index 90% rename from packages/stripe-php/lib/FileUpload.php rename to vendor/stripe/stripe-php/lib/FileUpload.php index 7dc98c78..cfd6fce5 100644 --- a/packages/stripe-php/lib/FileUpload.php +++ b/vendor/stripe/stripe-php/lib/FileUpload.php @@ -27,7 +27,8 @@ class FileUpload extends ApiResource } /** - * @param string $id The ID of the file upload to retrieve. + * @param array|string $id The ID of the file upload to retrieve, or an + * options array containing an `id key. * @param array|string|null $opts * * @return FileUpload diff --git a/packages/stripe-php/lib/HttpClient/ClientInterface.php b/vendor/stripe/stripe-php/lib/HttpClient/ClientInterface.php similarity index 91% rename from packages/stripe-php/lib/HttpClient/ClientInterface.php rename to vendor/stripe/stripe-php/lib/HttpClient/ClientInterface.php index dc4af5d1..559ae8ac 100644 --- a/packages/stripe-php/lib/HttpClient/ClientInterface.php +++ b/vendor/stripe/stripe-php/lib/HttpClient/ClientInterface.php @@ -11,7 +11,7 @@ interface ClientInterface * @param array $params KV pairs for parameters. Can be nested for arrays and hashes * @param boolean $hasFile Whether or not $params references a file (via an @ prefix or * CurlFile) - * @throws Error\Api & Error\ApiConnection + * @throws \Stripe\Error\Api & \Stripe\Error\ApiConnection * @return array($rawBody, $httpStatusCode, $httpHeader) */ public function request($method, $absUrl, $headers, $params, $hasFile); diff --git a/packages/stripe-php/lib/HttpClient/CurlClient.php b/vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php similarity index 87% rename from packages/stripe-php/lib/HttpClient/CurlClient.php rename to vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php index e070d324..1c7d3d89 100644 --- a/packages/stripe-php/lib/HttpClient/CurlClient.php +++ b/vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php @@ -36,6 +36,8 @@ class CurlClient implements ClientInterface protected $defaultOptions; + protected $userAgentInfo; + /** * CurlClient constructor. * @@ -52,6 +54,16 @@ class CurlClient implements ClientInterface public function __construct($defaultOptions = null) { $this->defaultOptions = $defaultOptions; + $this->initUserAgentInfo(); + } + + public function initUserAgentInfo() + { + $curlVersion = curl_version(); + $this->userAgentInfo = array( + 'httplib' => 'curl ' . $curlVersion['version'], + 'ssllib' => $curlVersion['ssl_version'], + ); } public function getDefaultOptions() @@ -59,6 +71,11 @@ class CurlClient implements ClientInterface return $this->defaultOptions; } + public function getUserAgentInfo() + { + return $this->userAgentInfo; + } + // USER DEFINED TIMEOUTS const DEFAULT_TIMEOUT = 80; @@ -114,16 +131,16 @@ class CurlClient implements ClientInterface } $opts[CURLOPT_HTTPGET] = 1; if (count($params) > 0) { - $encoded = self::encode($params); + $encoded = Util\Util::urlEncode($params); $absUrl = "$absUrl?$encoded"; } } elseif ($method == 'post') { $opts[CURLOPT_POST] = 1; - $opts[CURLOPT_POSTFIELDS] = $hasFile ? $params : self::encode($params); + $opts[CURLOPT_POSTFIELDS] = $hasFile ? $params : Util\Util::urlEncode($params); } elseif ($method == 'delete') { $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; if (count($params) > 0) { - $encoded = self::encode($params); + $encoded = Util\Util::urlEncode($params); $absUrl = "$absUrl?$encoded"; } } else { @@ -238,45 +255,4 @@ class CurlClient implements ClientInterface { return dirname(__FILE__) . '/../../data/ca-certificates.crt'; } - - /** - * @param array $arr An map of param keys to values. - * @param string|null $prefix - * - * Only public for testability, should not be called outside of CurlClient - * - * @return string A querystring, essentially. - */ - public static function encode($arr, $prefix = null) - { - if (!is_array($arr)) { - return $arr; - } - - $r = array(); - foreach ($arr as $k => $v) { - if (is_null($v)) { - continue; - } - - if ($prefix) { - if ($k !== null && (!is_int($k) || is_array($v))) { - $k = $prefix."[".$k."]"; - } else { - $k = $prefix."[]"; - } - } - - if (is_array($v)) { - $enc = self::encode($v, $k); - if ($enc) { - $r[] = $enc; - } - } else { - $r[] = urlencode($k)."=".urlencode($v); - } - } - - return implode("&", $r); - } } diff --git a/packages/stripe-php/lib/Invoice.php b/vendor/stripe/stripe-php/lib/Invoice.php similarity index 88% rename from packages/stripe-php/lib/Invoice.php rename to vendor/stripe/stripe-php/lib/Invoice.php index e994566c..f4161a7b 100644 --- a/packages/stripe-php/lib/Invoice.php +++ b/vendor/stripe/stripe-php/lib/Invoice.php @@ -21,7 +21,8 @@ class Invoice extends ApiResource } /** - * @param string $id The ID of the invoice to retrieve. + * @param array|string $id The ID of the invoice to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Invoice @@ -82,10 +83,10 @@ class Invoice extends ApiResource /** * @return Invoice The paid invoice. */ - public function pay($opts = null) + public function pay($params = null, $opts = null) { $url = $this->instanceUrl() . '/pay'; - list($response, $opts) = $this->_request('post', $url, null, $opts); + list($response, $opts) = $this->_request('post', $url, $params, $opts); $this->refreshFrom($response, $opts); return $this; } diff --git a/packages/stripe-php/lib/InvoiceItem.php b/vendor/stripe/stripe-php/lib/InvoiceItem.php similarity index 92% rename from packages/stripe-php/lib/InvoiceItem.php rename to vendor/stripe/stripe-php/lib/InvoiceItem.php index ab9c4ba3..22f1cc07 100644 --- a/packages/stripe-php/lib/InvoiceItem.php +++ b/vendor/stripe/stripe-php/lib/InvoiceItem.php @@ -10,7 +10,8 @@ namespace Stripe; class InvoiceItem extends ApiResource { /** - * @param string $id The ID of the invoice item to retrieve. + * @param array|string $id The ID of the invoice item to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return InvoiceItem diff --git a/packages/stripe-php/lib/JsonSerializable.php b/vendor/stripe/stripe-php/lib/JsonSerializable.php similarity index 100% rename from packages/stripe-php/lib/JsonSerializable.php rename to vendor/stripe/stripe-php/lib/JsonSerializable.php diff --git a/packages/stripe-php/lib/Card.php b/vendor/stripe/stripe-php/lib/LoginLink.php similarity index 52% rename from packages/stripe-php/lib/Card.php rename to vendor/stripe/stripe-php/lib/LoginLink.php index 227bee13..7f01ae20 100644 --- a/packages/stripe-php/lib/Card.php +++ b/vendor/stripe/stripe-php/lib/LoginLink.php @@ -3,11 +3,11 @@ namespace Stripe; /** - * Class Card + * Class LoginLink * * @package Stripe */ -class Card extends ExternalAccount +class LoginLink extends ApiResource { } diff --git a/vendor/stripe/stripe-php/lib/OAuth.php b/vendor/stripe/stripe-php/lib/OAuth.php new file mode 100644 index 00000000..b2bd43da --- /dev/null +++ b/vendor/stripe/stripe-php/lib/OAuth.php @@ -0,0 +1,98 @@ +<?php + +namespace Stripe; + +abstract class OAuth +{ + /** + * Generates a URL to Stripe's OAuth form. + * + * @param array|null $params + * @param array|null $opts + * + * @return string The URL to Stripe's OAuth form. + */ + public static function authorizeUrl($params = null, $opts = null) + { + if (!$params) { + $params = array(); + } + + $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; + + $params['client_id'] = self::_getClientId($params); + if (!array_key_exists('response_type', $params)) { + $params['response_type'] = 'code'; + } + $query = Util\Util::urlEncode($params); + + return $base . '/oauth/authorize?' . $query; + } + + /** + * Use an authoriztion code to connect an account to your platform and + * fetch the user's credentials. + * + * @param array|null $params + * @param array|null $opts + * + * @return StripeObject Object containing the response from the API. + */ + public static function token($params = null, $opts = null) + { + $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; + $requestor = new ApiRequestor(null, $base); + list($response, $apiKey) = $requestor->request( + 'post', + '/oauth/token', + $params, + null + ); + return Util\Util::convertToStripeObject($response->json, $opts); + } + + /** + * Disconnects an account from your platform. + * + * @param array|null $params + * @param array|null $opts + * + * @return StripeObject Object containing the response from the API. + */ + public static function deauthorize($params = null, $opts = null) + { + if (!$params) { + $params = array(); + } + + $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; + $requestor = new ApiRequestor(null, $base); + $params['client_id'] = self::_getClientId($params); + list($response, $apiKey) = $requestor->request( + 'post', + '/oauth/deauthorize', + $params, + null + ); + return Util\Util::convertToStripeObject($response->json, $opts); + } + + private static function _getClientId($params = null) + { + $clientId = ($params && array_key_exists('client_id', $params)) ? $params['client_id'] : null; + if ($clientId === null) { + $clientId = Stripe::getClientId(); + } + if ($clientId === null) { + $msg = 'No client_id provided. (HINT: set your client_id using ' + . '"Stripe::setClientId(<CLIENT-ID>)". You can find your client_ids ' + . 'in your Stripe dashboard at ' + . 'https://dashboard.stripe.com/account/applications/settings, ' + . 'after registering your account as a platform. See ' + . 'https://stripe.com/docs/connect/standard-accounts for details, ' + . 'or email support@stripe.com if you have any questions.'; + throw new Error\Authentication($msg); + } + return $clientId; + } +} diff --git a/packages/stripe-php/lib/Order.php b/vendor/stripe/stripe-php/lib/Order.php similarity index 94% rename from packages/stripe-php/lib/Order.php rename to vendor/stripe/stripe-php/lib/Order.php index 9fc65e2e..58a7ee2d 100644 --- a/packages/stripe-php/lib/Order.php +++ b/vendor/stripe/stripe-php/lib/Order.php @@ -10,7 +10,8 @@ namespace Stripe; class Order extends ApiResource { /** - * @param string $id The ID of the Order to retrieve. + * @param array|string $id The ID of the order to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Order diff --git a/packages/stripe-php/lib/OrderReturn.php b/vendor/stripe/stripe-php/lib/OrderReturn.php similarity index 56% rename from packages/stripe-php/lib/OrderReturn.php rename to vendor/stripe/stripe-php/lib/OrderReturn.php index aa7fd4e9..551cb75c 100644 --- a/packages/stripe-php/lib/OrderReturn.php +++ b/vendor/stripe/stripe-php/lib/OrderReturn.php @@ -10,7 +10,19 @@ namespace Stripe; class OrderReturn extends ApiResource { /** - * @param string $id The ID of the OrderReturn to retrieve. + * This is a special case because the order returns endpoint has an + * underscore in it. The parent `className` function strips underscores. + * + * @return string The name of the class. + */ + public static function className() + { + return 'order_return'; + } + + /** + * @param array|string $id The ID of the order return to retrieve, or an + * options array containing an `id` field. * @param array|string|null $opts * * @return Order diff --git a/vendor/stripe/stripe-php/lib/Payout.php b/vendor/stripe/stripe-php/lib/Payout.php new file mode 100644 index 00000000..9a0eb183 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Payout.php @@ -0,0 +1,98 @@ +<?php + +namespace Stripe; + +/** + * Class Payout + * + * @property string $id + * @property string $object + * @property int $amount + * @property string $balance_transaction + * @property string $cancellation_balance_transaction + * @property int $created + * @property string $currency + * @property int $arrival_date + * @property string $destination + * @property string $failure_code + * @property string $failure_message + * @property bool $livemode + * @property mixed $metadata + * @property string $method + * @property string $recipient + * @property string $source_type + * @property string $statement_descriptor + * @property string $status + * @property string $type + * + * @package Stripe + */ +class Payout extends ApiResource +{ + /** + * @param array|string $id The ID of the payout to retrieve, or an options + * array containing an `id` key. + * @param array|string|null $opts + * + * @return Payout + */ + public static function retrieve($id, $opts = null) + { + return self::_retrieve($id, $opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return Collection of Payouts + */ + public static function all($params = null, $opts = null) + { + return self::_all($params, $opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return Payout The created payout. + */ + public static function create($params = null, $opts = null) + { + return self::_create($params, $opts); + } + + /** + * @param string $id The ID of the payout to update. + * @param array|null $params + * @param array|string|null $options + * + * @return Payout The updated payout. + */ + public static function update($id, $params = null, $options = null) + { + return self::_update($id, $params, $options); + } + + /** + * @return Payout The canceled payout. + */ + public function cancel() + { + $url = $this->instanceUrl() . '/cancel'; + list($response, $opts) = $this->_request('post', $url); + $this->refreshFrom($response, $opts); + return $this; + } + + /** + * @param array|string|null $opts + * + * @return Payout The saved payout. + */ + public function save($opts = null) + { + return $this->_save($opts); + } +} diff --git a/packages/stripe-php/lib/Plan.php b/vendor/stripe/stripe-php/lib/Plan.php similarity index 94% rename from packages/stripe-php/lib/Plan.php rename to vendor/stripe/stripe-php/lib/Plan.php index b911e17c..dcfffbf3 100644 --- a/packages/stripe-php/lib/Plan.php +++ b/vendor/stripe/stripe-php/lib/Plan.php @@ -23,7 +23,8 @@ namespace Stripe; class Plan extends ApiResource { /** - * @param string $id The ID of the plan to retrieve. + * @param array|string $id The ID of the plan to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Plan diff --git a/packages/stripe-php/lib/Product.php b/vendor/stripe/stripe-php/lib/Product.php similarity index 92% rename from packages/stripe-php/lib/Product.php rename to vendor/stripe/stripe-php/lib/Product.php index 2fdd22a0..1f8d2995 100644 --- a/packages/stripe-php/lib/Product.php +++ b/vendor/stripe/stripe-php/lib/Product.php @@ -10,7 +10,8 @@ namespace Stripe; class Product extends ApiResource { /** - * @param string $id The ID of the Product to retrieve. + * @param array|string $id The ID of the product to retrieve, or an options + * array contianing an `id` key. * @param array|string|null $opts * * @return Product diff --git a/packages/stripe-php/lib/Recipient.php b/vendor/stripe/stripe-php/lib/Recipient.php similarity index 94% rename from packages/stripe-php/lib/Recipient.php rename to vendor/stripe/stripe-php/lib/Recipient.php index 04bcb7bb..ca2b2cab 100644 --- a/packages/stripe-php/lib/Recipient.php +++ b/vendor/stripe/stripe-php/lib/Recipient.php @@ -10,7 +10,8 @@ namespace Stripe; class Recipient extends ApiResource { /** - * @param string $id The ID of the recipient to retrieve. + * @param array|string $id The ID of the recipient to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return Recipient diff --git a/vendor/stripe/stripe-php/lib/RecipientTransfer.php b/vendor/stripe/stripe-php/lib/RecipientTransfer.php new file mode 100644 index 00000000..f4e46db3 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/RecipientTransfer.php @@ -0,0 +1,38 @@ +<?php + +namespace Stripe; + +/** + * Class RecipientTransfer + * + * @property string $id + * @property string $object + * @property int $amount + * @property int $amount_reversed + * @property string $balance_transaction + * @property string $bank_account + * @property string $card + * @property int $created + * @property string $currency + * @property int $date + * @property string $description + * @property string $destination + * @property string $failure_code + * @property string $failure_message + * @property bool $livemode + * @property mixed $metadata + * @property string $method + * @property string $recipient + * @property mixed $reversals + * @property bool $reversed + * @property string $source_type + * @property string $statement_descriptor + * @property string $status + * @property string $type + * + * @package Stripe + */ +class RecipientTransfer extends ApiResource +{ + +} diff --git a/packages/stripe-php/lib/Refund.php b/vendor/stripe/stripe-php/lib/Refund.php similarity index 93% rename from packages/stripe-php/lib/Refund.php rename to vendor/stripe/stripe-php/lib/Refund.php index b4e0e76a..62ce8c92 100644 --- a/packages/stripe-php/lib/Refund.php +++ b/vendor/stripe/stripe-php/lib/Refund.php @@ -23,7 +23,8 @@ class Refund extends ApiResource { /** - * @param string $id The ID of the refund to retrieve. + * @param array|string $id The ID of the refund to retrieve, or an options + * array containing an `id` key. * @param array|string|null $options * * @return Refund diff --git a/packages/stripe-php/lib/SKU.php b/vendor/stripe/stripe-php/lib/SKU.php similarity index 92% rename from packages/stripe-php/lib/SKU.php rename to vendor/stripe/stripe-php/lib/SKU.php index 7089604e..19d27eac 100644 --- a/packages/stripe-php/lib/SKU.php +++ b/vendor/stripe/stripe-php/lib/SKU.php @@ -10,7 +10,8 @@ namespace Stripe; class SKU extends ApiResource { /** - * @param string $id The ID of the SKU to retrieve. + * @param array|string $id The ID of the SKU to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return SKU diff --git a/packages/stripe-php/lib/SingletonApiResource.php b/vendor/stripe/stripe-php/lib/SingletonApiResource.php similarity index 100% rename from packages/stripe-php/lib/SingletonApiResource.php rename to vendor/stripe/stripe-php/lib/SingletonApiResource.php diff --git a/vendor/stripe/stripe-php/lib/Source.php b/vendor/stripe/stripe-php/lib/Source.php new file mode 100644 index 00000000..24971373 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Source.php @@ -0,0 +1,116 @@ +<?php + +namespace Stripe; + +/** + * Class Source + * + * @package Stripe + */ +class Source extends ApiResource +{ + /** + * @param array|string $id The ID of the source to retrieve, or an options + * array containing an `id` key. + * @param array|string|null $opts + * + * @return Source + */ + public static function retrieve($id, $opts = null) + { + return self::_retrieve($id, $opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return Collection of Sources + */ + public static function all($params = null, $opts = null) + { + return self::_all($params, $opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return Source The created Source. + */ + public static function create($params = null, $opts = null) + { + return self::_create($params, $opts); + } + + /** + * @param string $id The ID of the source to update. + * @param array|null $params + * @param array|string|null $options + * + * @return Source The updated source. + */ + public static function update($id, $params = null, $options = null) + { + return self::_update($id, $params, $options); + } + + /** + * @param array|string|null $opts + * + * @return Source The saved source. + */ + public function save($opts = null) + { + return $this->_save($opts); + } + + /** + * @param array|null $params + * @param array|string|null $opts + * + * @return Source The deleted source. + */ + public function delete($params = null, $options = null) + { + self::_validateParams($params); + + $id = $this['id']; + if (!$id) { + $class = get_class($this); + $msg = "Could not determine which URL to request: $class instance " + . "has invalid ID: $id"; + throw new Error\InvalidRequest($msg, null); + } + + if ($this['customer']) { + $base = Customer::classUrl(); + $parentExtn = urlencode(Util\Util::utf8($this['customer'])); + $extn = urlencode(Util\Util::utf8($id)); + $url = "$base/$parentExtn/sources/$extn"; + + list($response, $opts) = $this->_request('delete', $url, $params, $options); + $this->refreshFrom($response, $opts); + return $this; + } else { + $message = "Source objects cannot be deleted, they can only be " + . "detached from customer objects. This source object does not " + . "appear to be currently attached to a customer object."; + throw new Error\Api($message); + } + } + + /** + * @param array|null $params + * @param array|string|null $options + * + * @return BankAccount The verified bank account. + */ + public function verify($params = null, $options = null) + { + $url = $this->instanceUrl() . '/verify'; + list($response, $opts) = $this->_request('post', $url, $params, $options); + $this->refreshFrom($response, $opts); + return $this; + } +} diff --git a/packages/stripe-php/lib/Stripe.php b/vendor/stripe/stripe-php/lib/Stripe.php similarity index 69% rename from packages/stripe-php/lib/Stripe.php rename to vendor/stripe/stripe-php/lib/Stripe.php index e54af9f7..26ba4550 100644 --- a/packages/stripe-php/lib/Stripe.php +++ b/vendor/stripe/stripe-php/lib/Stripe.php @@ -12,9 +12,15 @@ class Stripe // @var string The Stripe API key to be used for requests. public static $apiKey; + // @var string The Stripe client_id to be used for Connect requests. + public static $clientId; + // @var string The base URL for the Stripe API. public static $apiBase = 'https://api.stripe.com'; + // @var string The base URL for the OAuth API. + public static $connectBase = 'https://connect.stripe.com'; + // @var string The base URL for the Stripe API uploads endpoint. public static $apiUploadBase = 'https://uploads.stripe.com'; @@ -30,7 +36,11 @@ class Stripe // @var array The application's information (name, version, URL) public static $appInfo = null; - const VERSION = '4.3.0'; + // @var Util\LoggerInterface|null The logger to which the library will + // produce messages. + public static $logger = null; + + const VERSION = '5.2.3'; /** * @return string The API key used for requests. @@ -40,6 +50,35 @@ class Stripe return self::$apiKey; } + /** + * @return string The client_id used for Connect requests. + */ + public static function getClientId() + { + return self::$clientId; + } + + /** + * @return Util\LoggerInterface The logger to which the library will + * produce messages. + */ + public static function getLogger() + { + if (self::$logger == null) { + return new Util\DefaultLogger(); + } + return self::$logger; + } + + /** + * @param Util\LoggerInterface $logger The logger to which the library + * will produce messages. + */ + public static function setLogger($logger) + { + self::$logger = $logger; + } + /** * Sets the API key to be used for requests. * @@ -50,6 +89,16 @@ class Stripe self::$apiKey = $apiKey; } + /** + * Sets the client_id to be used for Connect requests. + * + * @param string $clientId + */ + public static function setClientId($clientId) + { + self::$clientId = $clientId; + } + /** * @return string The API version used for requests. null if we're using the * latest version. diff --git a/packages/stripe-php/lib/StripeObject.php b/vendor/stripe/stripe-php/lib/StripeObject.php similarity index 95% rename from packages/stripe-php/lib/StripeObject.php rename to vendor/stripe/stripe-php/lib/StripeObject.php index 9fd96e9f..33a4b1d6 100644 --- a/packages/stripe-php/lib/StripeObject.php +++ b/vendor/stripe/stripe-php/lib/StripeObject.php @@ -27,11 +27,12 @@ class StripeObject implements ArrayAccess, JsonSerializable { self::$permanentAttributes = new Util\Set(array('_opts', 'id')); self::$nestedUpdatableAttributes = new Util\Set(array( - 'metadata', 'legal_entity', 'address', 'dob', 'transfer_schedule', 'verification', - 'tos_acceptance', 'personal_address', + 'metadata', 'legal_entity', 'address', 'dob', 'payout_schedule', 'transfer_schedule', 'verification', + 'tos_acceptance', 'personal_address', 'address_kana', 'address_kanji', 'shipping', // will make the array into an AttachedObject: weird, but works for now 'additional_owners', 0, 1, 2, 3, 4, // Max 3, but leave the 4th so errors work properly - 'inventory' + 'inventory', + 'owner', )); } @@ -130,11 +131,11 @@ class StripeObject implements ArrayAccess, JsonSerializable . "with the result returned by Stripe's API, " . "probably as a result of a save(). The attributes currently " . "available on this object are: $attrs"; - error_log($message); + Stripe::getLogger()->error($message); return $nullval; } else { $class = get_class($this); - error_log("Stripe Notice: Undefined property of $class instance: $k"); + Stripe::getLogger()->error("Stripe Notice: Undefined property of $class instance: $k"); return $nullval; } } diff --git a/packages/stripe-php/lib/Subscription.php b/vendor/stripe/stripe-php/lib/Subscription.php similarity index 94% rename from packages/stripe-php/lib/Subscription.php rename to vendor/stripe/stripe-php/lib/Subscription.php index a95ab091..c7263926 100644 --- a/packages/stripe-php/lib/Subscription.php +++ b/vendor/stripe/stripe-php/lib/Subscription.php @@ -21,7 +21,8 @@ class Subscription extends ApiResource const STATUS_UNPAID = 'unpaid'; /** - * @param string $id The ID of the subscription to retrieve. + * @param array|string $id The ID of the subscription to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return Subscription diff --git a/packages/stripe-php/lib/SubscriptionItem.php b/vendor/stripe/stripe-php/lib/SubscriptionItem.php similarity index 93% rename from packages/stripe-php/lib/SubscriptionItem.php rename to vendor/stripe/stripe-php/lib/SubscriptionItem.php index 947d83fc..98b1f919 100644 --- a/packages/stripe-php/lib/SubscriptionItem.php +++ b/vendor/stripe/stripe-php/lib/SubscriptionItem.php @@ -21,7 +21,8 @@ class SubscriptionItem extends ApiResource } /** - * @param string $id The ID of the subscription item to retrieve. + * @param array|string $id The ID of the subscription item to retrieve, or + * an options array containing an `id` key. * @param array|string|null $opts * * @return SubscriptionItem diff --git a/packages/stripe-php/lib/ThreeDSecure.php b/vendor/stripe/stripe-php/lib/ThreeDSecure.php similarity index 85% rename from packages/stripe-php/lib/ThreeDSecure.php rename to vendor/stripe/stripe-php/lib/ThreeDSecure.php index 1f189b7d..11eb2f65 100644 --- a/packages/stripe-php/lib/ThreeDSecure.php +++ b/vendor/stripe/stripe-php/lib/ThreeDSecure.php @@ -13,7 +13,8 @@ class ThreeDSecure extends ApiResource } /** - * @param string $id The ID of the 3DS auth to retrieve. + * @param array|string $id The ID of the 3DS auth to retrieve, or an + * options array contianing an `id` key. * @param array|string|null $options * * @return ThreeDSecure diff --git a/packages/stripe-php/lib/Token.php b/vendor/stripe/stripe-php/lib/Token.php similarity index 87% rename from packages/stripe-php/lib/Token.php rename to vendor/stripe/stripe-php/lib/Token.php index d3e5a4bc..93ad748d 100644 --- a/packages/stripe-php/lib/Token.php +++ b/vendor/stripe/stripe-php/lib/Token.php @@ -20,7 +20,8 @@ namespace Stripe; class Token extends ApiResource { /** - * @param string $id The ID of the token to retrieve. + * @param array|string $id The ID of the token to retrieve, or an options + * array containing an `id` key. * @param array|string|null $opts * * @return Token diff --git a/packages/stripe-php/lib/Transfer.php b/vendor/stripe/stripe-php/lib/Transfer.php similarity index 85% rename from packages/stripe-php/lib/Transfer.php rename to vendor/stripe/stripe-php/lib/Transfer.php index 0feae172..24a626ab 100644 --- a/packages/stripe-php/lib/Transfer.php +++ b/vendor/stripe/stripe-php/lib/Transfer.php @@ -9,35 +9,25 @@ namespace Stripe; * @property string $object * @property int $amount * @property int $amount_reversed - * @property mixed $application_fee * @property string $balance_transaction * @property int $created * @property string $currency * @property int $date - * @property mixed $description * @property mixed $destination * @property mixed $destination_payment - * @property mixed $failure_code - * @property mixed $failure_message - * @property mixed $fraud_details - * @property mixed $invoice * @property bool $livemode * @property mixed $metadata - * @property mixed $recipient * @property mixed $reversals * @property bool $reversed * @property mixed $source_transaction - * @property string $source_type - * @property mixed $statement_descriptor - * @property string $status - * @property string $type * * @package Stripe */ class Transfer extends ApiResource { /** - * @param string $id The ID of the transfer to retrieve. + * @param array|string $id The ID of the transfer to retrieve, or an + * options array containing an `id` key. * @param array|string|null $opts * * @return Transfer diff --git a/packages/stripe-php/lib/TransferReversal.php b/vendor/stripe/stripe-php/lib/TransferReversal.php similarity index 100% rename from packages/stripe-php/lib/TransferReversal.php rename to vendor/stripe/stripe-php/lib/TransferReversal.php diff --git a/packages/stripe-php/lib/Util/AutoPagingIterator.php b/vendor/stripe/stripe-php/lib/Util/AutoPagingIterator.php similarity index 100% rename from packages/stripe-php/lib/Util/AutoPagingIterator.php rename to vendor/stripe/stripe-php/lib/Util/AutoPagingIterator.php diff --git a/vendor/stripe/stripe-php/lib/Util/DefaultLogger.php b/vendor/stripe/stripe-php/lib/Util/DefaultLogger.php new file mode 100644 index 00000000..d9cf03b5 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Util/DefaultLogger.php @@ -0,0 +1,18 @@ +<?php + +namespace Stripe\Util; + +/** + * A very basic implementation of LoggerInterface that has just enough + * functionality that it can be the default for this library. + */ +class DefaultLogger implements LoggerInterface +{ + public function error($message, array $context = array()) + { + if (count($context) > 0) { + throw new Exception('DefaultLogger does not currently implement context. Please implement if you need it.'); + } + error_log($message); + } +} diff --git a/vendor/stripe/stripe-php/lib/Util/LoggerInterface.php b/vendor/stripe/stripe-php/lib/Util/LoggerInterface.php new file mode 100644 index 00000000..a72d8e84 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Util/LoggerInterface.php @@ -0,0 +1,36 @@ +<?php + +namespace Stripe\Util; + +/** + * Describes a logger instance. + * + * This is a subset of the interface of the same name in the PSR-3 logger + * interface. We guarantee to keep it compatible, but we'd redefined it here so + * that we don't have to pull in the extra dependencies for users who don't want + * it. + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md + * for the full interface specification. + * + * The message MUST be a string or object implementing __toString(). + * + * The message MAY contain placeholders in the form: {foo} where foo + * will be replaced by the context data in key "foo". + * + * The context array can contain arbitrary data, the only assumption that + * can be made by implementors is that if an Exception instance is given + * to produce a stack trace, it MUST be in a key named "exception". + */ +interface LoggerInterface +{ + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * @return null + */ + public function error($message, array $context = array()); +} diff --git a/packages/stripe-php/lib/Util/RequestOptions.php b/vendor/stripe/stripe-php/lib/Util/RequestOptions.php similarity index 100% rename from packages/stripe-php/lib/Util/RequestOptions.php rename to vendor/stripe/stripe-php/lib/Util/RequestOptions.php diff --git a/packages/stripe-php/lib/Util/Set.php b/vendor/stripe/stripe-php/lib/Util/Set.php similarity index 100% rename from packages/stripe-php/lib/Util/Set.php rename to vendor/stripe/stripe-php/lib/Util/Set.php diff --git a/packages/stripe-php/lib/Util/Util.php b/vendor/stripe/stripe-php/lib/Util/Util.php similarity index 69% rename from packages/stripe-php/lib/Util/Util.php rename to vendor/stripe/stripe-php/lib/Util/Util.php index fe229758..6eec773e 100644 --- a/packages/stripe-php/lib/Util/Util.php +++ b/vendor/stripe/stripe-php/lib/Util/Util.php @@ -7,6 +7,7 @@ use Stripe\StripeObject; abstract class Util { private static $isMbstringAvailable = null; + private static $isHashEqualsAvailable = null; /** * Whether the provided array (or other) is a list rather than a dictionary. @@ -75,19 +76,23 @@ abstract class Util 'coupon' => 'Stripe\\Coupon', 'customer' => 'Stripe\\Customer', 'dispute' => 'Stripe\\Dispute', + 'ephemeral_key' => 'Stripe\\EphemeralKey', 'list' => 'Stripe\\Collection', + 'login_link' => 'Stripe\\LoginLink', 'invoice' => 'Stripe\\Invoice', 'invoiceitem' => 'Stripe\\InvoiceItem', 'event' => 'Stripe\\Event', - 'file' => 'Stripe\\FileUpload', + 'file_upload' => 'Stripe\\FileUpload', 'token' => 'Stripe\\Token', 'transfer' => 'Stripe\\Transfer', 'transfer_reversal' => 'Stripe\\TransferReversal', 'order' => 'Stripe\\Order', 'order_return' => 'Stripe\\OrderReturn', + 'payout' => 'Stripe\\Payout', 'plan' => 'Stripe\\Plan', 'product' => 'Stripe\\Product', 'recipient' => 'Stripe\\Recipient', + 'recipient_transfer' => 'Stripe\\RecipientTransfer', 'refund' => 'Stripe\\Refund', 'sku' => 'Stripe\\SKU', 'source' => 'Stripe\\Source', @@ -141,4 +146,72 @@ abstract class Util return $value; } } + + /** + * Compares two strings for equality. The time taken is independent of the + * number of characters that match. + * + * @param string $a one of the strings to compare. + * @param string $b the other string to compare. + * @return bool true if the strings are equal, false otherwise. + */ + public static function secureCompare($a, $b) + { + if (self::$isHashEqualsAvailable === null) { + self::$isHashEqualsAvailable = function_exists('hash_equals'); + } + + if (self::$isHashEqualsAvailable) { + return hash_equals($a, $b); + } else { + if (strlen($a) != strlen($b)) { + return false; + } + + $result = 0; + for ($i = 0; $i < strlen($a); $i++) { + $result |= ord($a[$i]) ^ ord($b[$i]); + } + return ($result == 0); + } + } + + /** + * @param array $arr A map of param keys to values. + * @param string|null $prefix + * + * @return string A querystring, essentially. + */ + public static function urlEncode($arr, $prefix = null) + { + if (!is_array($arr)) { + return $arr; + } + + $r = array(); + foreach ($arr as $k => $v) { + if (is_null($v)) { + continue; + } + + if ($prefix) { + if ($k !== null && (!is_int($k) || is_array($v))) { + $k = $prefix."[".$k."]"; + } else { + $k = $prefix."[]"; + } + } + + if (is_array($v)) { + $enc = self::urlEncode($v, $k); + if ($enc) { + $r[] = $enc; + } + } else { + $r[] = urlencode($k)."=".urlencode($v); + } + } + + return implode("&", $r); + } } diff --git a/vendor/stripe/stripe-php/lib/Webhook.php b/vendor/stripe/stripe-php/lib/Webhook.php new file mode 100644 index 00000000..718acd27 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/Webhook.php @@ -0,0 +1,40 @@ +<?php + +namespace Stripe; + +abstract class Webhook +{ + const DEFAULT_TOLERANCE = 300; + + /** + * Returns an Event instance using the provided JSON payload. Throws a + * \UnexpectedValueException if the payload is not valid JSON, and a + * \Stripe\SignatureVerificationException if the signature verification + * fails for any reason. + * + * @param string $payload the payload sent by Stripe. + * @param string $sigHeader the contents of the signature header sent by + * Stripe. + * @param string $secret secret used to generate the signature. + * @param int $tolerance maximum difference allowed between the header's + * timestamp and the current time + * @return \Stripe\Event the Event instance + * @throws \UnexpectedValueException if the payload is not valid JSON, + * \Stripe\SignatureVerification if the verification fails. + */ + public static function constructEvent($payload, $sigHeader, $secret, $tolerance = self::DEFAULT_TOLERANCE) + { + $data = json_decode($payload, true); + $jsonError = json_last_error(); + if ($data === null && $jsonError !== JSON_ERROR_NONE) { + $msg = "Invalid payload: $payload " + . "(json_last_error() was $jsonError)"; + throw new \UnexpectedValueException($msg); + } + $event = Event::constructFrom($data, null); + + WebhookSignature::verifyHeader($payload, $sigHeader, $secret, $tolerance); + + return $event; + } +} diff --git a/vendor/stripe/stripe-php/lib/WebhookSignature.php b/vendor/stripe/stripe-php/lib/WebhookSignature.php new file mode 100644 index 00000000..c96ea9f5 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/WebhookSignature.php @@ -0,0 +1,132 @@ +<?php + +namespace Stripe; + +abstract class WebhookSignature +{ + const EXPECTED_SCHEME = "v1"; + + /** + * Verifies the signature header sent by Stripe. Throws a + * SignatureVerification exception if the verification fails for any + * reason. + * + * @param string $payload the payload sent by Stripe. + * @param string $header the contents of the signature header sent by + * Stripe. + * @param string $secret secret used to generate the signature. + * @param int $tolerance maximum difference allowed between the header's + * timestamp and the current time + * @throws SignatureVerification if the verification fails. + */ + public static function verifyHeader($payload, $header, $secret, $tolerance = null) + { + // Extract timestamp and signatures from header + $timestamp = self::getTimestamp($header); + $signatures = self::getSignatures($header, self::EXPECTED_SCHEME); + if ($timestamp == -1) { + throw new Error\SignatureVerification( + "Unable to extract timestamp and signatures from header", + $header, + $payload + ); + } + if (empty($signatures)) { + throw new Error\SignatureVerification( + "No signatures found with expected scheme", + $header, + $payload + ); + } + + // Check if expected signature is found in list of signatures from + // header + $signedPayload = "$timestamp.$payload"; + $expectedSignature = self::computeSignature($signedPayload, $secret); + $signatureFound = false; + foreach ($signatures as $signature) { + if (Util\Util::secureCompare($expectedSignature, $signature)) { + $signatureFound = true; + break; + } + } + if (!$signatureFound) { + throw new Error\SignatureVerification( + "No signatures found matching the expected signature for payload", + $header, + $payload + ); + } + + // Check if timestamp is within tolerance + if (($tolerance > 0) && ((time() - $timestamp) > $tolerance)) { + throw new Error\SignatureVerification( + "Timestamp outside the tolerance zone", + $header, + $payload + ); + } + + return true; + } + + /** + * Extracts the timestamp in a signature header. + * + * @param string $header the signature header + * @return int the timestamp contained in the header, or -1 if no valid + * timestamp is found + */ + private static function getTimestamp($header) + { + $items = explode(",", $header); + + foreach ($items as $item) { + $itemParts = explode("=", $item, 2); + if ($itemParts[0] == "t") { + if (!is_numeric($itemParts[1])) { + return -1; + } + return intval($itemParts[1]); + } + } + + return -1; + } + + /** + * Extracts the signatures matching a given scheme in a signature header. + * + * @param string $header the signature header + * @param string $scheme the signature scheme to look for. + * @return array the list of signatures matching the provided scheme. + */ + private static function getSignatures($header, $scheme) + { + $signatures = array(); + $items = explode(",", $header); + + foreach ($items as $item) { + $itemParts = explode("=", $item, 2); + if ($itemParts[0] == $scheme) { + array_push($signatures, $itemParts[1]); + } + } + + return $signatures; + } + + /** + * Computes the signature for a given payload and secret. + * + * The current scheme used by Stripe ("v1") is HMAC/SHA-256. + * + * @param string $payload the payload to sign. + * @param string $secret the secret used to generate the signature. + * @return string the signature as a string. + */ + private static function computeSignature($payload, $secret) + { + return hash_hmac("sha256", $payload, $secret); + } +} diff --git a/packages/stripe-php/phpunit.no_autoload.xml b/vendor/stripe/stripe-php/phpunit.no_autoload.xml similarity index 100% rename from packages/stripe-php/phpunit.no_autoload.xml rename to vendor/stripe/stripe-php/phpunit.no_autoload.xml diff --git a/packages/stripe-php/phpunit.xml b/vendor/stripe/stripe-php/phpunit.xml similarity index 100% rename from packages/stripe-php/phpunit.xml rename to vendor/stripe/stripe-php/phpunit.xml diff --git a/packages/stripe-php/tests/AccountTest.php b/vendor/stripe/stripe-php/tests/AccountTest.php similarity index 84% rename from packages/stripe-php/tests/AccountTest.php rename to vendor/stripe/stripe-php/tests/AccountTest.php index 994ba6f6..5f8df539 100644 --- a/packages/stripe-php/tests/AccountTest.php +++ b/vendor/stripe/stripe-php/tests/AccountTest.php @@ -295,6 +295,69 @@ class AccountTest extends TestCase $account->legal_entity->additional_owners[1] = array('first_name' => 'Jane'); $account->save(); + $this->assertSame(2, count($account->legal_entity->additional_owners)); $this->assertSame('Jane', $account->legal_entity->additional_owners[1]->first_name); } + + public function testLoginLinkCreation() + { + $accountId = 'acct_EXPRESS'; + $mockExpress = array( + 'id' => $accountId, + 'object' => 'account', + 'login_links' => array( + 'object' => 'list', + 'data' => array(), + 'has_more' => false, + 'url' => "/v1/accounts/$accountId/login_links" + ) + ); + + $this->mockRequest('GET', "/v1/accounts/$accountId", array(), $mockExpress); + + $mockLoginLink = array( + 'object' => 'login_link', + 'created' => 1493820886, + 'url' => "https://connect.stripe.com/$accountId/AAAAAAAA" + ); + + $this->mockRequest('POST', "/v1/accounts/$accountId/login_links", array(), $mockLoginLink); + + $account = Account::retrieve($accountId); + $loginLink = $account->login_links->create(); + $this->assertSame('login_link', $loginLink->object); + $this->assertSame('Stripe\LoginLink', get_class($loginLink)); + } + + public function testDeauthorize() + { + Stripe::setClientId('ca_test'); + + $accountId = 'acct_test_deauth'; + $mockAccount = array( + 'id' => $accountId, + 'object' => 'account', + ); + + $this->mockRequest('GET', "/v1/accounts/$accountId", array(), $mockAccount); + + $this->mockRequest( + 'POST', + '/oauth/deauthorize', + array( + 'client_id' => 'ca_test', + 'stripe_user_id' => $accountId, + ), + array( + 'stripe_user_id' => $accountId, + ), + 200, + Stripe::$connectBase + ); + + $account = Account::retrieve($accountId); + $account->deauthorize(); + + Stripe::setClientId(null); + } } diff --git a/vendor/stripe/stripe-php/tests/ApiRequestorTest.php b/vendor/stripe/stripe-php/tests/ApiRequestorTest.php new file mode 100644 index 00000000..465f0c19 --- /dev/null +++ b/vendor/stripe/stripe-php/tests/ApiRequestorTest.php @@ -0,0 +1,228 @@ +<?php + +namespace Stripe; + +use Stripe\HttpClient\CurlClient; + +class ApiRequestorTest extends TestCase +{ + public function testEncodeObjects() + { + $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); + $method = $reflector->getMethod('_encodeObjects'); + $method->setAccessible(true); + + $a = array('customer' => new Customer('abcd')); + $enc = $method->invoke(null, $a); + $this->assertSame($enc, array('customer' => 'abcd')); + + // Preserves UTF-8 + $v = array('customer' => "☃"); + $enc = $method->invoke(null, $v); + $this->assertSame($enc, $v); + + // Encodes latin-1 -> UTF-8 + $v = array('customer' => "\xe9"); + $enc = $method->invoke(null, $v); + $this->assertSame($enc, array('customer' => "\xc3\xa9")); + } + + public function testHttpClientInjection() + { + $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); + $method = $reflector->getMethod('httpClient'); + $method->setAccessible(true); + + $curl = new CurlClient(); + $curl->setTimeout(10); + ApiRequestor::setHttpClient($curl); + + $injectedCurl = $method->invoke(new ApiRequestor()); + $this->assertSame($injectedCurl, $curl); + } + + public function testDefaultHeaders() + { + $reflector = new \ReflectionClass('Stripe\\ApiRequestor'); + $method = $reflector->getMethod('_defaultHeaders'); + $method->setAccessible(true); + + // no way to stub static methods with PHPUnit 4.x :( + Stripe::setAppInfo('MyTestApp', '1.2.34', 'https://mytestapp.example'); + $apiKey = 'sk_test_notarealkey'; + $clientInfo = array('httplib' => 'testlib 0.1.2'); + + $headers = $method->invoke(null, $apiKey, $clientInfo); + + $ua = json_decode($headers['X-Stripe-Client-User-Agent']); + $this->assertSame($ua->application->name, 'MyTestApp'); + $this->assertSame($ua->application->version, '1.2.34'); + $this->assertSame($ua->application->url, 'https://mytestapp.example'); + + $this->assertSame($ua->httplib, 'testlib 0.1.2'); + + $this->assertSame( + $headers['User-Agent'], + 'Stripe/v1 PhpBindings/' . Stripe::VERSION . ' MyTestApp/1.2.34 (https://mytestapp.example)' + ); + + $this->assertSame($headers['Authorization'], 'Bearer ' . $apiKey); + } + + public function testErrorInvalidRequest() + { + $this->mockRequest( + 'POST', + '/v1/charges', + array(), + array( + 'error' => array( + 'type' => 'invalid_request_error', + 'message' => 'Missing id', + 'param' => 'id', + ), + ), + 400 + ); + + try { + Charge::create(); + $this->fail("Did not raise error"); + } catch (Error\InvalidRequest $e) { + $this->assertSame('Missing id', $e->getMessage()); + $this->assertSame('id', $e->getStripeParam()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } + + public function testErrorAuthentication() + { + $this->mockRequest( + 'POST', + '/v1/charges', + array(), + array( + 'error' => array( + 'type' => 'invalid_request_error', + 'message' => 'You did not provide an API key.', + ), + ), + 401 + ); + + try { + Charge::create(); + $this->fail("Did not raise error"); + } catch (Error\Authentication $e) { + $this->assertSame('You did not provide an API key.', $e->getMessage()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } + + public function testErrorCard() + { + $this->mockRequest( + 'POST', + '/v1/charges', + array(), + array( + 'error' => array( + 'type' => 'card_error', + 'message' => 'Your card was declined.', + 'code' => 'card_declined', + 'decline_code' => 'generic_decline', + 'charge' => 'ch_declined_charge', + ), + ), + 402 + ); + + try { + Charge::create(); + $this->fail("Did not raise error"); + } catch (Error\Card $e) { + $this->assertSame('Your card was declined.', $e->getMessage()); + $this->assertSame('card_declined', $e->getStripeCode()); + $this->assertSame('generic_decline', $e->getDeclineCode()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } + + public function testErrorOAuthInvalidRequest() + { + $this->mockRequest( + 'POST', + '/oauth/token', + array(), + array( + 'error' => 'invalid_request', + 'error_description' => 'No grant type specified', + ), + 400, + Stripe::$connectBase + ); + + try { + OAuth::token(); + $this->fail("Did not raise error"); + } catch (Error\OAuth\InvalidRequest $e) { + $this->assertSame('invalid_request', $e->getErrorCode()); + $this->assertSame('No grant type specified', $e->getMessage()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } + + public function testErrorOAuthInvalidClient() + { + $this->mockRequest( + 'POST', + '/oauth/token', + array(), + array( + 'error' => 'invalid_client', + 'error_description' => 'No authentication was provided. Send your secret API key using the Authorization header, or as a client_secret POST parameter.', + ), + 401, + Stripe::$connectBase + ); + + try { + OAuth::token(); + $this->fail("Did not raise error"); + } catch (Error\OAuth\InvalidClient $e) { + $this->assertSame('invalid_client', $e->getErrorCode()); + $this->assertSame('No authentication was provided. Send your secret API key using the Authorization header, or as a client_secret POST parameter.', $e->getMessage()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } + + public function testErrorOAuthInvalidGrant() + { + $this->mockRequest( + 'POST', + '/oauth/token', + array(), + array( + 'error' => 'invalid_grant', + 'error_description' => 'This authorization code has already been used. All tokens issued with this code have been revoked.', + ), + 400, + Stripe::$connectBase + ); + + try { + OAuth::token(); + $this->fail("Did not raise error"); + } catch (Error\OAuth\InvalidGrant $e) { + $this->assertSame('invalid_grant', $e->getErrorCode()); + $this->assertSame('This authorization code has already been used. All tokens issued with this code have been revoked.', $e->getMessage()); + } catch (\Exception $e) { + $this->fail("Unexpected exception: " . get_class($e)); + } + } +} diff --git a/packages/stripe-php/tests/ApplePayDomainTest.php b/vendor/stripe/stripe-php/tests/ApplePayDomainTest.php similarity index 100% rename from packages/stripe-php/tests/ApplePayDomainTest.php rename to vendor/stripe/stripe-php/tests/ApplePayDomainTest.php diff --git a/packages/stripe-php/tests/ApplicationFeeRefundTest.php b/vendor/stripe/stripe-php/tests/ApplicationFeeRefundTest.php similarity index 100% rename from packages/stripe-php/tests/ApplicationFeeRefundTest.php rename to vendor/stripe/stripe-php/tests/ApplicationFeeRefundTest.php diff --git a/packages/stripe-php/tests/ApplicationFeeTest.php b/vendor/stripe/stripe-php/tests/ApplicationFeeTest.php similarity index 100% rename from packages/stripe-php/tests/ApplicationFeeTest.php rename to vendor/stripe/stripe-php/tests/ApplicationFeeTest.php diff --git a/vendor/stripe/stripe-php/tests/AttachedObjectTest.php b/vendor/stripe/stripe-php/tests/AttachedObjectTest.php new file mode 100644 index 00000000..e91232df --- /dev/null +++ b/vendor/stripe/stripe-php/tests/AttachedObjectTest.php @@ -0,0 +1,18 @@ +<?php + +namespace Stripe; + +class AttachedObjectTest extends TestCase +{ + public function testCount() + { + $ao = new AttachedObject(); + $this->assertSame(0, count($ao)); + + $ao['key1'] = 'value1'; + $this->assertSame(1, count($ao)); + + $ao['key2'] = 'value2'; + $this->assertSame(2, count($ao)); + } +} diff --git a/packages/stripe-php/tests/AuthenticationErrorTest.php b/vendor/stripe/stripe-php/tests/AuthenticationErrorTest.php similarity index 100% rename from packages/stripe-php/tests/AuthenticationErrorTest.php rename to vendor/stripe/stripe-php/tests/AuthenticationErrorTest.php diff --git a/packages/stripe-php/tests/BalanceTest.php b/vendor/stripe/stripe-php/tests/BalanceTest.php similarity index 100% rename from packages/stripe-php/tests/BalanceTest.php rename to vendor/stripe/stripe-php/tests/BalanceTest.php diff --git a/packages/stripe-php/tests/BalanceTransactionTest.php b/vendor/stripe/stripe-php/tests/BalanceTransactionTest.php similarity index 100% rename from packages/stripe-php/tests/BalanceTransactionTest.php rename to vendor/stripe/stripe-php/tests/BalanceTransactionTest.php diff --git a/packages/stripe-php/tests/BankAccountTest.php b/vendor/stripe/stripe-php/tests/BankAccountTest.php similarity index 100% rename from packages/stripe-php/tests/BankAccountTest.php rename to vendor/stripe/stripe-php/tests/BankAccountTest.php diff --git a/vendor/stripe/stripe-php/tests/BitcoinReceiverTest.php b/vendor/stripe/stripe-php/tests/BitcoinReceiverTest.php new file mode 100644 index 00000000..b958b1e9 --- /dev/null +++ b/vendor/stripe/stripe-php/tests/BitcoinReceiverTest.php @@ -0,0 +1,26 @@ +<?php + +namespace Stripe; + +class BitcoinReceiverTest extends TestCase +{ + public function testUrls() + { + $classUrl = BitcoinReceiver::classUrl('Stripe_BitcoinReceiver'); + $this->assertSame($classUrl, '/v1/bitcoin/receivers'); + $receiver = new BitcoinReceiver('abcd/efgh'); + $instanceUrl = $receiver->instanceUrl(); + $this->assertSame($instanceUrl, '/v1/bitcoin/receivers/abcd%2Fefgh'); + } + + // + // Note that there are no tests of consequences in here. The Bitcoin + // endpoints have been deprecated in favor of the generic sources API. The + // BitcoinReceiver class has been left in place for some backwards + // compatibility, but all users should be migrating off of it. The tests + // have been removed because we no longer have the API endpoints required + // to run them. + // + // [1] https://stripe.com/docs/sources + // +} diff --git a/packages/stripe-php/tests/CardErrorTest.php b/vendor/stripe/stripe-php/tests/CardErrorTest.php similarity index 83% rename from packages/stripe-php/tests/CardErrorTest.php rename to vendor/stripe/stripe-php/tests/CardErrorTest.php index 09f27347..62a8bf1c 100644 --- a/packages/stripe-php/tests/CardErrorTest.php +++ b/vendor/stripe/stripe-php/tests/CardErrorTest.php @@ -8,16 +8,10 @@ class CardErrorTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4000000000000002', - 'exp_month' => '3', - 'exp_year' => '2020' - ); - $charge = array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'source' => 'tok_chargeDeclined' ); try { @@ -31,6 +25,7 @@ class CardErrorTest extends TestCase 'message' => 'Your card was declined.', 'type' => 'card_error', 'code' => 'card_declined', + 'decline_code' => 'generic_decline', 'charge' => $actual['error']['charge'], )), $actual diff --git a/packages/stripe-php/tests/ChargeTest.php b/vendor/stripe/stripe-php/tests/ChargeTest.php similarity index 62% rename from packages/stripe-php/tests/ChargeTest.php rename to vendor/stripe/stripe-php/tests/ChargeTest.php index 6ec0fa1f..a5b8a404 100644 --- a/packages/stripe-php/tests/ChargeTest.php +++ b/vendor/stripe/stripe-php/tests/ChargeTest.php @@ -15,17 +15,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $c = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); $this->assertTrue($c->paid); @@ -36,17 +30,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $c = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ), array( 'idempotency_key' => self::generateRandomString(), @@ -61,17 +49,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $c = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); $d = Charge::retrieve($c->id); @@ -83,17 +65,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $charge = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); @@ -108,17 +84,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $charge = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); @@ -134,17 +104,11 @@ class ChargeTest extends TestCase { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $charge = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); @@ -158,41 +122,15 @@ class ChargeTest extends TestCase ); } - public function testCreateWithBitcoinReceiverSource() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $charge = Charge::create( - array( - 'amount' => 100, - 'currency' => 'usd', - 'source' => $receiver->id - ) - ); - - $this->assertSame($receiver->id, $charge->source->id); - $this->assertSame("bitcoin_receiver", $charge->source->object); - $this->assertSame("succeeded", $charge->status); - $this->assertInstanceOf('Stripe\\BitcoinReceiver', $charge->source); - } - public function markAsSafe() { self::authorizeFromEnv(); - $card = array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $charge = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'card' => 'tok_visa' ) ); diff --git a/packages/stripe-php/tests/CollectionTest.php b/vendor/stripe/stripe-php/tests/CollectionTest.php similarity index 100% rename from packages/stripe-php/tests/CollectionTest.php rename to vendor/stripe/stripe-php/tests/CollectionTest.php diff --git a/packages/stripe-php/tests/CountrySpecTest.php b/vendor/stripe/stripe-php/tests/CountrySpecTest.php similarity index 100% rename from packages/stripe-php/tests/CountrySpecTest.php rename to vendor/stripe/stripe-php/tests/CountrySpecTest.php diff --git a/packages/stripe-php/tests/CouponTest.php b/vendor/stripe/stripe-php/tests/CouponTest.php similarity index 100% rename from packages/stripe-php/tests/CouponTest.php rename to vendor/stripe/stripe-php/tests/CouponTest.php diff --git a/packages/stripe-php/tests/CurlClientTest.php b/vendor/stripe/stripe-php/tests/CurlClientTest.php similarity index 62% rename from packages/stripe-php/tests/CurlClientTest.php rename to vendor/stripe/stripe-php/tests/CurlClientTest.php index 864607f0..ca0ddb64 100644 --- a/packages/stripe-php/tests/CurlClientTest.php +++ b/vendor/stripe/stripe-php/tests/CurlClientTest.php @@ -23,6 +23,15 @@ class CurlClientTest extends TestCase $this->assertSame(0, $curl->getConnectTimeout()); } + public function testUserAgentInfo() + { + $curl = new CurlClient(); + $uaInfo = $curl->getUserAgentInfo(); + $this->assertNotNull($uaInfo); + $this->assertNotNull($uaInfo['httplib']); + $this->assertNotNull($uaInfo['ssllib']); + } + public function testDefaultOptions() { // make sure options array loads/saves properly @@ -48,48 +57,6 @@ class CurlClientTest extends TestCase $withBadClosure->request('get', 'https://httpbin.org/status/200', array(), array(), false); } - public function testEncode() - { - $a = array( - 'my' => 'value', - 'that' => array('your' => 'example'), - 'bar' => 1, - 'baz' => null - ); - - $enc = CurlClient::encode($a); - $this->assertSame('my=value&that%5Byour%5D=example&bar=1', $enc); - - $a = array('that' => array('your' => 'example', 'foo' => null)); - $enc = CurlClient::encode($a); - $this->assertSame('that%5Byour%5D=example', $enc); - - $a = array('that' => 'example', 'foo' => array('bar', 'baz')); - $enc = CurlClient::encode($a); - $this->assertSame('that=example&foo%5B%5D=bar&foo%5B%5D=baz', $enc); - - $a = array( - 'my' => 'value', - 'that' => array('your' => array('cheese', 'whiz', null)), - 'bar' => 1, - 'baz' => null - ); - - $enc = CurlClient::encode($a); - $expected = 'my=value&that%5Byour%5D%5B%5D=cheese' - . '&that%5Byour%5D%5B%5D=whiz&bar=1'; - $this->assertSame($expected, $enc); - - // Ignores an empty array - $enc = CurlClient::encode(array('foo' => array(), 'bar' => 'baz')); - $expected = 'bar=baz'; - $this->assertSame($expected, $enc); - - $a = array('foo' => array(array('bar' => 'baz'), array('bar' => 'bin'))); - $enc = CurlClient::encode($a); - $this->assertSame('foo%5B0%5D%5Bbar%5D=baz&foo%5B1%5D%5Bbar%5D=bin', $enc); - } - public function testSslOption() { // make sure options array loads/saves properly diff --git a/packages/stripe-php/tests/CustomerTest.php b/vendor/stripe/stripe-php/tests/CustomerTest.php similarity index 85% rename from packages/stripe-php/tests/CustomerTest.php rename to vendor/stripe/stripe-php/tests/CustomerTest.php index 606536ee..1679853f 100644 --- a/packages/stripe-php/tests/CustomerTest.php +++ b/vendor/stripe/stripe-php/tests/CustomerTest.php @@ -68,11 +68,14 @@ class CustomerTest extends TestCase { $customer = self::createTestCustomer(); - $customer->metadata['test'] = 'foo bar'; + $customer->metadata['test1'] = 'foo'; + $customer->metadata['test2'] = 'bar'; $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); - $this->assertSame('foo bar', $updatedCustomer->metadata['test']); + $this->assertSame(2, count($updatedCustomer->metadata)); + $this->assertSame('foo', $updatedCustomer->metadata['test1']); + $this->assertSame('bar', $updatedCustomer->metadata['test2']); } public function testDeleteMetadata() @@ -83,7 +86,7 @@ class CustomerTest extends TestCase $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); - $this->assertSame(0, count($updatedCustomer->metadata->keys())); + $this->assertSame(0, count($updatedCustomer->metadata)); } public function testUpdateSomeMetadata() @@ -146,17 +149,8 @@ class CustomerTest extends TestCase public function testCustomerAddCard() { - $token = Token::create( - array("card" => array( - "number" => "4242424242424242", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); - $customer = $this->createTestCustomer(); - $createdCard = $customer->sources->create(array("card" => $token->id)); + $createdCard = $customer->sources->create(array("card" => 'tok_visa')); $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); @@ -183,17 +177,8 @@ class CustomerTest extends TestCase public function testCustomerDeleteCard() { - $token = Token::create( - array("card" => array( - "number" => "4242424242424242", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); - $customer = $this->createTestCustomer(); - $createdCard = $customer->sources->create(array("card" => $token->id)); + $createdCard = $customer->sources->create(array("card" => 'tok_visa')); $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); @@ -212,17 +197,9 @@ class CustomerTest extends TestCase public function testCustomerAddSource() { self::authorizeFromEnv(); - $token = Token::create( - array("card" => array( - "number" => "4242424242424242", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); $customer = $this->createTestCustomer(); - $createdSource = $customer->sources->create(array("source" => $token->id)); + $createdSource = $customer->sources->create(array("source" => 'tok_visa')); $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); @@ -250,17 +227,9 @@ class CustomerTest extends TestCase public function testCustomerDeleteSource() { self::authorizeFromEnv(); - $token = Token::create( - array("card" => array( - "number" => "4242424242424242", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); $customer = $this->createTestCustomer(); - $createdSource = $customer->sources->create(array("source" => $token->id)); + $createdSource = $customer->sources->create(array("source" => 'tok_visa')); $customer->save(); $updatedCustomer = Customer::retrieve($customer->id); diff --git a/packages/stripe-php/tests/DiscountTest.php b/vendor/stripe/stripe-php/tests/DiscountTest.php similarity index 100% rename from packages/stripe-php/tests/DiscountTest.php rename to vendor/stripe/stripe-php/tests/DiscountTest.php diff --git a/packages/stripe-php/tests/DisputeTest.php b/vendor/stripe/stripe-php/tests/DisputeTest.php similarity index 81% rename from packages/stripe-php/tests/DisputeTest.php rename to vendor/stripe/stripe-php/tests/DisputeTest.php index 8e4de491..bac033c1 100644 --- a/packages/stripe-php/tests/DisputeTest.php +++ b/vendor/stripe/stripe-php/tests/DisputeTest.php @@ -13,17 +13,11 @@ class DisputeTest extends TestCase private function createDisputedCharge() { - $card = array( - 'number' => '4000000000000259', - 'exp_month' => 5, - 'exp_year' => date('Y') + 1 - ); - $c = Charge::create( array( 'amount' => 100, 'currency' => 'usd', - 'card' => $card + 'source' => 'tok_createDispute' ) ); $c = Charge::retrieve($c->id); @@ -61,11 +55,11 @@ class DisputeTest extends TestCase $c = $this->createDisputedCharge(); - $d = $c->dispute; + $d = Dispute::retrieve($c->dispute); $d->evidence["customer_name"] = "Bob"; $s = $d->save(); - $this->assertSame($d->id, $s->id); + $this->assertSame($c->dispute, $s->id); $this->assertSame("Bob", $s->evidence["customer_name"]); } @@ -74,8 +68,12 @@ class DisputeTest extends TestCase self::authorizeFromEnv(); $c = $this->createDisputedCharge(); + $d = Dispute::retrieve($c->dispute); + + $this->assertNotSame("lost", $d->status); + + $d->close(); - $d = $c->dispute->close(); $this->assertSame("lost", $d->status); } @@ -85,7 +83,8 @@ class DisputeTest extends TestCase $c = $this->createDisputedCharge(); - $d = Dispute::retrieve($c->dispute->id); - $this->assertSame($d->id, $c->dispute->id); + $d = Dispute::retrieve($c->dispute); + + $this->assertSame($c->dispute, $d->id); } } diff --git a/vendor/stripe/stripe-php/tests/EphemeralKeyTest.php b/vendor/stripe/stripe-php/tests/EphemeralKeyTest.php new file mode 100644 index 00000000..cf608b1b --- /dev/null +++ b/vendor/stripe/stripe-php/tests/EphemeralKeyTest.php @@ -0,0 +1,117 @@ +<?php + +namespace Stripe; + +class EphemeralKeyTest extends TestCase +{ + private $oldApiVersion = null; + + /** + * @before + */ + public function setUpApiVersion() + { + $this->oldApiVersion = Stripe::getApiVersion(); + } + + /** + * @after + */ + public function tearDownApiVersion() + { + Stripe::setApiVersion($this->oldApiVersion); + } + + public function testVersionlessCreateWithoutGlobalVersion() + { + $this->setExpectedException('\InvalidArgumentException'); + $key = EphemeralKey::create( + array('customer' => 'cus_123') + ); + } + + public function testVersionedCreateWithoutGlobalVersion() + { + $response = $this->ephemeralKeyResponse('cus_123'); + $this->mockCreate($response); + + $key = EphemeralKey::create( + array('customer' => 'cus_123'), + array('stripe_version' => '2017-05-25') + ); + $this->assertSame($key->id, $response['id']); + } + + public function testVersionlessCreateWithGlobalVersion() + { + Stripe::setApiVersion('2017-06-05'); + $this->setExpectedException('\InvalidArgumentException'); + $key = EphemeralKey::create( + array('customer' => 'cus_123') + ); + } + + public function testVersionedCreateWithGlobalVersion() + { + Stripe::setApiVersion('2017-06-05'); + $response = $this->ephemeralKeyResponse('cus_123'); + $this->mockCreate($response); + + $key = EphemeralKey::create( + array('customer' => 'cus_123'), + array('stripe_version' => '2017-05-25') + ); + $this->assertSame($key->id, $response['id']); + } + + public function testDelete() + { + $response = $this->ephemeralKeyResponse('cus_123'); + $this->mockCreate($response); + $this->mockDelete($response); + + $key = EphemeralKey::create( + array('customer' => 'cus_123'), + array('stripe_version' => '2017-05-25') + ); + + $deleted = $key->delete(); + $this->assertSame($key->id, $deleted->id); + } + + protected function mockCreate($response) + { + $this->mockRequest( + 'POST', + '/v1/ephemeral_keys', + array('customer' => $response['associated_objects'][0]['id']), + $response + ); + } + + protected function mockDelete($response) + { + $this->mockRequest( + 'DELETE', + sprintf('/v1/ephemeral_keys/%s', $response['id']), + array(), + $response + ); + } + + protected function ephemeralKeyResponse($customer) + { + return array( + 'id' => 'ephkey_123', + 'object' => 'ephemeral_key', + 'associated_objects' => array(array( + 'type' => 'customer', + 'id' => $customer + )), + 'created' => 1496957039, + 'expires' => 1496960639, + 'livemode' => false, + 'secret' => 'ek_test_supersecretstring' + ); + } +} diff --git a/packages/stripe-php/tests/ErrorTest.php b/vendor/stripe/stripe-php/tests/ErrorTest.php similarity index 100% rename from packages/stripe-php/tests/ErrorTest.php rename to vendor/stripe/stripe-php/tests/ErrorTest.php diff --git a/packages/stripe-php/tests/ExternalAccountTest.php b/vendor/stripe/stripe-php/tests/ExternalAccountTest.php similarity index 100% rename from packages/stripe-php/tests/ExternalAccountTest.php rename to vendor/stripe/stripe-php/tests/ExternalAccountTest.php diff --git a/packages/stripe-php/tests/FileUploadTest.php b/vendor/stripe/stripe-php/tests/FileUploadTest.php similarity index 95% rename from packages/stripe-php/tests/FileUploadTest.php rename to vendor/stripe/stripe-php/tests/FileUploadTest.php index 7d1faf3b..5ed3ba57 100644 --- a/packages/stripe-php/tests/FileUploadTest.php +++ b/vendor/stripe/stripe-php/tests/FileUploadTest.php @@ -17,6 +17,7 @@ class FileUploadTest extends TestCase fclose($fp); $this->assertSame(95, $file->size); $this->assertSame('png', $file->type); + $this->assertInstanceOf('Stripe\\FileUpload', $file); } public function testCreateAndRetrieveCurlFile() diff --git a/packages/stripe-php/tests/InvalidRequestErrorTest.php b/vendor/stripe/stripe-php/tests/InvalidRequestErrorTest.php similarity index 100% rename from packages/stripe-php/tests/InvalidRequestErrorTest.php rename to vendor/stripe/stripe-php/tests/InvalidRequestErrorTest.php diff --git a/packages/stripe-php/tests/InvoiceTest.php b/vendor/stripe/stripe-php/tests/InvoiceTest.php similarity index 66% rename from packages/stripe-php/tests/InvoiceTest.php rename to vendor/stripe/stripe-php/tests/InvoiceTest.php index e6e51683..45eb7034 100644 --- a/packages/stripe-php/tests/InvoiceTest.php +++ b/vendor/stripe/stripe-php/tests/InvoiceTest.php @@ -51,6 +51,33 @@ class InvoiceTest extends TestCase { self::authorizeFromEnv(); $invoices = Invoice::all(); - $this->assertTrue(count($invoices) > 0); + $this->assertGreaterThan(0, count($invoices)); + } + + public function testPay() + { + $response = array( + 'id' => 'in_foo', + 'object' => 'invoice', + 'paid' => false, + ); + $this->mockRequest( + 'GET', + '/v1/invoices/in_foo', + array(), + $response + ); + + $response['paid'] = true; + $this->mockRequest( + 'POST', + '/v1/invoices/in_foo/pay', + array('source' => 'src_bar'), + $response + ); + + $invoice = Invoice::retrieve('in_foo'); + $invoice->pay(array('source' => 'src_bar')); + $this->assertTrue($invoice->paid); } } diff --git a/vendor/stripe/stripe-php/tests/OAuthTest.php b/vendor/stripe/stripe-php/tests/OAuthTest.php new file mode 100644 index 00000000..732b6c5a --- /dev/null +++ b/vendor/stripe/stripe-php/tests/OAuthTest.php @@ -0,0 +1,99 @@ +<?php + +namespace Stripe; + +class OAuthTest extends TestCase +{ + /** + * @before + */ + public function setUpClientId() + { + Stripe::setClientId('ca_test'); + } + + /** + * @after + */ + public function tearDownClientId() + { + Stripe::setClientId(null); + } + + public function testAuthorizeUrl() + { + $uriStr = OAuth::authorizeUrl(array( + 'scope' => 'read_write', + 'state' => 'csrf_token', + 'stripe_user' => array( + 'email' => 'test@example.com', + 'url' => 'https://example.com/profile/test', + 'country' => 'US', + ), + )); + + $uri = parse_url($uriStr); + parse_str($uri['query'], $params); + + $this->assertSame('https', $uri['scheme']); + $this->assertSame('connect.stripe.com', $uri['host']); + $this->assertSame('/oauth/authorize', $uri['path']); + + $this->assertSame('ca_test', $params['client_id']); + $this->assertSame('read_write', $params['scope']); + $this->assertSame('test@example.com', $params['stripe_user']['email']); + $this->assertSame('https://example.com/profile/test', $params['stripe_user']['url']); + $this->assertSame('US', $params['stripe_user']['country']); + } + + public function testToken() + { + $this->mockRequest( + 'POST', + '/oauth/token', + array( + 'grant_type' => 'authorization_code', + 'code' => 'this_is_an_authorization_code', + ), + array( + 'access_token' => 'sk_access_token', + 'scope' => 'read_only', + 'livemode' => false, + 'token_type' => 'bearer', + 'refresh_token' => 'sk_refresh_token', + 'stripe_user_id' => 'acct_test', + 'stripe_publishable_key' => 'pk_test', + ), + 200, + Stripe::$connectBase + ); + + $resp = OAuth::token(array( + 'grant_type' => 'authorization_code', + 'code' => 'this_is_an_authorization_code', + )); + $this->assertSame('sk_access_token', $resp->access_token); + } + + public function testDeauthorize() + { + $this->mockRequest( + 'POST', + '/oauth/deauthorize', + array( + 'client_id' => 'ca_test', + 'stripe_user_id' => 'acct_test_deauth', + ), + array( + 'stripe_user_id' => 'acct_test_deauth', + ), + 200, + Stripe::$connectBase + ); + + $resp = OAuth::deauthorize(array( + 'stripe_user_id' => 'acct_test_deauth', + )); + $this->assertSame('acct_test_deauth', $resp->stripe_user_id); + } +} diff --git a/vendor/stripe/stripe-php/tests/PayoutTest.php b/vendor/stripe/stripe-php/tests/PayoutTest.php new file mode 100644 index 00000000..a8a0b240 --- /dev/null +++ b/vendor/stripe/stripe-php/tests/PayoutTest.php @@ -0,0 +1,89 @@ +<?php + +namespace Stripe; + +class PayoutTest extends TestCase +{ + private $managedAccount = null; + + /** + * Create a managed account and put enough funds in the balance + * to be able to create a payout afterwards. Also try to re-use + * the managed account across the tests to avoid hitting the + * rate limit for account creation. + */ + private function createAccountWithBalance() + { + if ($this->managedAccount === null) { + self::authorizeFromEnv(); + $account = self::createTestManagedAccount(); + + $charge = \Stripe\Charge::create(array( + 'currency' => 'usd', + 'amount' => '10000', + 'source' => 'tok_bypassPending', + 'destination' => array( + 'account' => $account->id + ) + )); + + $this->managedAccount = $account; + } + + return $this->managedAccount; + } + + private function createPayoutFromManagedAccount($accountId) + { + $payout = Payout::create( + array( + 'amount' => 100, + 'currency' => 'usd', + ), + array( + 'stripe_account' => $accountId + ) + ); + + return $payout; + } + + public function testCreate() + { + $account = self::createAccountWithBalance(); + $payout = self::createPayoutFromManagedAccount($account->id); + + $this->assertSame('pending', $payout->status); + } + + public function testRetrieve() + { + $account = self::createAccountWithBalance(); + $payout = self::createPayoutFromManagedAccount($account->id); + $reloaded = Payout::retrieve($payout->id, array('stripe_account' => $account->id)); + $this->assertSame($reloaded->id, $payout->id); + } + + public function testPayoutUpdateMetadata() + { + $account = self::createAccountWithBalance(); + $payout = self::createPayoutFromManagedAccount($account->id); + $payout->metadata['test'] = 'foo bar'; + $payout->save(); + + $updatedPayout = Payout::retrieve($payout->id, array('stripe_account' => $account->id)); + $this->assertSame('foo bar', $updatedPayout->metadata['test']); + } + + public function testPayoutUpdateMetadataAll() + { + $account = self::createAccountWithBalance(); + $payout = self::createPayoutFromManagedAccount($account->id); + + $payout->metadata = array('test' => 'foo bar'); + $payout->save(); + + $updatedPayout = Payout::retrieve($payout->id, array('stripe_account' => $account->id)); + $this->assertSame('foo bar', $updatedPayout->metadata['test']); + } +} diff --git a/packages/stripe-php/tests/PermissionsErrorTest.php b/vendor/stripe/stripe-php/tests/PermissionsErrorTest.php similarity index 100% rename from packages/stripe-php/tests/PermissionsErrorTest.php rename to vendor/stripe/stripe-php/tests/PermissionsErrorTest.php diff --git a/packages/stripe-php/tests/PlanTest.php b/vendor/stripe/stripe-php/tests/PlanTest.php similarity index 100% rename from packages/stripe-php/tests/PlanTest.php rename to vendor/stripe/stripe-php/tests/PlanTest.php diff --git a/packages/stripe-php/tests/ProductTest.php b/vendor/stripe/stripe-php/tests/ProductTest.php similarity index 95% rename from packages/stripe-php/tests/ProductTest.php rename to vendor/stripe/stripe-php/tests/ProductTest.php index 668d015e..ea4c15a3 100644 --- a/packages/stripe-php/tests/ProductTest.php +++ b/vendor/stripe/stripe-php/tests/ProductTest.php @@ -142,14 +142,7 @@ class ProductSKUOrderTest extends TestCase $stripeOrder = Order::retrieve($order->id); $this->assertSame($order->metadata->foo, "bar"); - $order->pay(array( - 'source' => array( - 'object' => 'card', - 'number' => '4242424242424242', - 'exp_month' => '05', - 'exp_year' => '2017' - ), - )); + $order->pay(array('source' => 'tok_visa')); $this->assertSame($order->status, 'paid'); $orderReturn = $order->returnOrder(); diff --git a/packages/stripe-php/tests/RateLimitErrorTest.php b/vendor/stripe/stripe-php/tests/RateLimitErrorTest.php similarity index 100% rename from packages/stripe-php/tests/RateLimitErrorTest.php rename to vendor/stripe/stripe-php/tests/RateLimitErrorTest.php diff --git a/packages/stripe-php/tests/RecipientTest.php b/vendor/stripe/stripe-php/tests/RecipientTest.php similarity index 76% rename from packages/stripe-php/tests/RecipientTest.php rename to vendor/stripe/stripe-php/tests/RecipientTest.php index e26bfe8c..7a51646b 100644 --- a/packages/stripe-php/tests/RecipientTest.php +++ b/vendor/stripe/stripe-php/tests/RecipientTest.php @@ -36,17 +36,8 @@ class RecipientTest extends TestCase public function testRecipientAddCard() { - $token = Token::create( - array("card" => array( - "number" => "4000056655665556", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); - $recipient = $this->createTestRecipient(); - $createdCard = $recipient->cards->create(array("card" => $token->id)); + $createdCard = $recipient->cards->create(array("card" => 'tok_visa_debit')); $recipient->save(); $updatedRecipient = Recipient::retrieve($recipient->id); @@ -56,17 +47,8 @@ class RecipientTest extends TestCase public function testRecipientUpdateCard() { - $token = Token::create( - array("card" => array( - "number" => "4000056655665556", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); - $recipient = $this->createTestRecipient(); - $createdCard = $recipient->cards->create(array("card" => $token->id)); + $createdCard = $recipient->cards->create(array("card" => 'tok_visa_debit')); $recipient->save(); $createdCards = $recipient->cards->all(); @@ -83,17 +65,8 @@ class RecipientTest extends TestCase public function testRecipientDeleteCard() { - $token = Token::create( - array("card" => array( - "number" => "4000056655665556", - "exp_month" => 5, - "exp_year" => date('Y') + 3, - "cvc" => "314" - )) - ); - $recipient = $this->createTestRecipient(); - $createdCard = $recipient->cards->create(array("card" => $token->id)); + $createdCard = $recipient->cards->create(array("card" => 'tok_visa_debit')); $recipient->save(); $updatedRecipient = Recipient::retrieve($recipient->id); diff --git a/packages/stripe-php/tests/RefundTest.php b/vendor/stripe/stripe-php/tests/RefundTest.php similarity index 63% rename from packages/stripe-php/tests/RefundTest.php rename to vendor/stripe/stripe-php/tests/RefundTest.php index e9dd8509..87729eab 100644 --- a/packages/stripe-php/tests/RefundTest.php +++ b/vendor/stripe/stripe-php/tests/RefundTest.php @@ -45,32 +45,6 @@ class RefundTest extends TestCase $this->assertSame(10, count($all->data)); } - public function testCreateForBitcoin() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $charge = Charge::create( - array( - 'amount' => $receiver->amount, - 'currency' => $receiver->currency, - 'description' => $receiver->description, - 'source' => $receiver->id - ) - ); - - $ref = Refund::create( - array( - 'amount' => $receiver->amount, - 'refund_address' => 'ABCDEF', - 'charge' => $charge->id - ) - ); - $this->assertSame($receiver->amount, $ref->amount); - $this->assertNotNull($ref->id); - } - // Deprecated charge endpoints: public function testCreateViaCharge() @@ -103,29 +77,4 @@ class RefundTest extends TestCase $this->assertSame($refB->id, $all->data[0]->id); $this->assertSame($refA->id, $all->data[1]->id); } - - public function testCreateForBitcoinViaCharge() - { - self::authorizeFromEnv(); - - $receiver = $this->createTestBitcoinReceiver("do+fill_now@stripe.com"); - - $charge = Charge::create( - array( - 'amount' => $receiver->amount, - 'currency' => $receiver->currency, - 'description' => $receiver->description, - 'source' => $receiver->id - ) - ); - - $ref = $charge->refunds->create( - array( - 'amount' => $receiver->amount, - 'refund_address' => 'ABCDEF' - ) - ); - $this->assertSame($receiver->amount, $ref->amount); - $this->assertNotNull($ref->id); - } } diff --git a/packages/stripe-php/tests/RequestOptionsTest.php b/vendor/stripe/stripe-php/tests/RequestOptionsTest.php similarity index 100% rename from packages/stripe-php/tests/RequestOptionsTest.php rename to vendor/stripe/stripe-php/tests/RequestOptionsTest.php diff --git a/vendor/stripe/stripe-php/tests/SourceTest.php b/vendor/stripe/stripe-php/tests/SourceTest.php new file mode 100644 index 00000000..5ba142b9 --- /dev/null +++ b/vendor/stripe/stripe-php/tests/SourceTest.php @@ -0,0 +1,218 @@ +<?php + +namespace Stripe; + +class SourceTest extends TestCase +{ + public function testRetrieve() + { + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + array( + 'id' => 'src_foo', + 'object' => 'source', + ) + ); + $source = Source::retrieve('src_foo'); + $this->assertSame($source->id, 'src_foo'); + } + + public function testCreate() + { + $this->mockRequest( + 'POST', + '/v1/sources', + array( + 'type' => 'bitcoin', + 'amount' => 1000, + 'currency' => 'usd', + 'owner' => array('email' => 'jenny.rosen@example.com'), + ), + array( + 'id' => 'src_foo', + 'object' => 'source' + ) + ); + $source = Source::create(array( + 'type' => 'bitcoin', + 'amount' => 1000, + 'currency' => 'usd', + 'owner' => array('email' => 'jenny.rosen@example.com'), + )); + $this->assertSame($source->id, 'src_foo'); + } + + public function testSave() + { + $response = array( + 'id' => 'src_foo', + 'object' => 'source', + 'metadata' => array(), + ); + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + $response + ); + + $response['metadata'] = array('foo' => 'bar'); + $this->mockRequest( + 'POST', + '/v1/sources/src_foo', + array( + 'metadata' => array('foo' => 'bar'), + ), + $response + ); + + $source = Source::retrieve('src_foo'); + $source->metadata['foo'] = 'bar'; + $source->save(); + $this->assertSame($source->metadata['foo'], 'bar'); + } + + public function testSaveOwner() + { + $response = array( + 'id' => 'src_foo', + 'object' => 'source', + 'owner' => array( + 'name' => null, + 'address' => null, + ), + ); + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + $response + ); + + $response['owner'] = array( + 'name' => "Stripey McStripe", + 'address' => array( + 'line1' => "Test Address", + 'city' => "Test City", + 'postal_code' => "12345", + 'state' => "Test State", + 'country' => "Test Country", + ) + ); + $this->mockRequest( + 'POST', + '/v1/sources/src_foo', + array( + 'owner' => array( + 'name' => "Stripey McStripe", + 'address' => array( + 'line1' => "Test Address", + 'city' => "Test City", + 'postal_code' => "12345", + 'state' => "Test State", + 'country' => "Test Country", + ), + ), + ), + $response + ); + + $source = Source::retrieve('src_foo'); + $source->owner['name'] = "Stripey McStripe"; + $source->owner['address'] = array( + 'line1' => "Test Address", + 'city' => "Test City", + 'postal_code' => "12345", + 'state' => "Test State", + 'country' => "Test Country", + ); + $source->save(); + $this->assertSame($source->owner['name'], "Stripey McStripe"); + $this->assertSame($source->owner['address']['line1'], "Test Address"); + $this->assertSame($source->owner['address']['city'], "Test City"); + $this->assertSame($source->owner['address']['postal_code'], "12345"); + $this->assertSame($source->owner['address']['state'], "Test State"); + $this->assertSame($source->owner['address']['country'], "Test Country"); + } + + public function testDeleteAttached() + { + $response = array( + 'id' => 'src_foo', + 'object' => 'source', + 'customer' => 'cus_bar', + ); + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + $response + ); + + unset($response['customer']); + $this->mockRequest( + 'DELETE', + '/v1/customers/cus_bar/sources/src_foo', + array(), + $response + ); + + $source = Source::retrieve('src_foo'); + $source->delete(); + $this->assertFalse(array_key_exists('customer', $source)); + } + + /** + * @expectedException Stripe\Error\Api + */ + public function testDeleteUnattached() + { + $response = array( + 'id' => 'src_foo', + 'object' => 'source', + ); + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + $response + ); + + $source = Source::retrieve('src_foo'); + $source->delete(); + } + + public function testVerify() + { + $response = array( + 'id' => 'src_foo', + 'object' => 'source', + 'verification' => array('status' => 'pending'), + ); + $this->mockRequest( + 'GET', + '/v1/sources/src_foo', + array(), + $response + ); + + $response['verification']['status'] = 'succeeded'; + $this->mockRequest( + 'POST', + '/v1/sources/src_foo/verify', + array( + 'values' => array(32, 45), + ), + $response + ); + + $source = Source::retrieve('src_foo'); + $this->assertSame($source->verification->status, 'pending'); + $source->verify(array( + 'values' => array(32, 45), + )); + $this->assertSame($source->verification->status, 'succeeded'); + } +} diff --git a/packages/stripe-php/tests/StripeObjectTest.php b/vendor/stripe/stripe-php/tests/StripeObjectTest.php similarity index 100% rename from packages/stripe-php/tests/StripeObjectTest.php rename to vendor/stripe/stripe-php/tests/StripeObjectTest.php diff --git a/packages/stripe-php/tests/SubscriptionItemTest.php b/vendor/stripe/stripe-php/tests/SubscriptionItemTest.php similarity index 69% rename from packages/stripe-php/tests/SubscriptionItemTest.php rename to vendor/stripe/stripe-php/tests/SubscriptionItemTest.php index 5821ab05..4e4a545a 100644 --- a/packages/stripe-php/tests/SubscriptionItemTest.php +++ b/vendor/stripe/stripe-php/tests/SubscriptionItemTest.php @@ -4,18 +4,19 @@ namespace Stripe; class SubscriptionItemTest extends TestCase { - public function testCreateUpdateRetrieveListCancel() { - $planID = 'gold-' . self::generateRandomString(20); - self::retrieveOrCreatePlan($planID); + $plan0ID = 'gold-' . self::generateRandomString(20); + self::retrieveOrCreatePlan($plan0ID); $customer = self::createTestCustomer(); - $sub = Subscription::create(array('plan' => $planID, 'customer' => $customer->id)); + $sub = Subscription::create(array('plan' => $plan0ID, 'customer' => $customer->id)); - $subItem = SubscriptionItem::create(array('plan' => $planID, 'subscription' => $sub->id)); + $plan1ID = 'gold-' . self::generateRandomString(20); + self::retrieveOrCreatePlan($plan1ID); - $this->assertSame($subItem->plan->id, $planID); + $subItem = SubscriptionItem::create(array('plan' => $plan1ID, 'subscription' => $sub->id)); + $this->assertSame($subItem->plan->id, $plan1ID); $subItem->quantity = 2; $subItem->save(); diff --git a/packages/stripe-php/tests/SubscriptionTest.php b/vendor/stripe/stripe-php/tests/SubscriptionTest.php similarity index 88% rename from packages/stripe-php/tests/SubscriptionTest.php rename to vendor/stripe/stripe-php/tests/SubscriptionTest.php index 92d433cc..08f74108 100644 --- a/packages/stripe-php/tests/SubscriptionTest.php +++ b/vendor/stripe/stripe-php/tests/SubscriptionTest.php @@ -75,30 +75,33 @@ class SubscriptionTest extends TestCase public function testCreateUpdateListCancelWithItems() { - $planID = 'gold-' . self::generateRandomString(20); - self::retrieveOrCreatePlan($planID); + $plan0ID = 'gold-' . self::generateRandomString(20); + self::retrieveOrCreatePlan($plan0ID); $customer = self::createTestCustomer(); $sub = Subscription::create(array( 'customer' => $customer->id, 'items' => array( - array('plan' => $planID), + array('plan' => $plan0ID), ), )); $this->assertSame(count($sub->items->data), 1); - $this->assertSame($sub->items->data[0]->plan->id, $planID); + $this->assertSame($sub->items->data[0]->plan->id, $plan0ID); + + $plan1ID = 'gold-' . self::generateRandomString(20); + self::retrieveOrCreatePlan($plan1ID); $sub = Subscription::update($sub->id, array( 'items' => array( - array('plan' => $planID), + array('plan' => $plan1ID), ), )); $this->assertSame(count($sub->items->data), 2); - $this->assertSame($sub->items->data[0]->plan->id, $planID); - $this->assertSame($sub->items->data[1]->plan->id, $planID); + $this->assertSame($sub->items->data[0]->plan->id, $plan0ID); + $this->assertSame($sub->items->data[1]->plan->id, $plan1ID); } public function testDeleteDiscount() diff --git a/packages/stripe-php/tests/TestCase.php b/vendor/stripe/stripe-php/tests/TestCase.php similarity index 68% rename from packages/stripe-php/tests/TestCase.php rename to vendor/stripe/stripe-php/tests/TestCase.php index f536db4c..2fb972f4 100644 --- a/packages/stripe-php/tests/TestCase.php +++ b/vendor/stripe/stripe-php/tests/TestCase.php @@ -25,16 +25,21 @@ class TestCase extends \PHPUnit_Framework_TestCase protected function setUp() { ApiRequestor::setHttpClient(HttpClient\CurlClient::instance()); + + // Peg the API version so that it can be varied independently of the + // one set on the test account. + Stripe::setApiVersion('2017-04-06'); + $this->mock = null; $this->call = 0; } - protected function mockRequest($method, $path, $params = array(), $return = array('id' => 'myId'), $rcode = 200) + protected function mockRequest($method, $path, $params = array(), $return = array('id' => 'myId'), $rcode = 200, $base = 'https://api.stripe.com') { $mock = $this->setUpMockRequest(); $mock->expects($this->at($this->call++)) ->method('request') - ->with(strtolower($method), 'https://api.stripe.com' . $path, $this->anything(), $params, false) + ->with(strtolower($method), $base . $path, $this->anything(), $params, false) ->willReturn(array(json_encode($return), $rcode, array())); } @@ -60,19 +65,15 @@ class TestCase extends \PHPUnit_Framework_TestCase 'amount' => 2000, 'currency' => 'usd', 'description' => 'Charge for test@example.com', - 'card' => array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 3, - ), + 'card' => 'tok_visa', ) ); } /** - * Create a valid test charge. + * Create a valid test transfer. */ - protected static function createTestTransfer(array $attributes = array()) + protected static function createTestTransfer(array $attributes = array(), $opts = null) { self::authorizeFromEnv(); @@ -84,7 +85,8 @@ class TestCase extends \PHPUnit_Framework_TestCase 'currency' => 'usd', 'description' => 'Transfer to test@example.com', 'recipient' => $recipient->id - ) + ), + $opts ); } @@ -97,11 +99,7 @@ class TestCase extends \PHPUnit_Framework_TestCase return Customer::create( $attributes + array( - 'card' => array( - 'number' => '4242424242424242', - 'exp_month' => 5, - 'exp_year' => date('Y') + 3, - ), + 'card' => 'tok_visa', ) ); } @@ -119,9 +117,9 @@ class TestCase extends \PHPUnit_Framework_TestCase 'type' => 'individual', 'tax_id' => '000000000', 'bank_account' => array( - 'country' => 'US', + 'country' => 'US', 'routing_number' => '110000000', - 'account_number' => '000123456789' + 'account_number' => '000123456789' ), ) ); @@ -143,6 +141,47 @@ class TestCase extends \PHPUnit_Framework_TestCase ); } + /** + * Create a test account + */ + protected static function createTestManagedAccount(array $attributes = array()) + { + self::authorizeFromEnv(); + + return Account::create( + $attributes + array( + 'managed' => true, + 'country' => 'US', + 'external_account' => array( + 'object' => 'bank_account', + 'country' => 'US', + 'currency' => 'usd', + 'routing_number' => '110000000', + 'account_number' => '000123456789' + ), + 'legal_entity' => array( + 'type' => 'individual', + 'personal_id_number' => '000000000', + 'type' => 'individual', + 'dob' => array('year' => '1980', 'month' => '01', 'day' => '01'), + 'first_name' => 'John', + 'last_name' => 'Doe', + 'address' => array( + 'line1' => '1234 Main Street', + 'postal_code' => '94110', + 'city' => 'San Francisco' + ), + 'personal_address' => array( + 'line1' => '1234 Main Street', + 'postal_code' => '94110', + 'city' => 'San Francisco' + ) + ), + 'tos_acceptance' => array('date' => time(), 'ip' => '127.0.0.1') + ) + ); + } + /** * Verify that a plan with a given ID exists, or create a new one if it does * not. @@ -188,7 +227,7 @@ class TestCase extends \PHPUnit_Framework_TestCase } /** - * Genereate a semi-random string + * Generate a semi-random string */ protected static function generateRandomString($length = 24) { @@ -204,9 +243,9 @@ class TestCase extends \PHPUnit_Framework_TestCase /** * Generate a semi-random email. */ - protected static function generateRandomEmail($domain = 'bar.com') + protected static function generateRandomEmail() { - return self::generateRandomString().'@'.$domain; + return 'dev-platform-bots+php-'.self::generateRandomString(12).'@stripe.com'; } protected static function createTestBitcoinReceiver($email) diff --git a/packages/stripe-php/tests/ThreeDSecureTest.php b/vendor/stripe/stripe-php/tests/ThreeDSecureTest.php similarity index 100% rename from packages/stripe-php/tests/ThreeDSecureTest.php rename to vendor/stripe/stripe-php/tests/ThreeDSecureTest.php diff --git a/packages/stripe-php/tests/TokenTest.php b/vendor/stripe/stripe-php/tests/TokenTest.php similarity index 100% rename from packages/stripe-php/tests/TokenTest.php rename to vendor/stripe/stripe-php/tests/TokenTest.php diff --git a/vendor/stripe/stripe-php/tests/TransferReversalTest.php b/vendor/stripe/stripe-php/tests/TransferReversalTest.php new file mode 100644 index 00000000..86d74665 --- /dev/null +++ b/vendor/stripe/stripe-php/tests/TransferReversalTest.php @@ -0,0 +1,19 @@ +<?php + +namespace Stripe; + +class TransferReversalTest extends TestCase +{ + // The resource that was traditionally called "transfer" became a "payout" + // in API version 2017-04-06. We're testing traditional transfers here, so + // we force the API version just prior anywhere that we need to. + private $opts = array('stripe_version' => '2017-02-14'); + + public function testList() + { + $transfer = self::createTestTransfer(array(), $this->opts); + $all = $transfer->reversals->all(); + $this->assertSame(false, $all['has_more']); + $this->assertSame(0, count($all->data)); + } +} diff --git a/vendor/stripe/stripe-php/tests/TransferTest.php b/vendor/stripe/stripe-php/tests/TransferTest.php new file mode 100644 index 00000000..f4fd347d --- /dev/null +++ b/vendor/stripe/stripe-php/tests/TransferTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Stripe; + +class TransferTest extends TestCase +{ + // The resource that was traditionally called "transfer" became a "payout" + // in API version 2017-04-06. We're testing traditional transfers here, so + // we force the API version just prior anywhere that we need to. + private $opts = array('stripe_version' => '2017-02-14'); + + public function testCreate() + { + $transfer = self::createTestTransfer(array(), $this->opts); + $this->assertSame('transfer', $transfer->object); + } + + public function testRetrieve() + { + $transfer = self::createTestTransfer(array(), $this->opts); + $reloaded = Transfer::retrieve($transfer->id, $this->opts); + $this->assertSame($reloaded->id, $transfer->id); + } + + public function testTransferUpdateMetadata() + { + $transfer = self::createTestTransfer(array(), $this->opts); + + $transfer->metadata['test'] = 'foo bar'; + $transfer->save(); + + $updatedTransfer = Transfer::retrieve($transfer->id, $this->opts); + $this->assertSame('foo bar', $updatedTransfer->metadata['test']); + } + + public function testTransferUpdateMetadataAll() + { + $transfer = self::createTestTransfer(array(), $this->opts); + + $transfer->metadata = array('test' => 'foo bar'); + $transfer->save(); + + $updatedTransfer = Transfer::retrieve($transfer->id, $this->opts); + $this->assertSame('foo bar', $updatedTransfer->metadata['test']); + } +} diff --git a/vendor/stripe/stripe-php/tests/UtilDefaultLoggerTest.php b/vendor/stripe/stripe-php/tests/UtilDefaultLoggerTest.php new file mode 100644 index 00000000..711af03c --- /dev/null +++ b/vendor/stripe/stripe-php/tests/UtilDefaultLoggerTest.php @@ -0,0 +1,28 @@ +<?php + +// Test in a slightly different namespace than usual. See comment on +// `error_log` below. +namespace Stripe\Util; + +class UtilLoggerTest extends \Stripe\TestCase +{ + public function testDefaultLogger() + { + $logger = new DefaultLogger(); + $logger->error("message"); + + global $lastMessage; + $this->assertSame($lastMessage, "message"); + } +} + +// This is a little terrible, but unfortunately there's no clean way to stub a +// call to `error_log`. Here we overwrite it so that we can get the last arguments +// that went to it. This is obviously bad, but luckily it's constrained to +// being just in \Stripe\Util (i.e. won't interfere with PHPUnit for example) +// and _just_ present when tests are running. +function error_log($message) +{ + global $lastMessage; + $lastMessage = $message; +} diff --git a/vendor/stripe/stripe-php/tests/UtilTest.php b/vendor/stripe/stripe-php/tests/UtilTest.php new file mode 100644 index 00000000..4cec5f6a --- /dev/null +++ b/vendor/stripe/stripe-php/tests/UtilTest.php @@ -0,0 +1,87 @@ +<?php + +namespace Stripe; + +class UtilTest extends TestCase +{ + public function testIsList() + { + $list = array(5, 'nstaoush', array()); + $this->assertTrue(Util\Util::isList($list)); + + $notlist = array(5, 'nstaoush', array(), 'bar' => 'baz'); + $this->assertFalse(Util\Util::isList($notlist)); + } + + public function testThatPHPHasValueSemanticsForArrays() + { + $original = array('php-arrays' => 'value-semantics'); + $derived = $original; + $derived['php-arrays'] = 'reference-semantics'; + + $this->assertSame('value-semantics', $original['php-arrays']); + } + + public function testConvertStripeObjectToArrayIncludesId() + { + $customer = self::createTestCustomer(); + $this->assertTrue(array_key_exists("id", $customer->__toArray(true))); + } + + public function testUtf8() + { + // UTF-8 string + $x = "\xc3\xa9"; + $this->assertSame(Util\Util::utf8($x), $x); + + // Latin-1 string + $x = "\xe9"; + $this->assertSame(Util\Util::utf8($x), "\xc3\xa9"); + + // Not a string + $x = true; + $this->assertSame(Util\Util::utf8($x), $x); + } + + public function testUrlEncode() + { + $a = array( + 'my' => 'value', + 'that' => array('your' => 'example'), + 'bar' => 1, + 'baz' => null + ); + + $enc = Util\Util::urlEncode($a); + $this->assertSame('my=value&that%5Byour%5D=example&bar=1', $enc); + + $a = array('that' => array('your' => 'example', 'foo' => null)); + $enc = Util\Util::urlEncode($a); + $this->assertSame('that%5Byour%5D=example', $enc); + + $a = array('that' => 'example', 'foo' => array('bar', 'baz')); + $enc = Util\Util::urlEncode($a); + $this->assertSame('that=example&foo%5B%5D=bar&foo%5B%5D=baz', $enc); + + $a = array( + 'my' => 'value', + 'that' => array('your' => array('cheese', 'whiz', null)), + 'bar' => 1, + 'baz' => null + ); + + $enc = Util\Util::urlEncode($a); + $expected = 'my=value&that%5Byour%5D%5B%5D=cheese' + . '&that%5Byour%5D%5B%5D=whiz&bar=1'; + $this->assertSame($expected, $enc); + + // Ignores an empty array + $enc = Util\Util::urlEncode(array('foo' => array(), 'bar' => 'baz')); + $expected = 'bar=baz'; + $this->assertSame($expected, $enc); + + $a = array('foo' => array(array('bar' => 'baz'), array('bar' => 'bin'))); + $enc = Util\Util::urlEncode($a); + $this->assertSame('foo%5B0%5D%5Bbar%5D=baz&foo%5B1%5D%5Bbar%5D=bin', $enc); + } +} diff --git a/vendor/stripe/stripe-php/tests/WebhookTest.php b/vendor/stripe/stripe-php/tests/WebhookTest.php new file mode 100644 index 00000000..3363181b --- /dev/null +++ b/vendor/stripe/stripe-php/tests/WebhookTest.php @@ -0,0 +1,110 @@ +<?php + +namespace Stripe; + +class WebhookTest extends TestCase +{ + const EVENT_PAYLOAD = "{ + \"id\": \"evt_test_webhook\", + \"object\": \"event\" +}"; + const SECRET = "whsec_test_secret"; + + private function generateHeader($opts = array()) + { + $timestamp = array_key_exists('timestamp', $opts) ? $opts['timestamp'] : time(); + $payload = array_key_exists('payload', $opts) ? $opts['payload'] : self::EVENT_PAYLOAD; + $secret = array_key_exists('secret', $opts) ? $opts['secret'] : self::SECRET; + $scheme = array_key_exists('scheme', $opts) ? $opts['scheme'] : WebhookSignature::EXPECTED_SCHEME; + $signature = array_key_exists('signature', $opts) ? $opts['signature'] : null; + if ($signature === null) { + $signedPayload = "$timestamp.$payload"; + $signature = hash_hmac("sha256", $signedPayload, $secret); + } + return "t=$timestamp,$scheme=$signature"; + } + + public function testValidJsonAndHeader() + { + $sigHeader = $this->generateHeader(); + $event = Webhook::constructEvent(self::EVENT_PAYLOAD, $sigHeader, self::SECRET); + $this->assertEquals("evt_test_webhook", $event->id); + } + + /** + * @expectedException \UnexpectedValueException + */ + public function testInvalidJson() + { + $payload = "this is not valid JSON"; + $sigHeader = $this->generateHeader(array("payload" => $payload)); + Webhook::constructEvent($payload, $sigHeader, self::SECRET); + } + + /** + * @expectedException \Stripe\Error\SignatureVerification + */ + public function testValidJsonAndInvalidHeader() + { + $sigHeader = "bad_header"; + Webhook::constructEvent(self::EVENT_PAYLOAD, $sigHeader, self::SECRET); + } + + /** + * @expectedException \Stripe\Error\SignatureVerification + * @expectedExceptionMessage Unable to extract timestamp and signatures from header + */ + public function testMalformedHeader() + { + $sigHeader = "i'm not even a real signature header"; + WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET); + } + + /** + * @expectedException \Stripe\Error\SignatureVerification + * @expectedExceptionMessage No signatures found with expected scheme + */ + public function testNoSignaturesWithExpectedScheme() + { + $sigHeader = $this->generateHeader(array("scheme" => "v0")); + WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET); + } + + /** + * @expectedException \Stripe\Error\SignatureVerification + * @expectedExceptionMessage No signatures found matching the expected signature for payload + */ + public function testNoValidSignatureForPayload() + { + $sigHeader = $this->generateHeader(array("signature" => "bad_signature")); + WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET); + } + + /** + * @expectedException \Stripe\Error\SignatureVerification + * @expectedExceptionMessage Timestamp outside the tolerance zone + */ + public function testTimestampOutsideTolerance() + { + $sigHeader = $this->generateHeader(array("timestamp" => time() - 15)); + WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET, 10); + } + + public function testValidHeaderAndSignature() + { + $sigHeader = $this->generateHeader(); + $this->assertTrue(WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET, 10)); + } + + public function testHeaderContainsValidSignature() + { + $sigHeader = $this->generateHeader() . ",v1=bad_signature"; + $this->assertTrue(WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET, 10)); + } + + public function testTimestampOffButNoTolerance() + { + $sigHeader = $this->generateHeader(array("timestamp" => 12345)); + $this->assertTrue(WebhookSignature::verifyHeader(self::EVENT_PAYLOAD, $sigHeader, self::SECRET)); + } +} diff --git a/packages/stripe-php/tests/bootstrap.no_autoload.php b/vendor/stripe/stripe-php/tests/bootstrap.no_autoload.php similarity index 100% rename from packages/stripe-php/tests/bootstrap.no_autoload.php rename to vendor/stripe/stripe-php/tests/bootstrap.no_autoload.php diff --git a/packages/stripe-php/tests/bootstrap.php b/vendor/stripe/stripe-php/tests/bootstrap.php similarity index 100% rename from packages/stripe-php/tests/bootstrap.php rename to vendor/stripe/stripe-php/tests/bootstrap.php -- GitLab