1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 02:09:22 +02:00

Add Stripe Support

Bootstrap update
This commit is contained in:
daniel 2019-06-01 09:32:02 -03:00
parent fdd368f818
commit 5f6deb2d78
152 changed files with 17300 additions and 4214 deletions

0
locale/function.php Executable file → Normal file
View file

View file

@ -41,7 +41,7 @@ class CookieAlert extends PluginAbstract {
public function getEmptyDataObject() {
$obj = new stdClass();
$obj->text = '<b>This website uses cookies</b> &#x1F36A; so we can provide you with the best user experiense. Without these cookies, the website simply would not work.';
$obj->text = '<b>This website uses cookies</b> &#x1F36A; so we can provide you with the best user experience. Without these cookies, the website simply would not work.';
$obj->btnText = 'I agree';
return $obj;
}

17
plugin/StripeYPT/.gitignore vendored Normal file
View file

@ -0,0 +1,17 @@
# Mac OS X dumps these all over the place.
.DS_Store
# Ignore the SimpleTest library if it is installed to /test/.
/test/simpletest/
# Ignore the /vendor/ directory for people using composer
/vendor/
# If the vendor directory isn't being commited the composer.lock file should also be ignored
composer.lock
# Ignore PHPUnit coverage file
clover.xml
# Ignore IDE's configuration files
.idea

View file

@ -0,0 +1,690 @@
# Changelog
## 6.36.0 - 2019-05-22
* [#661](https://github.com/stripe/stripe-php/pull/661) Add constants for new TaxId types
* [#662](https://github.com/stripe/stripe-php/pull/662) Add constants for BalanceTransaction types
## 6.35.2 - 2019-05-20
* [#655](https://github.com/stripe/stripe-php/pull/655) Add constants for payment intent statuses
* [#659](https://github.com/stripe/stripe-php/pull/659) Fix PHPDoc for various nested Account actions
* [#660](https://github.com/stripe/stripe-php/pull/660) Fix various PHPDoc
## 6.35.1 - 2019-05-20
* [#658](https://github.com/stripe/stripe-php/pull/658) Use absolute value when checking timestamp tolerance
## 6.35.0 - 2019-05-14
* [#651](https://github.com/stripe/stripe-php/pull/651) Add support for the Capability resource and APIs
## 6.34.6 - 2019-05-13
* [#654](https://github.com/stripe/stripe-php/pull/654) Fix typo in definition of `Event::PAYMENT_METHOD_ATTACHED` constant
## 6.34.5 - 2019-05-06
* [#647](https://github.com/stripe/stripe-php/pull/647) Set the return type to static for more operations
## 6.34.4 - 2019-05-06
* [#650](https://github.com/stripe/stripe-php/pull/650) Add missing constants for Event types
## 6.34.3 - 2019-05-01
* [#644](https://github.com/stripe/stripe-php/pull/644) Update return type to `static` to improve static analysis
* [#645](https://github.com/stripe/stripe-php/pull/645) Fix constant for `payment_intent.payment_failed`
## 6.34.2 - 2019-04-26
* [#642](https://github.com/stripe/stripe-php/pull/642) Fix an issue where existing idempotency keys would be overwritten when using automatic retries
## 6.34.1 - 2019-04-25
* [#640](https://github.com/stripe/stripe-php/pull/640) Add missing phpdocs
## 6.34.0 - 2019-04-24
* [#626](https://github.com/stripe/stripe-php/pull/626) Add support for the `TaxRate` resource and APIs
* [#639](https://github.com/stripe/stripe-php/pull/639) Fix multiple phpdoc issues
## 6.33.0 - 2019-04-22
* [#630](https://github.com/stripe/stripe-php/pull/630) Add support for the `TaxId` resource and APIs
## 6.32.1 - 2019-04-19
* [#636](https://github.com/stripe/stripe-php/pull/636) Correct type of `$personId` in PHPDoc
## 6.32.0 - 2019-04-18
* [#621](https://github.com/stripe/stripe-php/pull/621) Add support for `CreditNote`
## 6.31.5 - 2019-04-12
* [#628](https://github.com/stripe/stripe-php/pull/628) Add constants for `person.*` event types
* [#628](https://github.com/stripe/stripe-php/pull/628) Add missing constants for `Account` and `Person`
## 6.31.4 - 2019-04-05
* [#624](https://github.com/stripe/stripe-php/pull/624) Fix encoding of nested parameters in multipart requests
## 6.31.3 - 2019-04-02
* [#623](https://github.com/stripe/stripe-php/pull/623) Only use HTTP/2 with curl >= 7.60.0
## 6.31.2 - 2019-03-25
* [#619](https://github.com/stripe/stripe-php/pull/619) Fix PHPDoc return types for list methods for nested resources
## 6.31.1 - 2019-03-22
* [#612](https://github.com/stripe/stripe-php/pull/612) Add a lot of constants
* [#614](https://github.com/stripe/stripe-php/pull/614) Add missing subscription status constants
## 6.31.0 - 2019-03-18
* [#600](https://github.com/stripe/stripe-php/pull/600) Add support for the `PaymentMethod` resource and APIs
* [#606](https://github.com/stripe/stripe-php/pull/606) Add support for retrieving a Checkout `Session`
* [#611](https://github.com/stripe/stripe-php/pull/611) Add support for deleting a Terminal `Location` and `Reader`
## 6.30.5 - 2019-03-11
* [#607](https://github.com/stripe/stripe-php/pull/607) Correctly handle case where a metadata key is called `metadata`
## 6.30.4 - 2019-02-27
* [#602](https://github.com/stripe/stripe-php/pull/602) Add `subscription_schedule` to `Subscription` for PHPDoc.
## 6.30.3 - 2019-02-26
* [#603](https://github.com/stripe/stripe-php/pull/603) Improve PHPDoc on the `Source` object to cover all types of Sources currently supported.
## 6.30.2 - 2019-02-25
* [#601](https://github.com/stripe/stripe-php/pull/601) Fix PHPDoc across multiple resources and add support for new events.
## 6.30.1 - 2019-02-16
* [#599](https://github.com/stripe/stripe-php/pull/599) Fix PHPDoc for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
## 6.30.0 - 2019-02-12
* [#590](https://github.com/stripe/stripe-php/pull/590) Add support for `SubscriptionSchedule` and `SubscriptionScheduleRevision`
## 6.29.3 - 2019-01-31
* [#592](https://github.com/stripe/stripe-php/pull/592) Some more PHPDoc fixes
## 6.29.2 - 2019-01-31
* [#591](https://github.com/stripe/stripe-php/pull/591) Fix PHPDoc for nested resources
## 6.29.1 - 2019-01-25
* [#566](https://github.com/stripe/stripe-php/pull/566) Fix dangling message contents
* [#586](https://github.com/stripe/stripe-php/pull/586) Don't overwrite `CURLOPT_HTTP_VERSION` option
## 6.29.0 - 2019-01-23
* [#579](https://github.com/stripe/stripe-php/pull/579) Rename `CheckoutSession` to `Session` and move it under the `Checkout` namespace. This is a breaking change, but we've reached out to affected merchants and all new merchants would use the new approach.
## 6.28.1 - 2019-01-21
* [#580](https://github.com/stripe/stripe-php/pull/580) Properly serialize `individual` on `Account` objects
## 6.28.0 - 2019-01-03
* [#576](https://github.com/stripe/stripe-php/pull/576) Add support for iterating directly over `Collection` instances
## 6.27.0 - 2018-12-21
* [#571](https://github.com/stripe/stripe-php/pull/571) Add support for the `CheckoutSession` resource
## 6.26.0 - 2018-12-11
* [#568](https://github.com/stripe/stripe-php/pull/568) Enable persistent connections
## 6.25.0 - 2018-12-10
* [#567](https://github.com/stripe/stripe-php/pull/567) Add support for account links
## 6.24.0 - 2018-11-28
* [#562](https://github.com/stripe/stripe-php/pull/562) Add support for the Review resource
* [#564](https://github.com/stripe/stripe-php/pull/564) Add event name constants for subscription schedule aborted/expiring
## 6.23.0 - 2018-11-27
* [#542](https://github.com/stripe/stripe-php/pull/542) Add support for `ValueList` and `ValueListItem` for Radar
## 6.22.1 - 2018-11-20
* [#561](https://github.com/stripe/stripe-php/pull/561) Add cast and some docs to telemetry introduced in 6.22.0/#549
## 6.22.0 - 2018-11-15
* [#549](https://github.com/stripe/stripe-php/pull/549) Add support for client telemetry
## 6.21.1 - 2018-11-12
* [#548](https://github.com/stripe/stripe-php/pull/548) Don't mutate `Exception` class properties from `OAuthBase` error
## 6.21.0 - 2018-11-08
* [#537](https://github.com/stripe/stripe-php/pull/537) Add new API endpoints for the `Invoice` resource.
## 6.20.1 - 2018-11-07
* [#546](https://github.com/stripe/stripe-php/pull/546) Drop files from the Composer package that aren't needed in the release
## 6.20.0 - 2018-10-30
* [#536](https://github.com/stripe/stripe-php/pull/536) Add support for the `Person` resource
* [#541](https://github.com/stripe/stripe-php/pull/541) Add support for the `WebhookEndpoint` resource
## 6.19.5 - 2018-10-17
* [#539](https://github.com/stripe/stripe-php/pull/539) Fix methods on `\Stripe\PaymentIntent` to properly pass arguments to the API.
## 6.19.4 - 2018-10-11
* [#534](https://github.com/stripe/stripe-php/pull/534) Fix PSR-4 autoloading for `\Stripe\FileUpload` class alias
## 6.19.3 - 2018-10-09
* [#530](https://github.com/stripe/stripe-php/pull/530) Add constants for `flow` (`FLOW_*`), `status` (`STATUS_*`) and `usage` (`USAGE_*`) on `\Stripe\Source`
## 6.19.2 - 2018-10-08
* [#531](https://github.com/stripe/stripe-php/pull/531) Store HTTP response headers in case-insensitive array
## 6.19.1 - 2018-09-25
* [#526](https://github.com/stripe/stripe-php/pull/526) Ignore null values in request parameters
## 6.19.0 - 2018-09-24
* [#523](https://github.com/stripe/stripe-php/pull/523) Add support for Stripe Terminal
## 6.18.0 - 2018-09-24
* [#520](https://github.com/stripe/stripe-php/pull/520) Rename `\Stripe\FileUpload` to `\Stripe\File`
## 6.17.2 - 2018-09-18
* [#522](https://github.com/stripe/stripe-php/pull/522) Fix warning when adding a new additional owner to an existing array
## 6.17.1 - 2018-09-14
* [#517](https://github.com/stripe/stripe-php/pull/517) Integer-index encode all sequential arrays
## 6.17.0 - 2018-09-05
* [#514](https://github.com/stripe/stripe-php/pull/514) Add support for reporting resources
## 6.16.0 - 2018-08-23
* [#509](https://github.com/stripe/stripe-php/pull/509) Add support for usage record summaries
## 6.15.0 - 2018-08-03
* [#504](https://github.com/stripe/stripe-php/pull/504) Add cancel support for topups
## 6.14.0 - 2018-08-02
* [#505](https://github.com/stripe/stripe-php/pull/505) Add support for file links
## 6.13.0 - 2018-07-31
* [#502](https://github.com/stripe/stripe-php/pull/502) Add `isDeleted()` method to `\Stripe\StripeObject`
## 6.12.0 - 2018-07-28
* [#501](https://github.com/stripe/stripe-php/pull/501) Add support for scheduled query runs (`\Stripe\Sigma\ScheduledQueryRun`) for Sigma
## 6.11.0 - 2018-07-26
* [#500](https://github.com/stripe/stripe-php/pull/500) Add support for Stripe Issuing
## 6.10.4 - 2018-07-19
* [#498](https://github.com/stripe/stripe-php/pull/498) Internal improvements to the `\Stripe\ApiResource.classUrl()` method
## 6.10.3 - 2018-07-16
* [#497](https://github.com/stripe/stripe-php/pull/497) Use HTTP/2 only for HTTPS requests
## 6.10.2 - 2018-07-11
* [#494](https://github.com/stripe/stripe-php/pull/494) Enable HTTP/2 support
## 6.10.1 - 2018-07-10
* [#493](https://github.com/stripe/stripe-php/pull/493) Add PHPDoc for `auto_advance` on `\Stripe\Invoice`
## 6.10.0 - 2018-06-28
* [#488](https://github.com/stripe/stripe-php/pull/488) Add support for `$appPartnerId` to `Stripe::setAppInfo()`
## 6.9.0 - 2018-06-28
* [#487](https://github.com/stripe/stripe-php/pull/487) Add support for payment intents
## 6.8.2 - 2018-06-24
* [#486](https://github.com/stripe/stripe-php/pull/486) Make `Account.deauthorize()` return the `StripeObject` from the API
## 6.8.1 - 2018-06-13
* [#472](https://github.com/stripe/stripe-php/pull/472) Added phpDoc for `ApiRequestor` and others, especially regarding thrown errors
## 6.8.0 - 2018-06-13
* [#481](https://github.com/stripe/stripe-php/pull/481) Add new `\Stripe\Discount` and `\Stripe\OrderItem` classes, add more PHPDoc describing object attributes
## 6.7.4 - 2018-05-29
* [#480](https://github.com/stripe/stripe-php/pull/480) PHPDoc changes for API version 2018-05-21 and the addition of the new `CHARGE_EXPIRED` event type
## 6.7.3 - 2018-05-28
* [#479](https://github.com/stripe/stripe-php/pull/479) Fix unnecessary traits on `\Stripe\InvoiceLineItem`
## 6.7.2 - 2018-05-28
* [#471](https://github.com/stripe/stripe-php/pull/471) Add `OBJECT_NAME` constant to all API resource classes, add `\Stripe\InvoiceLineItem` class
## 6.7.1 - 2018-05-13
* [#468](https://github.com/stripe/stripe-php/pull/468) Update fields in PHP docs for accuracy
## 6.7.0 - 2018-05-09
* [#466](https://github.com/stripe/stripe-php/pull/466) Add support for issuer fraud records
## 6.6.0 - 2018-04-11
* [#460](https://github.com/stripe/stripe-php/pull/460) Add support for flexible billing primitives
## 6.5.0 - 2018-04-05
* [#461](https://github.com/stripe/stripe-php/pull/461) Don't zero keys on non-`metadata` subobjects
## 6.4.2 - 2018-03-17
* [#458](https://github.com/stripe/stripe-php/pull/458) Add PHPDoc for `account` on `\Stripe\Event`
## 6.4.1 - 2018-03-02
* [#455](https://github.com/stripe/stripe-php/pull/455) Fix namespaces in PHPDoc
* [#456](https://github.com/stripe/stripe-php/pull/456) Fix namespaces for some exceptions
## 6.4.0 - 2018-02-28
* [#453](https://github.com/stripe/stripe-php/pull/453) Add constants for `reason` (`REASON_*`) and `status` (`STATUS_*`) on `\Stripe\Dispute`
## 6.3.2 - 2018-02-27
* [#452](https://github.com/stripe/stripe-php/pull/452) Add PHPDoc for `amount_paid` and `amount_remaining` on `\Stripe\Invoice`
## 6.3.1 - 2018-02-26
* [#443](https://github.com/stripe/stripe-php/pull/443) Add event types as constants to `\Stripe\Event` class
## 6.3.0 - 2018-02-23
* [#450](https://github.com/stripe/stripe-php/pull/450) Add support for `code` attribute on all Stripe exceptions
## 6.2.0 - 2018-02-21
* [#440](https://github.com/stripe/stripe-php/pull/440) Add support for topups
* [#442](https://github.com/stripe/stripe-php/pull/442) Fix PHPDoc for `\Stripe\Error\SignatureVerification`
## 6.1.0 - 2018-02-12
* [#435](https://github.com/stripe/stripe-php/pull/435) Fix header persistence on `Collection` objects
* [#436](https://github.com/stripe/stripe-php/pull/436) Introduce new `Idempotency` error class
## 6.0.0 - 2018-02-07
Major version release. List of backwards incompatible changes to watch out for:
+ The minimum PHP version is now 5.4.0. If you're using PHP 5.3 or older, consider upgrading to a more recent version.
* `\Stripe\AttachedObject` no longer exists. Attributes that used to be instances of `\Stripe\AttachedObject` (such as `metadata`) are now instances of `\Stripe\StripeObject`.
+ Attributes that used to be PHP arrays (such as `legal_entity->additional_owners` on `\Stripe\Account` instances) are now instances of `\Stripe\StripeObject`, except when they are empty. `\Stripe\StripeObject` has array semantics so this should not be an issue unless you are actively checking types.
* `\Stripe\Collection` now derives from `\Stripe\StripeObject` rather than from `\Stripe\ApiResource`.
Pull requests included in this release:
* [#410](https://github.com/stripe/stripe-php/pull/410) Drop support for PHP 5.3
* [#411](https://github.com/stripe/stripe-php/pull/411) Use traits for common API operations
* [#414](https://github.com/stripe/stripe-php/pull/414) Use short array syntax
* [#404](https://github.com/stripe/stripe-php/pull/404) Fix serialization logic
* [#417](https://github.com/stripe/stripe-php/pull/417) Remove `ExternalAccount` class
* [#418](https://github.com/stripe/stripe-php/pull/418) Increase test coverage
* [#421](https://github.com/stripe/stripe-php/pull/421) Update CA bundle and add script for future updates
* [#422](https://github.com/stripe/stripe-php/pull/422) Use vendored CA bundle for all requests
* [#428](https://github.com/stripe/stripe-php/pull/428) Support for automatic request retries
## 5.9.2 - 2018-02-07
* [#431](https://github.com/stripe/stripe-php/pull/431) Update PHPDoc @property tags for latest API version
## 5.9.1 - 2018-02-06
* [#427](https://github.com/stripe/stripe-php/pull/427) Add and update PHPDoc @property tags on all API resources
## 5.9.0 - 2018-01-17
* [#421](https://github.com/stripe/stripe-php/pull/421) Updated bundled CA certificates
* [#423](https://github.com/stripe/stripe-php/pull/423) Escape unsanitized input in OAuth example
## 5.8.0 - 2017-12-20
* [#403](https://github.com/stripe/stripe-php/pull/403) Add `__debugInfo()` magic method to `StripeObject`
## 5.7.0 - 2017-11-28
* [#390](https://github.com/stripe/stripe-php/pull/390) Remove some unsupported API methods
* [#391](https://github.com/stripe/stripe-php/pull/391) Alphabetize the list of API resources in `Util::convertToStripeObject()` and add missing resources
* [#393](https://github.com/stripe/stripe-php/pull/393) Fix expiry date update for card sources
## 5.6.0 - 2017-10-31
* [#386](https://github.com/stripe/stripe-php/pull/386) Support for exchange rates APIs
## 5.5.1 - 2017-10-30
* [#387](https://github.com/stripe/stripe-php/pull/387) Allow `personal_address_kana` and `personal_address_kanji` to be updated on an account
## 5.5.0 - 2017-10-27
* [#385](https://github.com/stripe/stripe-php/pull/385) Support for listing source transactions
## 5.4.0 - 2017-10-24
* [#383](https://github.com/stripe/stripe-php/pull/383) Add static methods to manipulate resources from parent
* `Account` gains methods for external accounts and login links (e.g. `createExternalAccount`, `createLoginLink`)
* `ApplicationFee` gains methods for refunds
* `Customer` gains methods for sources
* `Transfer` gains methods for reversals
## 5.3.0 - 2017-10-11
* [#378](https://github.com/stripe/stripe-php/pull/378) Rename source `delete` to `detach` (and deprecate the former)
## 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
## 4.2.0 - 2016-11-21
* Add retrieve method for 3-D Secure resources
## 4.1.1 - 2016-10-21
* Add docblock with model properties for `Plan`
## 4.1.0 - 2016-10-18
* Support for 403 status codes (permission denied)
## 4.0.1 - 2016-10-17
* Fix transfer reversal materialization
* Fixes for some property definitions in docblocks
## 4.0.0 - 2016-09-28
* Support for subscription items
* Drop attempt to force TLS 1.2: please note that this could be breaking if you're using old OS distributions or packages and upgraded recently (so please make sure to test your integration!)
## 3.23.0 - 2016-09-15
* Add support for Apple Pay domains
## 3.22.0 - 2016-09-13
* Add `Stripe::setAppInfo` to allow plugins to register user agent information
## 3.21.0 - 2016-08-25
* Add `Source` model for generic payment sources
## 3.20.0 - 2016-08-08
* Add `getDeclineCode` to card errors
## 3.19.0 - 2016-07-29
* Opt requests directly into TLS 1.2 where OpenSSL >= 1.0.1 (see #277 for context)
## 3.18.0 - 2016-07-28
* Add new `STATUS_` constants for subscriptions
## 3.17.1 - 2016-07-28
* Fix auto-paging iterator so that it plays nicely with `iterator_to_array`
## 3.17.0 - 2016-07-14
* Add field annotations to model classes for better editor hinting
## 3.16.0 - 2016-07-12
* Add `ThreeDSecure` model for 3-D secure payments
## 3.15.0 - 2016-06-29
* Add static `update` method to all resources that can be changed.
## 3.14.3 - 2016-06-20
* Make sure that cURL never sends `Expects: 100-continue`, even on large request bodies
## 3.14.2 - 2016-06-03
* Add `inventory` under `SKU` to list of keys that have nested data and can be updated
## 3.14.1 - 2016-05-27
* Fix some inconsistencies in PHPDoc
## 3.14.0 - 2016-05-25
* Add support for returning Relay orders
## 3.13.0 - 2016-05-04
* Add `list`, `create`, `update`, `retrieve`, and `delete` methods to the Subscription class
## 3.12.1 - 2016-04-07
* Additional check on value arrays for some extra safety
## 3.12.0 - 2016-03-31
* Fix bug `refreshFrom` on `StripeObject` would not take an `$opts` array
* Fix bug where `$opts` not passed to parent `save` method in `Account`
* Fix bug where non-existent variable was referenced in `reverse` in `Transfer`
* Update CA cert bundle for compatibility with OpenSSL versions below 1.0.1
## 3.11.0 - 2016-03-22
* Allow `CurlClient` to be initialized with default `CURLOPT_*` options
## 3.10.1 - 2016-03-22
* Fix bug where request params and options were ignored in `ApplicationFee`'s `refund.`
## 3.10.0 - 2016-03-15
* Add `reject` on `Account` to support the new API feature
## 3.9.2 - 2016-03-04
* Fix error when an object's metadata is set more than once
## 3.9.1 - 2016-02-24
* Fix encoding behavior of nested arrays for requests (see #227)
## 3.9.0 - 2016-02-09
* Add automatic pagination mechanism with `autoPagingIterator()`
* Allow global account ID to be set with `Stripe::setAccountId()`
## 3.8.0 - 2016-02-08
* Add `CountrySpec` model for looking up country payment information
## 3.7.1 - 2016-02-01
* Update bundled CA certs
## 3.7.0 - 2016-01-27
* Support deleting Relay products and SKUs
## 3.6.0 - 2016-01-05
* Allow configuration of HTTP client timeouts
## 3.5.0 - 2015-12-01
* Add a verification routine for external accounts
## 3.4.0 - 2015-09-14
* Products, SKUs, and Orders -- https://stripe.com/relay
## 3.3.0 - 2015-09-11
* Add support for 429 Rate Limit response
## 3.2.0 - 2015-08-17
* Add refund listing and retrieval without an associated charge
## 3.1.0 - 2015-08-03
* Add dispute listing and retrieval
* Add support for manage account deletion
## 3.0.0 - 2015-07-28
* Rename `\Stripe\Object` to `\Stripe\StripeObject` (PHP 7 compatibility)
* Rename `getCode` and `getParam` in exceptions to `getStripeCode` and `getStripeParam`
* Add support for calling `json_encode` on Stripe objects in PHP 5.4+
* Start supporting/testing PHP 7
## 2.3.0 - 2015-07-06
* Add request ID to all Stripe exceptions
## 2.2.0 - 2015-06-01
* Add support for Alipay accounts as sources
* Add support for bank accounts as sources (private beta)
* Add support for bank accounts and cards as external_accounts on Account objects
## 2.1.4 - 2015-05-13
* Fix CA certificate file path (thanks @lphilps & @matthewarkin)
## 2.1.3 - 2015-05-12
* Fix to account updating to permit `tos_acceptance` and `personal_address` to be set properly
* Fix to Transfer reversal creation (thanks @neatness!)
* Network requests are now done through a swappable class for easier mocking
## 2.1.2 - 2015-04-10
* Remove SSL cert revokation checking (all pre-Heartbleed certs have expired)
* Bug fixes to account updating
## 2.1.1 - 2015-02-27
* Support transfer reversals
## 2.1.0 - 2015-02-19
* Support new API version (2015-02-18)
* Added Bitcoin Receiever update and delete actions
* Edited tests to prefer "source" over "card" as per new API version
## 2.0.1 - 2015-02-16
* Fix to fetching endpoints that use a non-default baseUrl (`FileUpload`)
## 2.0.0 - 2015-02-14
* Bumped minimum version to 5.3.3
* Switched to Stripe namespace instead of Stripe_ class name prefiexes (thanks @chadicus!)
* Switched tests to PHPUnit (thanks @chadicus!)
* Switched style guide to PSR2 (thanks @chadicus!)
* Added $opts hash to the end of most methods: this permits passing 'idempotency_key', 'stripe_account', or 'stripe_version'. The last 2 will persist across multiple object loads.
* Added support for retrieving Account by ID
## 1.18.0 - 2015-01-21
* Support making bitcoin charges through BitcoinReceiver source object
## 1.17.5 - 2014-12-23
* Adding support for creating file uploads.
## 1.17.4 - 2014-12-15
* Saving objects fetched with a custom key now works (thanks @JustinHook & @jpasilan)
* Added methods for reporting charges as safe or fraudulent and for specifying the reason for refunds
## 1.17.3 - 2014-11-06
* Better handling of HHVM support for SSL certificate blacklist checking.
## 1.17.2 - 2014-09-23
* Coupons now are backed by a `Stripe_Coupon` instead of `Stripe_Object`, and support updating metadata
* Running operations (`create`, `retrieve`, `all`) on upcoming invoice items now works
## 1.17.1 - 2014-07-31
* Requests now send Content-Type header
## 1.17.0 - 2014-07-29
* Application Fee refunds now a list instead of array
* HHVM now works
* Small bug fixes (thanks @bencromwell & @fastest963)
* `__toString` now returns the name of the object in addition to its JSON representation
## 1.16.0 - 2014-06-17
* Add metadata for refunds and disputes
## 1.15.0 - 2014-05-28
* Support canceling transfers
## 1.14.1 - 2014-05-21
* Support cards for recipients.
## 1.13.1 - 2014-05-15
* Fix bug in account resource where `id` wasn't in the result
## 1.13.0 - 2014-04-10
* Add support for certificate blacklisting
* Update ca bundle
* Drop support for HHVM (Temporarily)
## 1.12.0 - 2014-04-01
* Add Stripe_RateLimitError for catching rate limit errors.
* Update to Zend coding style (thanks, @jpiasetz)
## 1.11.0 - 2014-01-29
* Add support for multiple subscriptions per customer
## 1.10.1 - 2013-12-02
* Add new ApplicationFee
## 1.9.1 - 2013-11-08
* Fix a bug where a null nestable object causes warnings to fire.
## 1.9.0 - 2013-10-16
* Add support for metadata API.
## 1.8.4 - 2013-09-18
* Add support for closing disputes.
## 1.8.3 - 2013-08-13
* Add new Balance and BalanceTransaction
## 1.8.2 - 2013-08-12
* Add support for unsetting attributes by updating to NULL. Setting properties to a blank string is now an error.
## 1.8.1 - 2013-07-12
* Add support for multiple cards API (Stripe API version 2013-07-12: https://stripe.com/docs/upgrades#2013-07-05)
## 1.8.0 - 2013-04-11
* Allow Transfers to be creatable
* Add new Recipient resource
## 1.7.15 - 2013-02-21
* Add 'id' to the list of permanent object attributes
## 1.7.14 - 2013-02-20
* Don't re-encode strings that are already encoded in UTF-8. If you were previously using plan or coupon objects with UTF-8 IDs, they may have been treated as ISO-8859-1 (Latin-1) and encoded to UTF-8 a 2nd time. You may now need to pass the IDs to utf8_encode before passing them to Stripe_Plan::retrieve or Stripe_Coupon::retrieve.
* Ensure that all input is encoded in UTF-8 before submitting it to Stripe's servers. (github issue #27)
## 1.7.13 - 2013-02-01
* Add support for passing options when retrieving Stripe objects e.g., Stripe_Charge::retrieve(array("id"=>"foo", "expand" => array("customer"))); Stripe_Charge::retrieve("foo") will continue to work
## 1.7.12 - 2013-01-15
* Add support for setting a Stripe API version override
## 1.7.11 - 2012-12-30
* Version bump to cleanup constants and such (fix issue #26)
## 1.7.10 - 2012-11-08
* Add support for updating charge disputes.
* Fix bug preventing retrieval of null attributes
## 1.7.9 - 2012-11-08
* Fix usage under autoloaders such as the one generated by composer (fix issue #22)
## 1.7.8 - 2012-10-30
* Add support for creating invoices.
* Add support for new invoice lines return format
* Add support for new list objects
## 1.7.7 - 2012-09-14
* Get all of the various version numbers in the repo in sync (no other changes)
## 1.7.6 - 2012-08-31
* Add update and pay methods to Invoice resource
## 1.7.5 - 2012-08-23
* Change internal function names so that Stripe_SingletonApiRequest is E_STRICT-clean (github issue #16)
## 1.7.4 - 2012-08-21
* Bugfix so that Stripe objects (e.g. Customer, Charge objects) used in API calls are transparently converted to their object IDs
## 1.7.3 - 2012-08-15
* Add new Account resource
## 1.7.2 - 2012-06-26
* Make clearer that you should be including lib/Stripe.php, not test/Stripe.php (github issue #14)
## 1.7.1 - 2012-05-24
* Add missing argument to Stripe_InvalidRequestError constructor in Stripe_ApiResource::instanceUrl. Fixes a warning when Stripe_ApiResource::instanceUrl is called on a resource with no ID (fix issue #12)
## 1.7.0 - 2012-05-17
* Support Composer and Packagist (github issue #9)
* Add new deleteDiscount method to Stripe_Customer
* Add new Transfer resource
* Switch from using HTTP Basic auth to Bearer auth. (Note: Stripe will support Basic auth for the indefinite future, but recommends Bearer auth when possible going forward)
* Numerous test suite improvements

21
plugin/StripeYPT/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2010-2019 Stripe, Inc. (https://stripe.com)
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.

242
plugin/StripeYPT/README.md Normal file
View file

@ -0,0 +1,242 @@
# Stripe PHP bindings
[![Build Status](https://travis-ci.org/stripe/stripe-php.svg?branch=master)](https://travis-ci.org/stripe/stripe-php)
[![Latest Stable Version](https://poser.pugx.org/stripe/stripe-php/v/stable.svg)](https://packagist.org/packages/stripe/stripe-php)
[![Total Downloads](https://poser.pugx.org/stripe/stripe-php/downloads.svg)](https://packagist.org/packages/stripe/stripe-php)
[![License](https://poser.pugx.org/stripe/stripe-php/license.svg)](https://packagist.org/packages/stripe/stripe-php)
[![Code Coverage](https://coveralls.io/repos/stripe/stripe-php/badge.svg?branch=master)](https://coveralls.io/r/stripe/stripe-php?branch=master)
You can sign up for a Stripe account at https://stripe.com.
## Requirements
PHP 5.4.0 and later.
## Composer
You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:
```bash
composer require stripe/stripe-php
```
To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
```php
require_once('vendor/autoload.php');
```
## Manual Installation
If you do not wish to use Composer, you can download the [latest release](https://github.com/stripe/stripe-php/releases). Then, to use the bindings, include the `init.php` file.
```php
require_once('/path/to/stripe-php/init.php');
```
## Dependencies
The bindings require the following extensions in order to work properly:
- [`curl`](https://secure.php.net/manual/en/book.curl.php), although you can use your own non-cURL client if you prefer
- [`json`](https://secure.php.net/manual/en/book.json.php)
- [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) (Multibyte String)
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
## Getting Started
Simple usage looks like:
```php
\Stripe\Stripe::setApiKey('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
$charge = \Stripe\Charge::create(['amount' => 2000, 'currency' => 'usd', 'source' => 'tok_189fqt2eZvKYlo2CTGBeg6Uq']);
echo $charge;
```
## Documentation
Please see https://stripe.com/docs/api for up-to-date documentation.
## Legacy Version Support
### PHP 5.3
If you are using PHP 5.3, you can download v5.9.2 ([zip](https://github.com/stripe/stripe-php/archive/v5.9.2.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v5.9.2.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
### PHP 5.2
If you are using PHP 5.2, you can download v1.18.0 ([zip](https://github.com/stripe/stripe-php/archive/v1.18.0.zip), [tar.gz](https://github.com/stripe/stripe-php/archive/v1.18.0.tar.gz)) from our [releases page](https://github.com/stripe/stripe-php/releases). This version will continue to work with new versions of the Stripe API for all common uses.
This legacy version may be included via `require_once("/path/to/stripe-php/lib/Stripe.php");`, and used like:
```php
Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$charge = Stripe_Charge::create(array('source' => 'tok_XXXXXXXX', 'amount' => 2000, 'currency' => 'usd'));
echo $charge;
```
## Custom Request Timeouts
*NOTE:* We do not recommend decreasing the timeout for non-read-only calls (e.g. charge creation), since even if you locally timeout, the request on Stripe's side can still complete. If you are decreasing timeouts on these calls, make sure to use [idempotency tokens](https://stripe.com/docs/api/php#idempotent_requests) to avoid executing the same transaction twice as a result of timeout retry logic.
To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.
```php
// set up your tweaked Curl client
$curl = new \Stripe\HttpClient\CurlClient();
$curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT
echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5
// tell Stripe to use the tweaked client
\Stripe\ApiRequestor::setHttpClient($curl);
// use the Stripe API client as you normally would
```
## Custom cURL Options (e.g. proxies)
Need to set a proxy for your requests? Pass in the requisite `CURLOPT_*` array to the CurlClient constructor, using the same syntax as `curl_stopt_array()`. This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.
```php
// set up your tweaked Curl client
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell Stripe to use the tweaked client
\Stripe\ApiRequestor::setHttpClient($curl);
```
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);
```
### Accessing response data
You can access the data from the last API response on any object via `getLastResponse()`.
```php
$charge = \Stripe\Charge::create(['amount' => 2000, 'currency' => 'usd', 'source' => 'tok_visa']);
echo $charge->getLastResponse()->headers['Request-Id'];
```
### 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](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`:
```php
$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]);
\Stripe\ApiRequestor::setHttpClient($curl);
```
### Per-request Configuration
For apps that need to use multiple keys during the lifetime of a process, like
one that uses [Stripe Connect][connect], it's also possible to set a
per-request key and/or account:
```php
\Stripe\Charge::all([], [
'api_key' => 'sk_test_...',
'stripe_account' => 'acct_...'
]);
\Stripe\Charge::retrieve("ch_18atAXCdGbJFKhCuBAa4532Z", [
'api_key' => 'sk_test_...',
'stripe_account' => 'acct_...'
]);
```
### Configuring CA Bundles
By default, the library will use its own internal bundle of known CA
certificates, but it's possible to configure your own:
```php
\Stripe\Stripe::setCABundlePath("path/to/ca/bundle");
```
### Configuring Automatic Retries
The library can be configured to automatically retry requests that fail due to
an intermittent network problem:
```php
\Stripe\Stripe::setMaxNetworkRetries(2);
```
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
retries are safe.
## Development
Get [Composer][composer]. For example, on Mac OS:
```bash
brew install composer
```
Install dependencies:
```bash
composer install
```
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
background terminal ([stripe-mock's README][stripe-mock] also contains
instructions for installing via Homebrew and other methods):
```bash
go get -u github.com/stripe/stripe-mock
stripe-mock
```
Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:
```bash
./vendor/bin/phpunit
```
Or to run an individual test file:
```bash
./vendor/bin/phpunit tests/UtilTest.php
```
Update bundled CA certificates from the [Mozilla cURL release][curl]:
```bash
./update_certs.php
```
## Attention plugin developers
Are you writing a plugin that integrates Stripe and embeds our library? Then please use the `setAppInfo` function to identify your plugin. For example:
```php
\Stripe\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
```
The method should be called once, before any request is sent to the API. The second and third parameters are optional.
### 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`.
[composer]: https://getcomposer.org/
[connect]: https://stripe.com/connect
[curl]: http://curl.haxx.se/docs/caextract.html
[psr3]: http://www.php-fig.org/psr/psr-3/
[idempotency-keys]: https://stripe.com/docs/api/php#idempotent_requests
[stripe-mock]: https://github.com/stripe/stripe-mock

View file

@ -0,0 +1,220 @@
<?php
global $global;
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
require_once $global['systemRootPath'] . 'plugin/StripeYPT/init.php';
class StripeYPT extends PluginAbstract {
public function getDescription() {
return "Stripe module for several purposes<br>
Go to Stripe dashboard Site here https://dashboard.stripe.com/test/apikeys (you must have Stripe account, of course)";
}
public function getName() {
return "StripeYPT";
}
public function getUUID() {
return "stripe09-c0b6-4264-85cb-47ae076d949f";
}
public function getPluginVersion() {
return "1.0";
}
public function getEmptyDataObject() {
$obj = new stdClass();
$obj->Publishablekey = "pk_test_aQT12wEjRLKhXgk77TX4ftfa";
$obj->Restrictedkey = "rk_test_kjyL5JaoAQwyiptuRlSzYJMZ00kRqXkLux";
$obj->disableSandbox = false;
return $obj;
}
private function start() {
global $global;
$obj = $this->getDataObject();
$notify_url = "{$global['webSiteRootURL']}plugin/StripeYPT/ipn.php";
\Stripe\Stripe::setApiKey($obj->Restrictedkey);
\Stripe\WebhookEndpoint::create([
"url" => $notify_url,
"enabled_events" => ["*"]
]);
}
public function setUpPayment($total = '1.00', $currency = "USD", $description = "") {
global $global;
$this->start();
$total = number_format(floatval($total), 2, "", "");
if (!empty($_POST['stripeToken'])) {
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => $total,
'currency' => $currency,
'description' => $description,
'source' => $token,
]);
return $charge;
}
return false;
}
static function getAmountFromPayment($payment) {
if (!is_object($payment)) {
return false;
}
if (empty($payment->amount)) {
return 0;
}
return self::addDot($payment->amount);
}
private static function addDot($value) {
$val = substr($payment->amount, 0, -2);
$cents = substr($payment->amount, -2);
return floatval("$val.$cents");
}
private static function removeDot($value) {
$value = floatval($value);
return number_format($value, 2, "", "");
}
static function getCurrencyFromPayment($payment) {
if (!is_object($payment)) {
return false;
}
return $payment->currency;
}
static function isPaymentOk($payment, $value, $currency) {
if (!is_object($payment)) {
return false;
}
if (empty($payment->paid)) {
return false;
}
if (strcasecmp($currency, self::getCurrencyFromPayment($payment)) !== 0) {
return false;
}
if ($value > self::getAmountFromPayment($payment)) {
return false;
}
return true;
}
public function createCostumer($users_id, $stripeToken) {
global $global;
$user = new User($users_id);
if (!empty($user)) {
return \Stripe\Customer::create([
"description" => "Customer [$users_id] " . $user->getNameIdentification(),
"source" => $stripeToken // obtained with Stripe.js
]);
}
return false;
}
public function getCostumerId($users_id, $stripeToken) {
$costumer = $this->createCostumer($users_id, $stripeToken);
if (!empty($costumer)) {
return $costumer->id;
}
return false;
}
private function createBillingPlan($total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = 'Base Agreement') {
global $global;
$this->start();
return \Stripe\Plan::create([
'currency' => $currency,
'interval' => $frequency,
'interval_count' => $interval,
"product" => [
"name" => $name,
"type" => "service"
],
'nickname' => $name,
'amount' => self::removeDot($total),
]);
}
static function updateBillingPlan($plans_id, $total = '1.00', $currency = "USD", $interval = 1, $name = 'Base Agreement') {
global $global;
if (empty($plan_id)) {
return false;
}
$this->start();
return \Stripe\Plan::update($plans_id, [
'currency' => $currency,
'interval_count' => $interval,
"product" => [
"name" => $name
],
'nickname' => $name,
'amount' => self::removeDot($total),
]);
}
public function setUpSubscription($plans_id, $stripeToken) {
if (!User::isLogged()) {
error_log("setUpSubscription: User not logged");
return false;
}
$subs = new SubscriptionPlansTable($plans_id);
$obj = YouPHPTubePlugin::getObjectData('YPTWallet');
if (empty($subs)) {
error_log("setUpSubscription: Plan not found");
return false;
}
// check costumer
$sub = Subscription::getOrCreateStripeSubscription(User::getId(), $plans_id);
if (empty($sub['stripe_costumer_id'])) {
$sub['stripe_costumer_id'] = $this->getCostumerId(User::getId(), $stripeToken);
if (empty($sub['stripe_costumer_id'])) {
error_log("setUpSubscription: Could not create a Stripe costumer");
return false;
}
Subscription::getOrCreateStripeSubscription(User::getId(), $plans_id, $sub['stripe_costumer_id']);
}
// check plan
if (empty($subs['stripe_plan_id'])) {
$interval = $subs->getHow_many_days();
$price = $subs->getPrice();
$paymentName = $subs->getName();
if (empty($paymentName)) {
$paymentName = "Recurrent Payment";
}
$plan = $this->createBillingPlan($price, $obj->currency, "day", $interval, $paymentName);
if (empty($plan)) {
error_log("setUpSubscription: could not create stripe plan");
return false;
}
$subs['stripe_plan_id'] = $plan->id;
}
$this->start();
return \Stripe\Subscription::create([
"customer" => $sub['stripe_costumer_id'],
"items" => [
[
"plan" => $subs['stripe_plan_id'],
],
]
]);
}
}

1
plugin/StripeYPT/VERSION Normal file
View file

@ -0,0 +1 @@
6.36.0

View file

@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
$autoload = (int)$argv[1];
$returnStatus = null;
if (!$autoload) {
// Modify composer to not autoload Stripe
$composer = json_decode(file_get_contents('composer.json'), true);
unset($composer['autoload']);
unset($composer['require-dev']['squizlabs/php_codesniffer']);
file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT));
}
passthru('composer update', $returnStatus);
if ($returnStatus !== 0) {
exit(1);
}
if ($autoload) {
// Only run CS on 1 of the 2 environments
passthru(
'./vendor/bin/phpcs --standard=PSR2 -n lib tests *.php',
$returnStatus
);
if ($returnStatus !== 0) {
exit(1);
}
}
$config = $autoload ? 'phpunit.xml' : 'phpunit.no_autoload.xml';
passthru("./vendor/bin/phpunit -c $config", $returnStatus);
if ($returnStatus !== 0) {
exit(1);
}

View file

@ -0,0 +1,37 @@
{
"name": "stripe/stripe-php",
"description": "Stripe PHP Library",
"keywords": [
"stripe",
"payment processing",
"api"
],
"homepage": "https://stripe.com/",
"license": "MIT",
"authors": [
{
"name": "Stripe and contributors",
"homepage": "https://github.com/stripe/stripe-php/contributors"
}
],
"require": {
"php": ">=5.4.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"php-coveralls/php-coveralls": "1.*",
"squizlabs/php_codesniffer": "~2.0",
"symfony/process": "~2.8"
},
"autoload": {
"psr-4": { "Stripe\\" : "lib/" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}

File diff suppressed because it is too large Load diff

142
plugin/StripeYPT/init.php Normal file
View file

@ -0,0 +1,142 @@
<?php
// Stripe singleton
require(dirname(__FILE__) . '/lib/Stripe.php');
// Utilities
require(dirname(__FILE__) . '/lib/Util/AutoPagingIterator.php');
require(dirname(__FILE__) . '/lib/Util/CaseInsensitiveArray.php');
require(dirname(__FILE__) . '/lib/Util/LoggerInterface.php');
require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
require(dirname(__FILE__) . '/lib/Util/RandomGenerator.php');
require(dirname(__FILE__) . '/lib/Util/RequestOptions.php');
require(dirname(__FILE__) . '/lib/Util/Set.php');
require(dirname(__FILE__) . '/lib/Util/Util.php');
// HttpClient
require(dirname(__FILE__) . '/lib/HttpClient/ClientInterface.php');
require(dirname(__FILE__) . '/lib/HttpClient/CurlClient.php');
// Errors
require(dirname(__FILE__) . '/lib/Error/Base.php');
require(dirname(__FILE__) . '/lib/Error/Api.php');
require(dirname(__FILE__) . '/lib/Error/ApiConnection.php');
require(dirname(__FILE__) . '/lib/Error/Authentication.php');
require(dirname(__FILE__) . '/lib/Error/Card.php');
require(dirname(__FILE__) . '/lib/Error/Idempotency.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');
// API operations
require(dirname(__FILE__) . '/lib/ApiOperations/All.php');
require(dirname(__FILE__) . '/lib/ApiOperations/Create.php');
require(dirname(__FILE__) . '/lib/ApiOperations/Delete.php');
require(dirname(__FILE__) . '/lib/ApiOperations/NestedResource.php');
require(dirname(__FILE__) . '/lib/ApiOperations/Request.php');
require(dirname(__FILE__) . '/lib/ApiOperations/Retrieve.php');
require(dirname(__FILE__) . '/lib/ApiOperations/Update.php');
// Plumbing
require(dirname(__FILE__) . '/lib/ApiResponse.php');
require(dirname(__FILE__) . '/lib/RequestTelemetry.php');
require(dirname(__FILE__) . '/lib/StripeObject.php');
require(dirname(__FILE__) . '/lib/ApiRequestor.php');
require(dirname(__FILE__) . '/lib/ApiResource.php');
require(dirname(__FILE__) . '/lib/SingletonApiResource.php');
// Stripe API Resources
require(dirname(__FILE__) . '/lib/Account.php');
require(dirname(__FILE__) . '/lib/AccountLink.php');
require(dirname(__FILE__) . '/lib/AlipayAccount.php');
require(dirname(__FILE__) . '/lib/ApplePayDomain.php');
require(dirname(__FILE__) . '/lib/ApplicationFee.php');
require(dirname(__FILE__) . '/lib/ApplicationFeeRefund.php');
require(dirname(__FILE__) . '/lib/Balance.php');
require(dirname(__FILE__) . '/lib/BalanceTransaction.php');
require(dirname(__FILE__) . '/lib/BankAccount.php');
require(dirname(__FILE__) . '/lib/BitcoinReceiver.php');
require(dirname(__FILE__) . '/lib/BitcoinTransaction.php');
require(dirname(__FILE__) . '/lib/Capability.php');
require(dirname(__FILE__) . '/lib/Card.php');
require(dirname(__FILE__) . '/lib/Charge.php');
require(dirname(__FILE__) . '/lib/Checkout/Session.php');
require(dirname(__FILE__) . '/lib/Collection.php');
require(dirname(__FILE__) . '/lib/CountrySpec.php');
require(dirname(__FILE__) . '/lib/Coupon.php');
require(dirname(__FILE__) . '/lib/CreditNote.php');
require(dirname(__FILE__) . '/lib/Customer.php');
require(dirname(__FILE__) . '/lib/Discount.php');
require(dirname(__FILE__) . '/lib/Dispute.php');
require(dirname(__FILE__) . '/lib/EphemeralKey.php');
require(dirname(__FILE__) . '/lib/Event.php');
require(dirname(__FILE__) . '/lib/ExchangeRate.php');
require(dirname(__FILE__) . '/lib/File.php');
require(dirname(__FILE__) . '/lib/FileLink.php');
require(dirname(__FILE__) . '/lib/FileUpload.php');
require(dirname(__FILE__) . '/lib/Invoice.php');
require(dirname(__FILE__) . '/lib/InvoiceItem.php');
require(dirname(__FILE__) . '/lib/InvoiceLineItem.php');
require(dirname(__FILE__) . '/lib/IssuerFraudRecord.php');
require(dirname(__FILE__) . '/lib/Issuing/Authorization.php');
require(dirname(__FILE__) . '/lib/Issuing/Card.php');
require(dirname(__FILE__) . '/lib/Issuing/CardDetails.php');
require(dirname(__FILE__) . '/lib/Issuing/Cardholder.php');
require(dirname(__FILE__) . '/lib/Issuing/Dispute.php');
require(dirname(__FILE__) . '/lib/Issuing/Transaction.php');
require(dirname(__FILE__) . '/lib/LoginLink.php');
require(dirname(__FILE__) . '/lib/Order.php');
require(dirname(__FILE__) . '/lib/OrderItem.php');
require(dirname(__FILE__) . '/lib/OrderReturn.php');
require(dirname(__FILE__) . '/lib/PaymentIntent.php');
require(dirname(__FILE__) . '/lib/PaymentMethod.php');
require(dirname(__FILE__) . '/lib/Payout.php');
require(dirname(__FILE__) . '/lib/Person.php');
require(dirname(__FILE__) . '/lib/Plan.php');
require(dirname(__FILE__) . '/lib/Product.php');
require(dirname(__FILE__) . '/lib/Radar/ValueList.php');
require(dirname(__FILE__) . '/lib/Radar/ValueListItem.php');
require(dirname(__FILE__) . '/lib/Recipient.php');
require(dirname(__FILE__) . '/lib/RecipientTransfer.php');
require(dirname(__FILE__) . '/lib/Refund.php');
require(dirname(__FILE__) . '/lib/Reporting/ReportRun.php');
require(dirname(__FILE__) . '/lib/Reporting/ReportType.php');
require(dirname(__FILE__) . '/lib/Review.php');
require(dirname(__FILE__) . '/lib/SKU.php');
require(dirname(__FILE__) . '/lib/Sigma/ScheduledQueryRun.php');
require(dirname(__FILE__) . '/lib/Source.php');
require(dirname(__FILE__) . '/lib/SourceTransaction.php');
require(dirname(__FILE__) . '/lib/Subscription.php');
require(dirname(__FILE__) . '/lib/SubscriptionItem.php');
require(dirname(__FILE__) . '/lib/SubscriptionSchedule.php');
require(dirname(__FILE__) . '/lib/SubscriptionScheduleRevision.php');
require(dirname(__FILE__) . '/lib/TaxId.php');
require(dirname(__FILE__) . '/lib/TaxRate.php');
require(dirname(__FILE__) . '/lib/Terminal/ConnectionToken.php');
require(dirname(__FILE__) . '/lib/Terminal/Location.php');
require(dirname(__FILE__) . '/lib/Terminal/Reader.php');
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
require(dirname(__FILE__) . '/lib/Token.php');
require(dirname(__FILE__) . '/lib/Topup.php');
require(dirname(__FILE__) . '/lib/Transfer.php');
require(dirname(__FILE__) . '/lib/TransferReversal.php');
require(dirname(__FILE__) . '/lib/UsageRecord.php');
require(dirname(__FILE__) . '/lib/UsageRecordSummary.php');
// OAuth
require(dirname(__FILE__) . '/lib/OAuth.php');
// Webhooks
require(dirname(__FILE__) . '/lib/Webhook.php');
require(dirname(__FILE__) . '/lib/WebhookEndpoint.php');
require(dirname(__FILE__) . '/lib/WebhookSignature.php');

20
plugin/StripeYPT/ipn.php Normal file
View file

@ -0,0 +1,20 @@
<?php
// check recurrent payments
header('Content-Type: application/json');
if (empty($global['systemRootPath'])) {
$global['systemRootPath'] = '../../';
}
require_once $global['systemRootPath'] . 'videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
error_log("StripeIPN Start");
$plugin = YouPHPTubePlugin::loadPluginIfEnabled("YPTWallet");
$walletObject = YouPHPTubePlugin::getObjectData("YPTWallet");
$stripe = YouPHPTubePlugin::loadPluginIfEnabled("StripeYPT");
//error_log("StripeIPN: ".json_encode($obj));
error_log("StripeIPN: POST ".json_encode($_POST));
error_log("StripeIPN: GET ".json_encode($_GET));
error_log("StripeIPN END");
?>

View file

@ -0,0 +1,393 @@
<?php
namespace Stripe;
/**
* Class Account
*
* @property string $id
* @property string $object
* @property mixed $business_profile
* @property string $business_type
* @property mixed $capabilities
* @property bool $charges_enabled
* @property mixed $company
* @property string $country
* @property int $created
* @property string $default_currency
* @property bool $details_submitted
* @property string $email
* @property Collection $external_accounts
* @property mixed $individual
* @property StripeObject $metadata
* @property bool $payouts_enabled
* @property mixed $requirements
* @property mixed $settings
* @property mixed $tos_acceptance
* @property string $type
*
* @package Stripe
*/
class Account extends ApiResource
{
const OBJECT_NAME = "account";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\NestedResource;
use ApiOperations\Retrieve {
retrieve as protected _retrieve;
}
use ApiOperations\Update;
/**
* Possible string representations of an account's business type.
* @link https://stripe.com/docs/api/accounts/object#account_object-business_type
*/
const BUSINESS_TYPE_COMPANY = 'company';
const BUSINESS_TYPE_INDIVIDUAL = 'individual';
/**
* Possible string representations of an account's capabilities.
* @link https://stripe.com/docs/api/accounts/object#account_object-capabilities
*/
const CAPABILITY_CARD_PAYMENTS = 'card_payments';
const CAPABILITY_LEGACY_PAYMENTS = 'legacy_payments';
const CAPABILITY_PLATFORM_PAYMENTS = 'platform_payments';
/**
* Possible string representations of an account's capability status.
* @link https://stripe.com/docs/api/accounts/object#account_object-capabilities
*/
const CAPABILITY_STATUS_ACTIVE = 'active';
const CAPABILITY_STATUS_INACTIVE = 'inactive';
const CAPABILITY_STATUS_PENDING = 'pending';
/**
* Possible string representations of an account's type.
* @link https://stripe.com/docs/api/accounts/object#account_object-type
*/
const TYPE_CUSTOM = 'custom';
const TYPE_EXPRESS = 'express';
const TYPE_STANDARD = 'standard';
public static function getSavedNestedResources()
{
static $savedNestedResources = null;
if ($savedNestedResources === null) {
$savedNestedResources = new Util\Set([
'external_account',
'bank_account',
]);
}
return $savedNestedResources;
}
const PATH_CAPABILITIES = '/capabilities';
const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';
const PATH_LOGIN_LINKS = '/login_links';
const PATH_PERSONS = '/persons';
public function instanceUrl()
{
if ($this['id'] === null) {
return '/v1/account';
} else {
return parent::instanceUrl();
}
}
/**
* @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
*/
public static function retrieve($id = null, $opts = null)
{
if (!$opts && is_string($id) && substr($id, 0, 3) === 'sk_') {
$opts = $id;
$id = null;
}
return self::_retrieve($id, $opts);
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Account The rejected account.
*/
public function reject($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/reject';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $clientId
* @param array|string|null $opts
*
* @return StripeObject Object containing the response from the API.
*/
public function deauthorize($clientId = null, $opts = null)
{
$params = [
'client_id' => $clientId,
'stripe_user_id' => $this->id,
];
return OAuth::deauthorize($params, $opts);
}
/*
* Capabilities methods
* We can not add the capabilities() method today as the Account object already has a
* capabilities property which is a hash and not the sub-list of capabilities.
*/
/**
* @param string $id The ID of the account to which the capability belongs.
* @param string $capabilityId The ID of the capability to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return Capability
*/
public static function retrieveCapability($id, $capabilityId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
}
/**
* @param string $id The ID of the account to which the capability belongs.
* @param string $capabilityId The ID of the capability to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return Capability
*/
public static function updateCapability($id, $capabilityId, $params = null, $opts = null)
{
return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
}
/**
* @param string $id The ID of the account on which to retrieve the capabilities.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of capabilities.
*/
public static function allCapabilities($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_CAPABILITIES, $params, $opts);
}
/**
* @param string $id The ID of the account on which to create the external account.
* @param array|null $params
* @param array|string|null $opts
*
* @return BankAccount|Card
*/
public static function createExternalAccount($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
}
/**
* @param string $id The ID of the account to which the external account belongs.
* @param string $externalAccountId The ID of the external account to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return BankAccount|Card
*/
public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}
/**
* @param string $id The ID of the account to which the external account belongs.
* @param string $externalAccountId The ID of the external account to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return BankAccount|Card
*/
public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}
/**
* @param string $id The ID of the account to which the external account belongs.
* @param string $externalAccountId The ID of the external account to delete.
* @param array|null $params
* @param array|string|null $opts
*
* @return BankAccount|Card
*/
public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
return self::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}
/**
* @param string $id The ID of the account on which to retrieve the external accounts.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of external accounts (BankAccount or Card).
*/
public static function allExternalAccounts($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
}
/**
* @param string $id The ID of the account on which to create the login link.
* @param array|null $params
* @param array|string|null $opts
*
* @return LoginLink
*/
public static function createLoginLink($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_LOGIN_LINKS, $params, $opts);
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return Collection The list of persons.
*/
public function persons($params = null, $options = null)
{
$url = $this->instanceUrl() . '/persons';
list($response, $opts) = $this->_request('get', $url, $params, $options);
$obj = Util\Util::convertToStripeObject($response, $opts);
$obj->setLastResponse($response);
return $obj;
}
/**
* @param string $id The ID of the account on which to create the person.
* @param array|null $params
* @param array|string|null $opts
*
* @return Person
*/
public static function createPerson($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_PERSONS, $params, $opts);
}
/**
* @param string $id The ID of the account to which the person belongs.
* @param string $personId The ID of the person to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return Person
*/
public static function retrievePerson($id, $personId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}
/**
* @param string $id The ID of the account to which the person belongs.
* @param string $personId The ID of the person to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return Person
*/
public static function updatePerson($id, $personId, $params = null, $opts = null)
{
return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}
/**
* @param string $id The ID of the account to which the person belongs.
* @param string $personId The ID of the person to delete.
* @param array|null $params
* @param array|string|null $opts
*
* @return Person
*/
public static function deletePerson($id, $personId, $params = null, $opts = null)
{
return self::_deleteNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}
/**
* @param string $id The ID of the account on which to retrieve the persons.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of persons.
*/
public static function allPersons($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_PERSONS, $params, $opts);
}
public function serializeParameters($force = false)
{
$update = parent::serializeParameters($force);
if (isset($this->_values['legal_entity'])) {
$entity = $this['legal_entity'];
if (isset($entity->_values['additional_owners'])) {
$owners = $entity['additional_owners'];
$entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
$entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
$update['legal_entity'] = $entityUpdate;
}
}
if (isset($this->_values['individual'])) {
$individual = $this['individual'];
if (($individual instanceof Person) && !isset($update['individual'])) {
$update['individual'] = $individual->serializeParameters($force);
}
}
return $update;
}
private function serializeAdditionalOwners($legalEntity, $additionalOwners)
{
if (isset($legalEntity->_originalValues['additional_owners'])) {
$originalValue = $legalEntity->_originalValues['additional_owners'];
} else {
$originalValue = [];
}
if (($originalValue) && (count($originalValue) > count($additionalOwners))) {
throw new \InvalidArgumentException(
"You cannot delete an item from an array, you must instead set a new array"
);
}
$updateArr = [];
foreach ($additionalOwners as $i => $v) {
$update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;
if ($update !== []) {
if (!$originalValue ||
!array_key_exists($i, $originalValue) ||
($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
$updateArr[$i] = $update;
}
}
}
return $updateArr;
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Stripe;
/**
* Class AccountLink
*
* @property string $object
* @property int $created
* @property int $expires_at
* @property string $url
*
* @package Stripe
*/
class AccountLink extends ApiResource
{
const OBJECT_NAME = "account_link";
use ApiOperations\Create;
}

View file

@ -0,0 +1,72 @@
<?php
namespace Stripe;
/**
* Class AlipayAccount
*
* @package Stripe
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
class AlipayAccount extends ApiResource
{
const OBJECT_NAME = "alipay_account";
use ApiOperations\Delete;
use ApiOperations\Update;
/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} else {
$msg = "Alipay accounts cannot be accessed without a customer ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}
/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Retrieve an Alipay account using \$customer->sources->retrieve('alipay_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*
* @deprecated Alipay accounts are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/alipay
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Call save() on \$customer->sources->retrieve('alipay_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for listable resources. Adds a `all()` static method to the class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait All
{
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return \Stripe\Collection of ApiResources
*/
public static function all($params = null, $opts = null)
{
self::_validateParams($params);
$url = static::classUrl();
list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
if (!is_a($obj, 'Stripe\\Collection')) {
$class = get_class($obj);
$message = "Expected type \"Stripe\\Collection\", got \"$class\" instead";
throw new \Stripe\Error\Api($message);
}
$obj->setLastResponse($response);
$obj->setRequestParams($params);
return $obj;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for creatable resources. Adds a `create()` static method to the class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Create
{
/**
* @param array|null $params
* @param array|string|null $options
*
* @return static The created resource.
*/
public static function create($params = null, $options = null)
{
self::_validateParams($params);
$url = static::classUrl();
list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for deletable resources. Adds a `delete()` method to the class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Delete
{
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return static The deleted resource.
*/
public function delete($params = null, $opts = null)
{
self::_validateParams($params);
$url = $this->instanceUrl();
list($response, $opts) = $this->_request('delete', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,118 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for resources that have nested resources.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait NestedResource
{
/**
* @param string $method
* @param string $url
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _nestedResourceOperation($method, $url, $params = null, $options = null)
{
self::_validateParams($params);
list($response, $opts) = static::_staticRequest($method, $url, $params, $options);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}
/**
* @param string $id
* @param string $nestedPath
* @param string|null $nestedId
*
* @return string
*/
protected static function _nestedResourceUrl($id, $nestedPath, $nestedId = null)
{
$url = static::resourceUrl($id) . $nestedPath;
if ($nestedId !== null) {
$url .= "/$nestedId";
}
return $url;
}
/**
* @param string $id
* @param string $nestedPath
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _createNestedResource($id, $nestedPath, $params = null, $options = null)
{
$url = static::_nestedResourceUrl($id, $nestedPath);
return self::_nestedResourceOperation('post', $url, $params, $options);
}
/**
* @param string $id
* @param string $nestedPath
* @param string|null $nestedId
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
{
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
return self::_nestedResourceOperation('get', $url, $params, $options);
}
/**
* @param string $id
* @param string $nestedPath
* @param string|null $nestedId
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _updateNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
{
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
return self::_nestedResourceOperation('post', $url, $params, $options);
}
/**
* @param string $id
* @param string $nestedPath
* @param string|null $nestedId
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _deleteNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
{
$url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
return self::_nestedResourceOperation('delete', $url, $params, $options);
}
/**
* @param string $id
* @param string $nestedPath
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\StripeObject
*/
protected static function _allNestedResources($id, $nestedPath, $params = null, $options = null)
{
$url = static::_nestedResourceUrl($id, $nestedPath);
return self::_nestedResourceOperation('get', $url, $params, $options);
}
}

View file

@ -0,0 +1,61 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for resources that need to make API requests.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Request
{
/**
* @param array|null|mixed $params The list of parameters to validate
*
* @throws \Stripe\Error\Api if $params exists and is not an array
*/
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(['amount' => 100, "
. "'currency' => 'usd', 'source' => 'tok_1234'])\")";
throw new \Stripe\Error\Api($message);
}
}
/**
* @param string $method HTTP method ('get', 'post', etc.)
* @param string $url URL for the request
* @param array $params list of parameters for the request
* @param array|string|null $options
*
* @return array tuple containing (the JSON response, $options)
*/
protected function _request($method, $url, $params = [], $options = null)
{
$opts = $this->_opts->merge($options);
list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
$this->setLastResponse($resp);
return [$resp->json, $options];
}
/**
* @param string $method HTTP method ('get', 'post', etc.)
* @param string $url URL for the request
* @param array $params list of parameters for the request
* @param array|string|null $options
*
* @return array tuple containing (the JSON response, $options)
*/
protected static function _staticRequest($method, $url, $params, $options)
{
$opts = \Stripe\Util\RequestOptions::parse($options);
$baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl();
$requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl);
list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers);
$opts->discardNonPersistentHeaders();
return [$response, $opts];
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for retrievable resources. Adds a `retrieve()` static method to the
* class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Retrieve
{
/**
* @param array|string $id The ID of the API resource to retrieve,
* or an options array containing an `id` key.
* @param array|string|null $opts
*
* @return static
*/
public static function retrieve($id, $opts = null)
{
$opts = \Stripe\Util\RequestOptions::parse($opts);
$instance = new static($id, $opts);
$instance->refresh();
return $instance;
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Stripe\ApiOperations;
/**
* Trait for updatable resources. Adds an `update()` static method and a
* `save()` method to the class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Update
{
/**
* @param string $id The ID of the resource to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return static The updated resource.
*/
public static function update($id, $params = null, $opts = null)
{
self::_validateParams($params);
$url = static::resourceUrl($id);
list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}
/**
* @param array|string|null $opts
*
* @return static The saved resource.
*/
public function save($opts = null)
{
$params = $this->serializeParameters();
if (count($params) > 0) {
$url = $this->instanceUrl();
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
}
return $this;
}
}

View file

@ -0,0 +1,508 @@
<?php
namespace Stripe;
/**
* Class ApiRequestor
*
* @package Stripe
*/
class ApiRequestor
{
/**
* @var string|null
*/
private $_apiKey;
/**
* @var string
*/
private $_apiBase;
/**
* @var HttpClient\ClientInterface
*/
private static $_httpClient;
/**
* @var RequestTelemetry
*/
private static $requestTelemetry;
/**
* ApiRequestor constructor.
*
* @param string|null $apiKey
* @param string|null $apiBase
*/
public function __construct($apiKey = null, $apiBase = null)
{
$this->_apiKey = $apiKey;
if (!$apiBase) {
$apiBase = Stripe::$apiBase;
}
$this->_apiBase = $apiBase;
}
/**
* Creates a telemetry json blob for use in 'X-Stripe-Client-Telemetry' headers
* @static
*
* @param RequestTelemetry $requestTelemetry
* @return string
*/
private static function _telemetryJson($requestTelemetry)
{
$payload = array(
'last_request_metrics' => array(
'request_id' => $requestTelemetry->requestId,
'request_duration_ms' => $requestTelemetry->requestDuration,
));
$result = json_encode($payload);
if ($result != false) {
return $result;
} else {
Stripe::getLogger()->error("Serializing telemetry payload failed!");
return "{}";
}
}
/**
* @static
*
* @param ApiResource|bool|array|mixed $d
*
* @return ApiResource|array|string|mixed
*/
private static function _encodeObjects($d)
{
if ($d instanceof ApiResource) {
return Util\Util::utf8($d->id);
} elseif ($d === true) {
return 'true';
} elseif ($d === false) {
return 'false';
} elseif (is_array($d)) {
$res = [];
foreach ($d as $k => $v) {
$res[$k] = self::_encodeObjects($v);
}
return $res;
} else {
return Util\Util::utf8($d);
}
}
/**
* @param string $method
* @param string $url
* @param array|null $params
* @param array|null $headers
*
* @return array An array whose first element is an API response and second
* element is the API key used to make the request.
* @throws Error\Api
* @throws Error\Authentication
* @throws Error\Card
* @throws Error\InvalidRequest
* @throws Error\OAuth\InvalidClient
* @throws Error\OAuth\InvalidGrant
* @throws Error\OAuth\InvalidRequest
* @throws Error\OAuth\InvalidScope
* @throws Error\OAuth\UnsupportedGrantType
* @throws Error\OAuth\UnsupportedResponseType
* @throws Error\Permission
* @throws Error\RateLimit
* @throws Error\Idempotency
* @throws Error\ApiConnection
*/
public function request($method, $url, $params = null, $headers = null)
{
$params = $params ?: [];
$headers = $headers ?: [];
list($rbody, $rcode, $rheaders, $myApiKey) =
$this->_requestRaw($method, $url, $params, $headers);
$json = $this->_interpretResponse($rbody, $rcode, $rheaders);
$resp = new ApiResponse($rbody, $rcode, $rheaders, $json);
return [$resp, $myApiKey];
}
/**
* @param string $rbody A JSON string.
* @param int $rcode
* @param array $rheaders
* @param array $resp
*
* @throws Error\InvalidRequest if the error is caused by the user.
* @throws Error\Authentication if the error is caused by a lack of
* permissions.
* @throws Error\Permission if the error is caused by insufficient
* permissions.
* @throws Error\Card if the error is the error code is 402 (payment
* required)
* @throws Error\InvalidRequest if the error is caused by the user.
* @throws Error\Idempotency if the error is caused by an idempotency key.
* @throws Error\OAuth\InvalidClient
* @throws Error\OAuth\InvalidGrant
* @throws Error\OAuth\InvalidRequest
* @throws Error\OAuth\InvalidScope
* @throws Error\OAuth\UnsupportedGrantType
* @throws Error\OAuth\UnsupportedResponseType
* @throws Error\Permission if the error is caused by insufficient
* permissions.
* @throws Error\RateLimit if the error is caused by too many requests
* hitting the API.
* @throws Error\Api otherwise.
*/
public function handleErrorResponse($rbody, $rcode, $rheaders, $resp)
{
if (!is_array($resp) || !isset($resp['error'])) {
$msg = "Invalid response object from API: $rbody "
. "(HTTP response code was $rcode)";
throw new Error\Api($msg, $rcode, $rbody, $resp, $rheaders);
}
$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;
}
/**
* @static
*
* @param string $rbody
* @param int $rcode
* @param array $rheaders
* @param array $resp
* @param array $errorData
*
* @return Error\RateLimit|Error\Idempotency|Error\InvalidRequest|Error\Authentication|Error\Card|Error\Permission|Error\Api
*/
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;
$type = isset($errorData['type']) ? $errorData['type'] : 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') {
return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
}
if ($type == 'idempotency_error') {
return new Error\Idempotency($msg, $rcode, $rbody, $resp, $rheaders);
}
// intentional fall-through
case 404:
return new Error\InvalidRequest($msg, $param, $rcode, $rbody, $resp, $rheaders);
case 401:
return new Error\Authentication($msg, $rcode, $rbody, $resp, $rheaders);
case 402:
return new Error\Card($msg, $param, $code, $rcode, $rbody, $resp, $rheaders);
case 403:
return new Error\Permission($msg, $rcode, $rbody, $resp, $rheaders);
case 429:
return new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
default:
return new Error\Api($msg, $rcode, $rbody, $resp, $rheaders);
}
}
/**
* @static
*
* @param string|bool $rbody
* @param int $rcode
* @param array $rheaders
* @param array $resp
* @param string $errorCode
*
* @return null|Error\OAuth\InvalidClient|Error\OAuth\InvalidGrant|Error\OAuth\InvalidRequest|Error\OAuth\InvalidScope|Error\OAuth\UnsupportedGrantType|Error\OAuth\UnsupportedResponseType
*/
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;
}
/**
* @static
*
* @param null|array $appInfo
*
* @return null|string
*/
private static function _formatAppInfo($appInfo)
{
if ($appInfo !== null) {
$string = $appInfo['name'];
if ($appInfo['version'] !== null) {
$string .= '/' . $appInfo['version'];
}
if ($appInfo['url'] !== null) {
$string .= ' (' . $appInfo['url'] . ')';
}
return $string;
} else {
return null;
}
}
/**
* @static
*
* @param string $apiKey
* @param null $clientInfo
*
* @return array
*/
private static function _defaultHeaders($apiKey, $clientInfo = null)
{
$uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION;
$langVersion = phpversion();
$uname = php_uname();
$appInfo = Stripe::getAppInfo();
$ua = [
'bindings_version' => Stripe::VERSION,
'lang' => 'php',
'lang_version' => $langVersion,
'publisher' => 'stripe',
'uname' => $uname,
];
if ($clientInfo) {
$ua = array_merge($clientInfo, $ua);
}
if ($appInfo !== null) {
$uaString .= ' ' . self::_formatAppInfo($appInfo);
$ua['application'] = $appInfo;
}
$defaultHeaders = [
'X-Stripe-Client-User-Agent' => json_encode($ua),
'User-Agent' => $uaString,
'Authorization' => 'Bearer ' . $apiKey,
];
return $defaultHeaders;
}
/**
* @param string $method
* @param string $url
* @param array $params
* @param array $headers
*
* @return array
* @throws Error\Api
* @throws Error\ApiConnection
* @throws Error\Authentication
*/
private function _requestRaw($method, $url, $params, $headers)
{
$myApiKey = $this->_apiKey;
if (!$myApiKey) {
$myApiKey = Stripe::$apiKey;
}
if (!$myApiKey) {
$msg = 'No API key provided. (HINT: set your API key using '
. '"Stripe::setApiKey(<API-KEY>)". You can generate API keys from '
. 'the Stripe web interface. See https://stripe.com/api for '
. 'details, or email support@stripe.com if you have any questions.';
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, $clientUAInfo);
if (Stripe::$apiVersion) {
$defaultHeaders['Stripe-Version'] = Stripe::$apiVersion;
}
if (Stripe::$accountId) {
$defaultHeaders['Stripe-Account'] = Stripe::$accountId;
}
if (Stripe::$enableTelemetry && self::$requestTelemetry != null) {
$defaultHeaders["X-Stripe-Client-Telemetry"] = self::_telemetryJson(self::$requestTelemetry);
}
$hasFile = false;
$hasCurlFile = class_exists('\CURLFile', false);
foreach ($params as $k => $v) {
if (is_resource($v)) {
$hasFile = true;
$params[$k] = self::_processResourceParam($v, $hasCurlFile);
} elseif ($hasCurlFile && $v instanceof \CURLFile) {
$hasFile = true;
}
}
if ($hasFile) {
$defaultHeaders['Content-Type'] = 'multipart/form-data';
} else {
$defaultHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
}
$combinedHeaders = array_merge($defaultHeaders, $headers);
$rawHeaders = [];
foreach ($combinedHeaders as $header => $value) {
$rawHeaders[] = $header . ': ' . $value;
}
$requestStartMs = Util\Util::currentTimeMillis();
list($rbody, $rcode, $rheaders) = $this->httpClient()->request(
$method,
$absUrl,
$rawHeaders,
$params,
$hasFile
);
if (array_key_exists('request-id', $rheaders)) {
self::$requestTelemetry = new RequestTelemetry(
$rheaders['request-id'],
Util\Util::currentTimeMillis() - $requestStartMs
);
}
return [$rbody, $rcode, $rheaders, $myApiKey];
}
/**
* @param resource $resource
* @param bool $hasCurlFile
*
* @return \CURLFile|string
* @throws Error\Api
*/
private function _processResourceParam($resource, $hasCurlFile)
{
if (get_resource_type($resource) !== 'stream') {
throw new Error\Api(
'Attempted to upload a resource that is not a stream'
);
}
$metaData = stream_get_meta_data($resource);
if ($metaData['wrapper_type'] !== 'plainfile') {
throw new Error\Api(
'Only plainfile resource streams are supported'
);
}
if ($hasCurlFile) {
// We don't have the filename or mimetype, but the API doesn't care
return new \CURLFile($metaData['uri']);
} else {
return '@'.$metaData['uri'];
}
}
/**
* @param string $rbody
* @param int $rcode
* @param array $rheaders
*
* @return mixed
* @throws Error\Api
* @throws Error\Authentication
* @throws Error\Card
* @throws Error\InvalidRequest
* @throws Error\OAuth\InvalidClient
* @throws Error\OAuth\InvalidGrant
* @throws Error\OAuth\InvalidRequest
* @throws Error\OAuth\InvalidScope
* @throws Error\OAuth\UnsupportedGrantType
* @throws Error\OAuth\UnsupportedResponseType
* @throws Error\Permission
* @throws Error\RateLimit
* @throws Error\Idempotency
*/
private function _interpretResponse($rbody, $rcode, $rheaders)
{
$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, json_last_error() was $jsonError)";
throw new Error\Api($msg, $rcode, $rbody);
}
if ($rcode < 200 || $rcode >= 300) {
$this->handleErrorResponse($rbody, $rcode, $rheaders, $resp);
}
return $resp;
}
/**
* @static
*
* @param HttpClient\ClientInterface $client
*/
public static function setHttpClient($client)
{
self::$_httpClient = $client;
}
/**
* @static
*
* Resets any stateful telemetry data
*/
public static function resetTelemetry()
{
self::$requestTelemetry = null;
}
/**
* @return HttpClient\ClientInterface
*/
private function httpClient()
{
if (!self::$_httpClient) {
self::$_httpClient = HttpClient\CurlClient::instance();
}
return self::$_httpClient;
}
}

View file

@ -0,0 +1,112 @@
<?php
namespace Stripe;
/**
* Class ApiResource
*
* @package Stripe
*/
abstract class ApiResource extends StripeObject
{
use ApiOperations\Request;
/**
* @return \Stripe\Util\Set A list of fields that can be their own type of
* API resource (say a nested card under an account for example), and if
* that resource is set, it should be transmitted to the API on a create or
* update. Doing so is not the default behavior because API resources
* should normally be persisted on their own RESTful endpoints.
*/
public static function getSavedNestedResources()
{
static $savedNestedResources = null;
if ($savedNestedResources === null) {
$savedNestedResources = new Util\Set();
}
return $savedNestedResources;
}
/**
* @var boolean A flag that can be set a behavior that will cause this
* resource to be encoded and sent up along with an update of its parent
* resource. This is usually not desirable because resources are updated
* individually on their own endpoints, but there are certain cases,
* replacing a customer's source for example, where this is allowed.
*/
public $saveWithParent = false;
public function __set($k, $v)
{
parent::__set($k, $v);
$v = $this->$k;
if ((static::getSavedNestedResources()->includes($k)) &&
($v instanceof ApiResource)) {
$v->saveWithParent = true;
}
return $v;
}
/**
* @return ApiResource The refreshed resource.
*/
public function refresh()
{
$requestor = new ApiRequestor($this->_opts->apiKey, static::baseUrl());
$url = $this->instanceUrl();
list($response, $this->_opts->apiKey) = $requestor->request(
'get',
$url,
$this->_retrieveOptions,
$this->_opts->headers
);
$this->setLastResponse($response);
$this->refreshFrom($response->json, $this->_opts);
return $this;
}
/**
* @return string The base URL for the given class.
*/
public static function baseUrl()
{
return Stripe::$apiBase;
}
/**
* @return string The endpoint URL for the given class.
*/
public static function classUrl()
{
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v1/foo/bars".
$base = str_replace('.', '/', static::OBJECT_NAME);
return "/v1/${base}s";
}
/**
* @return string The instance endpoint URL for the given class.
*/
public static function resourceUrl($id)
{
if ($id === null) {
$class = get_called_class();
$message = "Could not determine which URL to request: "
. "$class instance has invalid ID: $id";
throw new Error\InvalidRequest($message, null);
}
$id = Util\Util::utf8($id);
$base = static::classUrl();
$extn = urlencode($id);
return "$base/$extn";
}
/**
* @return string The full API URL for this API resource.
*/
public function instanceUrl()
{
return static::resourceUrl($this['id']);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Stripe;
/**
* Class ApiResponse
*
* @package Stripe
*/
class ApiResponse
{
public $headers;
public $body;
public $json;
public $code;
/**
* @param string $body
* @param integer $code
* @param array|null $headers
* @param array|null $json
*
* @return obj An APIResponse
*/
public function __construct($body, $code, $headers, $json)
{
$this->body = $body;
$this->code = $code;
$this->headers = $headers;
$this->json = $json;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Stripe;
/**
* Class ApplePayDomain
*
* @package Stripe
*/
class ApplePayDomain extends ApiResource
{
const OBJECT_NAME = "apple_pay_domain";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
/**
* @return string The class URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public static function classUrl()
{
return '/v1/apple_pay/domains';
}
}

View file

@ -0,0 +1,98 @@
<?php
namespace Stripe;
/**
* Class ApplicationFee
*
* @property string $id
* @property string $object
* @property string $account
* @property int $amount
* @property int $amount_refunded
* @property string $application
* @property string $balance_transaction
* @property string $charge
* @property int $created
* @property string $currency
* @property bool $livemode
* @property string $originating_transaction
* @property bool $refunded
* @property Collection $refunds
*
* @package Stripe
*/
class ApplicationFee extends ApiResource
{
const OBJECT_NAME = "application_fee";
use ApiOperations\All;
use ApiOperations\NestedResource;
use ApiOperations\Retrieve;
const PATH_REFUNDS = '/refunds';
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return ApplicationFee The refunded application fee.
*/
public function refund($params = null, $opts = null)
{
$this->refunds->create($params, $opts);
$this->refresh();
return $this;
}
/**
* @param string|null $id The ID of the application fee on which to create the refund.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApplicationFeeRefund
*/
public static function createRefund($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_REFUNDS, $params, $opts);
}
/**
* @param string|null $id The ID of the application fee to which the refund belongs.
* @param array|null $refundId The ID of the refund to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApplicationFeeRefund
*/
public static function retrieveRefund($id, $refundId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_REFUNDS, $refundId, $params, $opts);
}
/**
* @param string|null $id The ID of the application fee to which the refund belongs.
* @param array|null $refundId The ID of the refund to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApplicationFeeRefund
*/
public static function updateRefund($id, $refundId, $params = null, $opts = null)
{
return self::_updateNestedResource($id, static::PATH_REFUNDS, $refundId, $params, $opts);
}
/**
* @param string|null $id The ID of the application fee on which to retrieve the refunds.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of refunds.
*/
public static function allRefunds($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_REFUNDS, $params, $opts);
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Stripe;
/**
* Class ApplicationFeeRefund
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $balance_transaction
* @property int $created
* @property string $currency
* @property string $fee
* @property StripeObject $metadata
*
* @package Stripe
*/
class ApplicationFeeRefund extends ApiResource
{
const OBJECT_NAME = "fee_refund";
use ApiOperations\Update {
save as protected _save;
}
/**
* @return string The API URL for this Stripe refund.
*/
public function instanceUrl()
{
$id = $this['id'];
$fee = $this['fee'];
if (!$id) {
throw new Error\InvalidRequest(
"Could not determine which URL to request: " .
"class instance has invalid ID: $id",
null
);
}
$id = Util\Util::utf8($id);
$fee = Util\Util::utf8($fee);
$base = ApplicationFee::classUrl();
$feeExtn = urlencode($fee);
$extn = urlencode($id);
return "$base/$feeExtn/refunds/$extn";
}
/**
* @param array|string|null $opts
*
* @return ApplicationFeeRefund The saved refund.
*/
public function save($opts = null)
{
return $this->_save($opts);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Stripe;
/**
* Class Balance
*
* @property string $object
* @property array $available
* @property array $connect_reserved
* @property bool $livemode
* @property array $pending
*
* @package Stripe
*/
class Balance extends SingletonApiResource
{
const OBJECT_NAME = "balance";
/**
* @param array|string|null $opts
*
* @return Balance
*/
public static function retrieve($opts = null)
{
return self::_singletonRetrieve($opts);
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace Stripe;
/**
* Class BalanceTransaction
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $available_on
* @property int $created
* @property string $currency
* @property string $description
* @property float $exchange_rate
* @property int $fee
* @property mixed $fee_details
* @property int $net
* @property string $source
* @property string $status
* @property string $type
*
* @package Stripe
*/
class BalanceTransaction extends ApiResource
{
const OBJECT_NAME = "balance_transaction";
use ApiOperations\All;
use ApiOperations\Retrieve;
/**
* Possible string representations of the type of balance transaction.
* @link https://stripe.com/docs/api/balance/balance_transaction#balance_transaction_object-type
*/
const TYPE_ADJUSTMENT = 'adjustment';
const TYPE_ADVANCE = 'advance';
const TYPE_ADVANCE_FUNDING = 'advance_funding';
const TYPE_APPLICATION_FEE = 'application_fee';
const TYPE_APPLICATION_FEE_REFUND = 'application_fee_refund';
const TYPE_CHARGE = 'charge';
const TYPE_CONNECT_COLLECTION_TRANSFER = 'connect_collection_transfer';
const TYPE_ISSUING_AUTHORIZATION_HOLD = 'issuing_authorization_hold';
const TYPE_ISSUING_AUTHORIZATION_RELEASE = 'issuing_authorization_release';
const TYPE_ISSUING_TRANSACTION = 'issuing_transaction';
const TYPE_PAYMENT = 'payment';
const TYPE_PAYMENT_FAILURE_REFUND = 'payment_failure_refund';
const TYPE_PAYMENT_REFUND = 'payment_refund';
const TYPE_PAYOUT = 'payout';
const TYPE_PAYOUT_CANCEL = 'payout_cancel';
const TYPE_PAYOUT_FAILURE = 'payout_failure';
const TYPE_REFUND = 'refund';
const TYPE_REFUND_FAILURE = 'refund_failure';
const TYPE_RESERVE_TRANSACTION = 'reserve_transaction';
const TYPE_RESERVED_FUNDS = 'reserved_funds';
const TYPE_STRIPE_FEE = 'stripe_fee';
const TYPE_STRIPE_FX_FEE = 'stripe_fx_fee';
const TYPE_TAX_FEE = 'tax_fee';
const TYPE_TOPUP = 'topup';
const TYPE_TOPUP_REVERSAL = 'topup_reversal';
const TYPE_TRANSFER = 'transfer';
const TYPE_TRANSFER_CANCEL = 'transfer_cancel';
const TYPE_TRANSFER_FAILURE = 'transfer_failure';
const TYPE_TRANSFER_REFUND = 'transfer_refund';
/**
* @return string The class URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public static function classUrl()
{
return "/v1/balance/history";
}
}

View file

@ -0,0 +1,109 @@
<?php
namespace Stripe;
/**
* Class BankAccount
*
* @property string $id
* @property string $object
* @property string $account
* @property string $account_holder_name
* @property string $account_holder_type
* @property string $bank_name
* @property string $country
* @property string $currency
* @property string $customer
* @property bool $default_for_currency
* @property string $fingerprint
* @property string $last4
* @property StripeObject $metadata
* @property string $routing_number
* @property string $status
*
* @package Stripe
*/
class BankAccount extends ApiResource
{
const OBJECT_NAME = "bank_account";
use ApiOperations\Delete;
use ApiOperations\Update;
/**
* Possible string representations of the bank verification status.
* @link https://stripe.com/docs/api/external_account_bank_accounts/object#account_bank_account_object-status
*/
const STATUS_NEW = 'new';
const STATUS_VALIDATED = 'validated';
const STATUS_VERIFIED = 'verified';
const STATUS_VERIFICATION_FAILED = 'verification_failed';
const STATUS_ERRORED = 'errored';
/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} elseif ($this['account']) {
$base = Account::classUrl();
$parent = $this['account'];
$path = 'external_accounts';
} else {
$msg = "Bank accounts cannot be accessed without a customer ID or account ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}
/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Retrieve a bank account using \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Call save() on \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @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;
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Stripe;
/**
* Class BitcoinReceiver
*
* @package Stripe
*
* @deprecated Bitcoin receivers are deprecated. Please use the sources API instead.
* @link https://stripe.com/docs/sources/bitcoin
*/
class BitcoinReceiver extends ApiResource
{
const OBJECT_NAME = "bitcoin_receiver";
use ApiOperations\All;
use ApiOperations\Retrieve;
/**
* @return string The class URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public static function classUrl()
{
return "/v1/bitcoin/receivers";
}
/**
* @return string The instance URL for this resource. It needs to be special
* cased because it doesn't fit into the standard resource pattern.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
} else {
$base = BitcoinReceiver::classUrl();
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$extn";
}
}
}

View file

@ -0,0 +1,14 @@
<?php
namespace Stripe;
/**
* Class BitcoinTransaction
*
* @package Stripe
*/
class BitcoinTransaction extends ApiResource
{
const OBJECT_NAME = "bitcoin_transaction";
}

View file

@ -0,0 +1,83 @@
<?php
namespace Stripe;
/**
* Class Capability
*
* @package Stripe
*
* @property string $id
* @property string $object
* @property string $account
* @property bool $requested
* @property int $requested_at
* @property mixed $requirements
* @property string $status
*/
class Capability extends ApiResource
{
const OBJECT_NAME = "capability";
use ApiOperations\Update;
/**
* Possible string representations of a capability's status.
* @link https://stripe.com/docs/api/capabilities/object#capability_object-status
*/
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
const STATUS_PENDING = 'pending';
const STATUS_UNREQUESTED = 'unrequested';
/**
* @return string The API URL for this Stripe account reversal.
*/
public function instanceUrl()
{
$id = $this['id'];
$account = $this['account'];
if (!$id) {
throw new Error\InvalidRequest(
"Could not determine which URL to request: " .
"class instance has invalid ID: $id",
null
);
}
$id = Util\Util::utf8($id);
$account = Util\Util::utf8($account);
$base = Account::classUrl();
$accountExtn = urlencode($account);
$extn = urlencode($id);
return "$base/$accountExtn/capabilities/$extn";
}
/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Capabilities cannot be accessed without an account ID. " .
"Retrieve a Capability using \$account->retrieveCapability('acap_123') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Capabilities cannot be accessed without an account ID. " .
"Update a Capability using \$account->updateCapability('acap_123') instead.";
throw new Error\InvalidRequest($msg, null);
}
}

View file

@ -0,0 +1,130 @@
<?php
namespace Stripe;
/**
* Class Card
*
* @property string $id
* @property string $object
* @property string $account
* @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[] $available_payout_methods
* @property string $brand
* @property string $country
* @property string $currency
* @property string $customer
* @property string $cvc_check
* @property bool $default_for_currency
* @property string $dynamic_last4
* @property int $exp_month
* @property int $exp_year
* @property string $fingerprint
* @property string $funding
* @property string $last4
* @property StripeObject $metadata
* @property string $name
* @property string $recipient
* @property string $tokenization_method
*
* @package Stripe
*/
class Card extends ApiResource
{
const OBJECT_NAME = "card";
use ApiOperations\Delete;
use ApiOperations\Update;
/**
* Possible string representations of the CVC check status.
* @link https://stripe.com/docs/api/cards/object#card_object-cvc_check
*/
const CVC_CHECK_FAIL = 'fail';
const CVC_CHECK_PASS = 'pass';
const CVC_CHECK_UNAVAILABLE = 'unavailable';
const CVC_CHECK_UNCHECKED = 'unchecked';
/**
* Possible string representations of the funding of the card.
* @link https://stripe.com/docs/api/cards/object#card_object-funding
*/
const FUNDING_CREDIT = 'credit';
const FUNDING_DEBIT = 'debit';
const FUNDING_PREPAID = 'prepaid';
const FUNDING_UNKNOWN = 'unknown';
/**
* Possible string representations of the tokenization method when using Apple Pay or Google Pay.
* @link https://stripe.com/docs/api/cards/object#card_object-tokenization_method
*/
const TOKENIZATION_METHOD_APPLE_PAY = 'apple_pay';
const TOKENIZATION_METHOD_GOOGLE_PAY = 'google_pay';
/**
* @return string The instance URL for this resource. It needs to be special
* cased because cards are nested resources that may belong to different
* top-level resources.
*/
public function instanceUrl()
{
if ($this['customer']) {
$base = Customer::classUrl();
$parent = $this['customer'];
$path = 'sources';
} elseif ($this['account']) {
$base = Account::classUrl();
$parent = $this['account'];
$path = 'external_accounts';
} elseif ($this['recipient']) {
$base = Recipient::classUrl();
$parent = $this['recipient'];
$path = 'cards';
} else {
$msg = "Cards cannot be accessed without a customer ID, account ID or recipient ID.";
throw new Error\InvalidRequest($msg, null);
}
$parentExtn = urlencode(Util\Util::utf8($parent));
$extn = urlencode(Util\Util::utf8($this['id']));
return "$base/$parentExtn/$path/$extn";
}
/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Retrieve a card using \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or " .
"\$account->external_accounts->retrieve('card_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Call save() on \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or " .
"\$account->external_accounts->retrieve('card_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
}

View file

@ -0,0 +1,207 @@
<?php
namespace Stripe;
/**
* Class Charge
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $amount_refunded
* @property string $application
* @property string $application_fee
* @property int $application_fee_amount
* @property string $balance_transaction
* @property mixed $billing_details
* @property bool $captured
* @property int $created
* @property string $currency
* @property string $customer
* @property string $description
* @property string $destination
* @property string $dispute
* @property string $failure_code
* @property string $failure_message
* @property mixed $fraud_details
* @property string $invoice
* @property bool $livemode
* @property StripeObject $metadata
* @property string $on_behalf_of
* @property string $order
* @property mixed $outcome
* @property bool $paid
* @property string $payment_intent
* @property string $payment_method
* @property mixed $payment_method_details
* @property string $receipt_email
* @property string $receipt_number
* @property string $receipt_url
* @property bool $refunded
* @property Collection $refunds
* @property string $review
* @property mixed $shipping
* @property mixed $source
* @property string $source_transfer
* @property string $statement_descriptor
* @property string $status
* @property string $transfer
* @property mixed $transfer_data
* @property string $transfer_group
*
* @package Stripe
*/
class Charge extends ApiResource
{
const OBJECT_NAME = "charge";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of decline codes.
* These strings are applicable to the decline_code property of the \Stripe\Error\Card exception.
* @link https://stripe.com/docs/declines/codes
*/
const DECLINED_APPROVE_WITH_ID = 'approve_with_id';
const DECLINED_CALL_ISSUER = 'call_issuer';
const DECLINED_CARD_NOT_SUPPORTED = 'card_not_supported';
const DECLINED_CARD_VELOCITY_EXCEEDED = 'card_velocity_exceeded';
const DECLINED_CURRENCY_NOT_SUPPORTED = 'currency_not_supported';
const DECLINED_DO_NOT_HONOR = 'do_not_honor';
const DECLINED_DO_NOT_TRY_AGAIN = 'do_not_try_again';
const DECLINED_DUPLICATED_TRANSACTION = 'duplicate_transaction';
const DECLINED_EXPIRED_CARD = 'expired_card';
const DECLINED_FRAUDULENT = 'fraudulent';
const DECLINED_GENERIC_DECLINE = 'generic_decline';
const DECLINED_INCORRECT_NUMBER = 'incorrect_number';
const DECLINED_INCORRECT_CVC = 'incorrect_cvc';
const DECLINED_INCORRECT_PIN = 'incorrect_pin';
const DECLINED_INCORRECT_ZIP = 'incorrect_zip';
const DECLINED_INSUFFICIENT_FUNDS = 'insufficient_funds';
const DECLINED_INVALID_ACCOUNT = 'invalid_account';
const DECLINED_INVALID_AMOUNT = 'invalid_amount';
const DECLINED_INVALID_CVC = 'invalid_cvc';
const DECLINED_INVALID_EXPIRY_YEAR = 'invalid_expiry_year';
const DECLINED_INVALID_NUMBER = 'invalid_number';
const DECLINED_INVALID_PIN = 'invalid_pin';
const DECLINED_ISSUER_NOT_AVAILABLE = 'issuer_not_available';
const DECLINED_LOST_CARD = 'lost_card';
const DECLINED_MERCHANT_BLACKLIST = 'merchant_blacklist';
const DECLINED_NEW_ACCOUNT_INFORMATION_AVAILABLE = 'new_account_information_available';
const DECLINED_NO_ACTION_TAKEN = 'no_action_taken';
const DECLINED_NOT_PERMITTED = 'not_permitted';
const DECLINED_PICKUP_CARD = 'pickup_card';
const DECLINED_PIN_TRY_EXCEEDED = 'pin_try_exceeded';
const DECLINED_PROCESSING_ERROR = 'processing_error';
const DECLINED_REENTER_TRANSACTION = 'reenter_transaction';
const DECLINED_RESTRICTED_CARD = 'restricted_card';
const DECLINED_REVOCATION_OF_ALL_AUTHORIZATIONS = 'revocation_of_all_authorizations';
const DECLINED_REVOCATION_OF_AUTHORIZATION = 'revocation_of_authorization';
const DECLINED_SECURITY_VIOLATION = 'security_violation';
const DECLINED_SERVICE_NOT_ALLOWED = 'service_not_allowed';
const DECLINED_STOLEN_CARD = 'stolen_card';
const DECLINED_STOP_PAYMENT_ORDER = 'stop_payment_order';
const DECLINED_TESTMODE_DECLINE = 'testmode_decline';
const DECLINED_TRANSACTION_NOT_ALLOWED = 'transaction_not_allowed';
const DECLINED_TRY_AGAIN_LATER = 'try_again_later';
const DECLINED_WITHDRAWAL_COUNT_LIMIT_EXCEEDED = 'withdrawal_count_limit_exceeded';
/**
* Possible string representations of the status of the charge.
* @link https://stripe.com/docs/api/charges/object#charge_object-status
*/
const STATUS_FAILED = 'failed';
const STATUS_PENDING = 'pending';
const STATUS_SUCCEEDED = 'succeeded';
/**
* @param array|null $params
* @param array|string|null $options
*
* @return Charge The refunded charge.
*/
public function refund($params = null, $options = null)
{
$url = $this->instanceUrl() . '/refund';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return Charge The captured charge.
*/
public function capture($params = null, $options = null)
{
$url = $this->instanceUrl() . '/capture';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @deprecated Use the `save` method on the Dispute object
*
* @return array The updated dispute.
*/
public function updateDispute($params = null, $options = null)
{
$url = $this->instanceUrl() . '/dispute';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom(['dispute' => $response], $opts, true);
return $this->dispute;
}
/**
* @param array|string|null $options
*
* @deprecated Use the `close` method on the Dispute object
*
* @return Charge The updated charge.
*/
public function closeDispute($options = null)
{
$url = $this->instanceUrl() . '/dispute/close';
list($response, $opts) = $this->_request('post', $url, null, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|string|null $opts
*
* @return Charge The updated charge.
*/
public function markAsFraudulent($opts = null)
{
$params = ['fraud_details' => ['user_report' => 'fraudulent']];
$url = $this->instanceUrl();
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|string|null $opts
*
* @return Charge The updated charge.
*/
public function markAsSafe($opts = null)
{
$params = ['fraud_details' => ['user_report' => 'safe']];
$url = $this->instanceUrl();
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Stripe\Checkout;
/**
* Class Session
*
* @property string $id
* @property string $object
* @property string $cancel_url
* @property string $client_reference_id
* @property string $customer
* @property string $customer_email
* @property mixed $display_items
* @property bool $livemode
* @property string $payment_intent
* @property string[] $payment_method_types
* @property string $subscription
* @property string $success_url
*
* @package Stripe
*/
class Session extends \Stripe\ApiResource
{
const OBJECT_NAME = "checkout.session";
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
}

View file

@ -0,0 +1,108 @@
<?php
namespace Stripe;
/**
* Class Collection
*
* @property string $object
* @property string $url
* @property bool $has_more
* @property mixed $data
*
* @package Stripe
*/
class Collection extends StripeObject implements \IteratorAggregate
{
const OBJECT_NAME = "list";
use ApiOperations\Request;
protected $_requestParams = [];
/**
* @return string The base URL for the given class.
*/
public static function baseUrl()
{
return Stripe::$apiBase;
}
public function setRequestParams($params)
{
$this->_requestParams = $params;
}
public function all($params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
list($response, $opts) = $this->_request('get', $url, $params, $opts);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
public function create($params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
public function retrieve($id, $params = null, $opts = null)
{
list($url, $params) = $this->extractPathAndUpdateParams($params);
$id = Util\Util::utf8($id);
$extn = urlencode($id);
list($response, $opts) = $this->_request(
'get',
"$url/$extn",
$params,
$opts
);
$this->_requestParams = $params;
return Util\Util::convertToStripeObject($response, $opts);
}
/**
* @return \ArrayIterator An iterator that can be used to iterate
* across objects in the current page.
*/
public function getIterator()
{
return new \ArrayIterator($this->data);
}
/**
* @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.
*/
public function autoPagingIterator()
{
return new Util\AutoPagingIterator($this, $this->_requestParams);
}
private function extractPathAndUpdateParams($params)
{
$url = parse_url($this->url);
if (!isset($url['path'])) {
throw new Error\Api("Could not parse list url into parts: $url");
}
if (isset($url['query'])) {
// If the URL contains a query param, parse it out into $params so they
// don't interact weirdly with each other.
$query = [];
parse_str($url['query'], $query);
$params = array_merge($params ?: [], $query);
}
return [$url['path'], $params];
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Stripe;
/**
* Class CountrySpec
*
* @property string $id
* @property string $object
* @property string $default_currency
* @property mixed $supported_bank_account_currencies
* @property string[] $supported_payment_currencies
* @property string[] $supported_payment_methods
* @property string[] $supported_transfer_countries
* @property mixed $verification_fields
*
* @package Stripe
*/
class CountrySpec extends ApiResource
{
const OBJECT_NAME = "country_spec";
use ApiOperations\All;
use ApiOperations\Retrieve;
}

View file

@ -0,0 +1,36 @@
<?php
namespace Stripe;
/**
* Class Coupon
*
* @property string $id
* @property string $object
* @property int $amount_off
* @property int $created
* @property string $currency
* @property string $duration
* @property int $duration_in_months
* @property bool $livemode
* @property int $max_redemptions
* @property StripeObject $metadata
* @property string $name
* @property float $percent_off
* @property int $redeem_by
* @property int $times_redeemed
* @property bool $valid
*
* @package Stripe
*/
class Coupon extends ApiResource
{
const OBJECT_NAME = "coupon";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}

View file

@ -0,0 +1,73 @@
<?php
namespace Stripe;
/**
* Class CreditNote
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $created
* @property string $currency
* @property string $customer
* @property string $invoice
* @property bool $livemode
* @property string $memo
* @property StripeObject $metadata
* @property string $number
* @property string $pdf
* @property string $reason
* @property string $refund
* @property string $status
* @property string $type
*
* @package Stripe
*/
class CreditNote extends ApiResource
{
const OBJECT_NAME = "credit_note";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of the credit note reason.
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-reason
*/
const REASON_DUPLICATE = 'duplicate';
const REASON_FRAUDULENT = 'fraudulent';
const REASON_ORDER_CHANGE = 'order_change';
const REASON_PRODUCT_UNSATISFACTORY = 'product_unsatisfactory';
/**
* Possible string representations of the credit note status.
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-status
*/
const STATUS_ISSUED = 'issued';
const STATUS_VOID = 'void';
/**
* Possible string representations of the credit note type.
* @link https://stripe.com/docs/api/credit_notes/object#credit_note_object-status
*/
const TYPE_POST_PAYMENT = 'post_payment';
const TYPE_PRE_PAYMENT = 'pre_payment';
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return CreditNote The voided credit note.
*/
public function voidCreditNote($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/void';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,268 @@
<?php
namespace Stripe;
/**
* Class Customer
*
* @property string $id
* @property string $object
* @property int $account_balance
* @property mixed $address
* @property string $created
* @property string $currency
* @property string $default_source
* @property bool $delinquent
* @property string $description
* @property Discount $discount
* @property string $email
* @property string $invoice_prefix
* @property mixed $invoice_settings
* @property bool $livemode
* @property StripeObject $metadata
* @property string $name
* @property string $phone
* @property string[] preferred_locales
* @property mixed $shipping
* @property Collection $sources
* @property Collection $subscriptions
* @property string $tax_exempt
* @property Collection $tax_ids
*
* @package Stripe
*/
class Customer extends ApiResource
{
const OBJECT_NAME = "customer";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\NestedResource;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of the customer's type of tax exemption.
* @link https://stripe.com/docs/api/customers/object#customer_object-tax_exempt
*/
const TAX_EXEMPT_NONE = 'none';
const TAX_EXEMPT_EXEMPT = 'exempt';
const TAX_EXEMPT_REVERSE = 'reverse';
public static function getSavedNestedResources()
{
static $savedNestedResources = null;
if ($savedNestedResources === null) {
$savedNestedResources = new Util\Set([
'source',
]);
}
return $savedNestedResources;
}
const PATH_SOURCES = '/sources';
const PATH_TAX_IDS = '/tax_ids';
/**
* @param array|null $params
*
* @return InvoiceItem The resulting invoice item.
*/
public function addInvoiceItem($params = null)
{
$params = $params ?: [];
$params['customer'] = $this->id;
$ii = InvoiceItem::create($params, $this->_opts);
return $ii;
}
/**
* @param array|null $params
*
* @return array An array of the customer's Invoices.
*/
public function invoices($params = null)
{
$params = $params ?: [];
$params['customer'] = $this->id;
$invoices = Invoice::all($params, $this->_opts);
return $invoices;
}
/**
* @param array|null $params
*
* @return array An array of the customer's InvoiceItems.
*/
public function invoiceItems($params = null)
{
$params = $params ?: [];
$params['customer'] = $this->id;
$iis = InvoiceItem::all($params, $this->_opts);
return $iis;
}
/**
* @param array|null $params
*
* @return array An array of the customer's Charges.
*/
public function charges($params = null)
{
$params = $params ?: [];
$params['customer'] = $this->id;
$charges = Charge::all($params, $this->_opts);
return $charges;
}
/**
* @param array|null $params
*
* @return Subscription The updated subscription.
*/
public function updateSubscription($params = null)
{
$url = $this->instanceUrl() . '/subscription';
list($response, $opts) = $this->_request('post', $url, $params);
$this->refreshFrom(['subscription' => $response], $opts, true);
return $this->subscription;
}
/**
* @param array|null $params
*
* @return Subscription The cancelled subscription.
*/
public function cancelSubscription($params = null)
{
$url = $this->instanceUrl() . '/subscription';
list($response, $opts) = $this->_request('delete', $url, $params);
$this->refreshFrom(['subscription' => $response], $opts, true);
return $this->subscription;
}
/**
* @return Customer The updated customer.
*/
public function deleteDiscount()
{
$url = $this->instanceUrl() . '/discount';
list($response, $opts) = $this->_request('delete', $url);
$this->refreshFrom(['discount' => null], $opts, true);
}
/**
* @param string|null $id The ID of the customer on which to create the source.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function createSource($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
}
/**
* @param string|null $id The ID of the customer to which the source belongs.
* @param string|null $sourceId The ID of the source to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
}
/**
* @param string|null $id The ID of the customer to which the source belongs.
* @param string|null $sourceId The ID of the source to update.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function updateSource($id, $sourceId, $params = null, $opts = null)
{
return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
}
/**
* @param string|null $id The ID of the customer to which the source belongs.
* @param string|null $sourceId The ID of the source to delete.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function deleteSource($id, $sourceId, $params = null, $opts = null)
{
return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
}
/**
* @param string|null $id The ID of the customer on which to retrieve the sources.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of sources.
*/
public static function allSources($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
}
/**
* @param string|null $id The ID of the customer on which to create the tax id.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function createTaxId($id, $params = null, $opts = null)
{
return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
}
/**
* @param string|null $id The ID of the customer to which the tax id belongs.
* @param string|null $taxIdId The ID of the tax id to retrieve.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
{
return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
}
/**
* @param string|null $id The ID of the customer to which the tax id belongs.
* @param string|null $taxIdId The ID of the tax id to delete.
* @param array|null $params
* @param array|string|null $opts
*
* @return ApiResource
*/
public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
{
return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
}
/**
* @param string|null $id The ID of the customer on which to retrieve the tax ids.
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection The list of tax ids.
*/
public static function allTaxIds($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Stripe;
/**
* Class Discount
*
* @property string $object
* @property Coupon $coupon
* @property string $customer
* @property int $end
* @property int $start
* @property string $subscription
*
* @package Stripe
*/
class Discount extends StripeObject
{
const OBJECT_NAME = "discount";
}

View file

@ -0,0 +1,78 @@
<?php
namespace Stripe;
/**
* Class Dispute
*
* @property string $id
* @property string $object
* @property int $amount
* @property BalanceTransaction[] $balance_transactions
* @property string $charge
* @property int $created
* @property string $currency
* @property mixed $evidence
* @property mixed $evidence_details
* @property bool $is_charge_refundable
* @property bool $livemode
* @property StripeObject $metadata
* @property string $reason
* @property string $status
*
* @package Stripe
*/
class Dispute extends ApiResource
{
const OBJECT_NAME = "dispute";
use ApiOperations\All;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of dispute reasons.
* @link https://stripe.com/docs/api#dispute_object
*/
const REASON_BANK_CANNOT_PROCESS = 'bank_cannot_process';
const REASON_CHECK_RETURNED = 'check_returned';
const REASON_CREDIT_NOT_PROCESSED = 'credit_not_processed';
const REASON_CUSTOMER_INITIATED = 'customer_initiated';
const REASON_DEBIT_NOT_AUTHORIZED = 'debit_not_authorized';
const REASON_DUPLICATE = 'duplicate';
const REASON_FRAUDULENT = 'fraudulent';
const REASON_GENERAL = 'general';
const REASON_INCORRECT_ACCOUNT_DETAILS = 'incorrect_account_details';
const REASON_INSUFFICIENT_FUNDS = 'insufficient_funds';
const REASON_PRODUCT_NOT_RECEIVED = 'product_not_received';
const REASON_PRODUCT_UNACCEPTABLE = 'product_unacceptable';
const REASON_SUBSCRIPTION_CANCELED = 'subscription_canceled';
const REASON_UNRECOGNIZED = 'unrecognized';
/**
* Possible string representations of dispute statuses.
* @link https://stripe.com/docs/api#dispute_object
*/
const STATUS_CHARGE_REFUNDED = 'charge_refunded';
const STATUS_LOST = 'lost';
const STATUS_NEEDS_RESPONSE = 'needs_response';
const STATUS_UNDER_REVIEW = 'under_review';
const STATUS_WARNING_CLOSED = 'warning_closed';
const STATUS_WARNING_NEEDS_RESPONSE = 'warning_needs_response';
const STATUS_WARNING_UNDER_REVIEW = 'warning_under_review';
const STATUS_WON = 'won';
/**
* @param array|string|null $options
*
* @return Dispute The closed dispute.
*/
public function close($options = null)
{
$url = $this->instanceUrl() . '/close';
list($response, $opts) = $this->_request('post', $url, null, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,41 @@
<?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
{
const OBJECT_NAME = "ephemeral_key";
use ApiOperations\Create {
create as protected _create;
}
use ApiOperations\Delete;
/**
* @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);
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class Api extends Base
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class ApiConnection extends Base
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class Authentication extends Base
{
}

View file

@ -0,0 +1,69 @@
<?php
namespace Stripe\Error;
use Exception;
abstract class Base extends Exception
{
public function __construct(
$message,
$httpStatus = null,
$httpBody = null,
$jsonBody = null,
$httpHeaders = null
) {
parent::__construct($message);
$this->httpStatus = $httpStatus;
$this->httpBody = $httpBody;
$this->jsonBody = $jsonBody;
$this->httpHeaders = $httpHeaders;
$this->requestId = null;
// TODO: make this a proper constructor argument in the next major
// release.
$this->stripeCode = isset($jsonBody["error"]["code"]) ? $jsonBody["error"]["code"] : null;
if ($httpHeaders && isset($httpHeaders['Request-Id'])) {
$this->requestId = $httpHeaders['Request-Id'];
}
}
public function getStripeCode()
{
return $this->stripeCode;
}
public function getHttpStatus()
{
return $this->httpStatus;
}
public function getHttpBody()
{
return $this->httpBody;
}
public function getJsonBody()
{
return $this->jsonBody;
}
public function getHttpHeaders()
{
return $this->httpHeaders;
}
public function getRequestId()
{
return $this->requestId;
}
public function __toString()
{
$id = $this->requestId ? " from API request '{$this->requestId}'": "";
$message = explode("\n", parent::__toString());
$message[0] .= $id;
return implode("\n", $message);
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Stripe\Error;
class Card extends Base
{
public function __construct(
$message,
$stripeParam,
$stripeCode,
$httpStatus,
$httpBody,
$jsonBody,
$httpHeaders = null
) {
parent::__construct($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders);
$this->stripeParam = $stripeParam;
// TODO: once Error\Base accepts the error code as an argument, pass it
// in the call to parent::__construct() and stop setting it here.
$this->stripeCode = $stripeCode;
// This one is not like the others because it was added later and we're
// trying to do our best not to change the public interface of this class'
// constructor.
// TODO: make this a proper constructor argument in the next major
// release.
$this->declineCode = isset($jsonBody["error"]["decline_code"]) ? $jsonBody["error"]["decline_code"] : null;
}
public function getDeclineCode()
{
return $this->declineCode;
}
public function getStripeParam()
{
return $this->stripeParam;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class Idempotency extends Base
{
}

View file

@ -0,0 +1,23 @@
<?php
namespace Stripe\Error;
class InvalidRequest extends Base
{
public function __construct(
$message,
$stripeParam,
$httpStatus = null,
$httpBody = null,
$jsonBody = null,
$httpHeaders = null
) {
parent::__construct($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders);
$this->stripeParam = $stripeParam;
}
public function getStripeParam()
{
return $this->stripeParam;
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Stripe\Error\OAuth;
/**
* InvalidClient is raised when authentication fails.
*/
class InvalidClient extends OAuthBase
{
}

View file

@ -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
{
}

View file

@ -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
{
}

View file

@ -0,0 +1,10 @@
<?php
namespace Stripe\Error\OAuth;
/**
* InvalidScope is raised when an invalid scope parameter is provided.
*/
class InvalidScope extends OAuthBase
{
}

View file

@ -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->errorCode = $code;
}
public function getErrorCode()
{
return $this->errorCode;
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Stripe\Error\OAuth;
/**
* UnsupportedGrantType is raised when an unuspported grant type
* parameter is specified.
*/
class UnsupportedGrantType extends OAuthBase
{
}

View file

@ -0,0 +1,11 @@
<?php
namespace Stripe\Error\OAuth;
/**
* UnsupportedResponseType is raised when an unsupported response type
* parameter is specified.
*/
class UnsupportedResponseType extends OAuthBase
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class Permission extends Base
{
}

View file

@ -0,0 +1,7 @@
<?php
namespace Stripe\Error;
class RateLimit extends InvalidRequest
{
}

View file

@ -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;
}
}

View file

@ -0,0 +1,168 @@
<?php
namespace Stripe;
/**
* Class Event
*
* @property string $id
* @property string $object
* @property string $account
* @property string $api_version
* @property int $created
* @property mixed $data
* @property bool $livemode
* @property int $pending_webhooks
* @property mixed $request
* @property string $type
*
* @package Stripe
*/
class Event extends ApiResource
{
const OBJECT_NAME = "event";
/**
* Possible string representations of event types.
* @link https://stripe.com/docs/api#event_types
*/
const ACCOUNT_UPDATED = 'account.updated';
const ACCOUNT_APPLICATION_AUTHORIZED = 'account.application.authorized';
const ACCOUNT_APPLICATION_DEAUTHORIZED = 'account.application.deauthorized';
const ACCOUNT_EXTERNAL_ACCOUNT_CREATED = 'account.external_account.created';
const ACCOUNT_EXTERNAL_ACCOUNT_DELETED = 'account.external_account.deleted';
const ACCOUNT_EXTERNAL_ACCOUNT_UPDATED = 'account.external_account.updated';
const APPLICATION_FEE_CREATED = 'application_fee.created';
const APPLICATION_FEE_REFUNDED = 'application_fee.refunded';
const APPLICATION_FEE_REFUND_UPDATED = 'application_fee.refund.updated';
const BALANCE_AVAILABLE = 'balance.available';
const CHARGE_CAPTURED = 'charge.captured';
const CHARGE_EXPIRED = 'charge.expired';
const CHARGE_FAILED = 'charge.failed';
const CHARGE_PENDING = 'charge.pending';
const CHARGE_REFUNDED = 'charge.refunded';
const CHARGE_SUCCEEDED = 'charge.succeeded';
const CHARGE_UPDATED = 'charge.updated';
const CHARGE_DISPUTE_CLOSED = 'charge.dispute.closed';
const CHARGE_DISPUTE_CREATED = 'charge.dispute.created';
const CHARGE_DISPUTE_FUNDS_REINSTATED = 'charge.dispute.funds_reinstated';
const CHARGE_DISPUTE_FUNDS_WITHDRAWN = 'charge.dispute.funds_withdrawn';
const CHARGE_DISPUTE_UPDATED = 'charge.dispute.updated';
const CHARGE_REFUND_UPDATED = 'charge.refund.updated';
const CHECKOUT_SESSION_COMPLETED = 'checkout.session.completed';
const COUPON_CREATED = 'coupon.created';
const COUPON_DELETED = 'coupon.deleted';
const COUPON_UPDATED = 'coupon.updated';
const CREDIT_NOTE_CREATED = 'credit_note.created';
const CREDIT_NOTE_UPDATED = 'credit_note.updated';
const CREDIT_NOTE_VOIDED = 'credit_note.voided';
const CUSTOMER_CREATED = 'customer.created';
const CUSTOMER_DELETED = 'customer.deleted';
const CUSTOMER_UPDATED = 'customer.updated';
const CUSTOMER_DISCOUNT_CREATED = 'customer.discount.created';
const CUSTOMER_DISCOUNT_DELETED = 'customer.discount.deleted';
const CUSTOMER_DISCOUNT_UPDATED = 'customer.discount.updated';
const CUSTOMER_SOURCE_CREATED = 'customer.source.created';
const CUSTOMER_SOURCE_DELETED = 'customer.source.deleted';
const CUSTOMER_SOURCE_EXPIRING = 'customer.source.expiring';
const CUSTOMER_SOURCE_UPDATED = 'customer.source.updated';
const CUSTOMER_SUBSCRIPTION_CREATED = 'customer.subscription.created';
const CUSTOMER_SUBSCRIPTION_DELETED = 'customer.subscription.deleted';
const CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END = 'customer.subscription.trial_will_end';
const CUSTOMER_SUBSCRIPTION_UPDATED = 'customer.subscription.updated';
const FILE_CREATED = 'file.created';
const INVOICE_CREATED = 'invoice.created';
const INVOICE_DELETED = 'invoice.deleted';
const INVOICE_FINALIZED = 'invoice.finalized';
const INVOICE_MARKED_UNCOLLECTIBLE = 'invoice.marked_uncollectible';
const INVOICE_PAYMENT_ACTION_REQUIRED = 'invoice.payment_action_required';
const INVOICE_PAYMENT_FAILED = 'invoice.payment_failed';
const INVOICE_PAYMENT_SUCCEEDED = 'invoice.payment_succeeded';
const INVOICE_SENT = 'invoice.sent';
const INVOICE_UPCOMING = 'invoice.upcoming';
const INVOICE_UPDATED = 'invoice.updated';
const INVOICE_VOIDED = 'invoice.voided';
const INVOICEITEM_CREATED = 'invoiceitem.created';
const INVOICEITEM_DELETED = 'invoiceitem.deleted';
const INVOICEITEM_UPDATED = 'invoiceitem.updated';
const ISSUER_FRAUD_RECORD_CREATED = 'issuer_fraud_record.created';
const ISSUING_AUTHORIZATION_CREATED = 'issuing_authorization.created';
const ISSUING_AUTHORIZATION_REQUEST = 'issuing_authorization.request';
const ISSUING_AUTHORIZATION_UPDATED = 'issuing_authorization.updated';
const ISSUING_CARD_CREATED = 'issuing_card.created';
const ISSUING_CARD_UPDATED = 'issuing_card.updated';
const ISSUING_CARDHOLDER_CREATED = 'issuing_cardholder.created';
const ISSUING_CARDHOLDER_UPDATED = 'issuing_cardholder.updated';
const ISSUING_DISPUTE_CREATED = 'issuing_dispute.created';
const ISSUING_DISPUTE_UPDATED = 'issuing_dispute.updated';
const ISSUING_TRANSACTION_CREATED = 'issuing_transaction.created';
const ISSUING_TRANSACTION_UPDATED = 'issuing_transaction.updated';
const ORDER_CREATED = 'order.created';
const ORDER_PAYMENT_FAILED = 'order.payment_failed';
const ORDER_PAYMENT_SUCCEEDED = 'order.payment_succeeded';
const ORDER_UPDATED = 'order.updated';
const ORDER_RETURN_CREATED = 'order_return.created';
const PAYMENT_INTENT_AMOUNT_CAPTURABLE_UPDATED = 'payment_intent.amount_capturable_updated';
const PAYMENT_INTENT_CREATED = 'payment_intent.created';
const PAYMENT_INTENT_PAYMENT_FAILED = 'payment_intent.payment_failed';
const PAYMENT_INTENT_SUCCEEDED = 'payment_intent.succeeded';
const PAYMENT_METHOD_ATTACHED = 'payment_method.attached';
const PAYMENT_METHOD_CARD_AUTOMATICALLY_UPDATED = 'payment_method.card_automatically_updated';
const PAYMENT_METHOD_DETACHED = 'payment_method.detached';
const PAYMENT_METHOD_UPDATED = 'payment_method.updated';
const PAYOUT_CANCELED = 'payout.canceled';
const PAYOUT_CREATED = 'payout.created';
const PAYOUT_FAILED = 'payout.failed';
const PAYOUT_PAID = 'payout.paid';
const PAYOUT_UPDATED = 'payout.updated';
const PERSON_CREATED = 'person.created';
const PERSON_DELETED = 'person.deleted';
const PERSON_UPDATED = 'person.updated';
const PING = 'ping';
const PLAN_CREATED = 'plan.created';
const PLAN_DELETED = 'plan.deleted';
const PLAN_UPDATED = 'plan.updated';
const PRODUCT_CREATED = 'product.created';
const PRODUCT_DELETED = 'product.deleted';
const PRODUCT_UPDATED = 'product.updated';
const RECIPIENT_CREATED = 'recipient.created';
const RECIPIENT_DELETED = 'recipient.deleted';
const RECIPIENT_UPDATED = 'recipient.updated';
const REPORTING_REPORT_RUN_FAILED = 'reporting.report_run.failed';
const REPORTING_REPORT_RUN_SUCCEEDED = 'reporting.report_run.succeeded';
const REPORTING_REPORT_TYPE_UPDATED = 'reporting.report_type.updated';
const REVIEW_CLOSED = 'review.closed';
const REVIEW_OPENED = 'review.opened';
const SIGMA_SCHEDULED_QUERY_RUN_CREATED = 'sigma.scheduled_query_run.created';
const SKU_CREATED = 'sku.created';
const SKU_DELETED = 'sku.deleted';
const SKU_UPDATED = 'sku.updated';
const SOURCE_CANCELED = 'source.canceled';
const SOURCE_CHARGEABLE = 'source.chargeable';
const SOURCE_FAILED = 'source.failed';
const SOURCE_MANDATE_NOTIFICATION = 'source.mandate_notification';
const SOURCE_REFUND_ATTRIBUTES_REQUIRED = 'source.refund_attributes_required';
const SOURCE_TRANSACTION_CREATED = 'source.transaction.created';
const SOURCE_TRANSACTION_UPDATED = 'source.transaction.updated';
const SUBSCRIPTION_SCHEDULE_ABORTED = 'subscription_schedule.aborted';
const SUBSCRIPTION_SCHEDULE_CANCELED = 'subscription_schedule.canceled';
const SUBSCRIPTION_SCHEDULE_COMPLETED = 'subscription_schedule.completed';
const SUBSCRIPTION_SCHEDULE_CREATED = 'subscription_schedule.created';
const SUBSCRIPTION_SCHEDULE_EXPIRING = 'subscription_schedule.expiring';
const SUBSCRIPTION_SCHEDULE_RELEASED = 'subscription_schedule.released';
const SUBSCRIPTION_SCHEDULE_UPDATED = 'subscription_schedule.updated';
const TAX_RATE_CREATED = 'tax_rate.created';
const TAX_RATE_UPDATED = 'tax_rate.updated';
const TOPUP_CANCELED = 'topup.canceled';
const TOPUP_CREATED = 'topup.created';
const TOPUP_FAILED = 'topup.failed';
const TOPUP_REVERSED = 'topup.reversed';
const TOPUP_SUCCEEDED = 'topup.succeeded';
const TRANSFER_CREATED = 'transfer.created';
const TRANSFER_REVERSED = 'transfer.reversed';
const TRANSFER_UPDATED = 'transfer.updated';
use ApiOperations\All;
use ApiOperations\Retrieve;
}

View file

@ -0,0 +1,17 @@
<?php
namespace Stripe;
/**
* Class ExchangeRate
*
* @package Stripe
*/
class ExchangeRate extends ApiResource
{
const OBJECT_NAME = "exchange_rate";
use ApiOperations\All;
use ApiOperations\Retrieve;
}

View file

@ -0,0 +1,62 @@
<?php
namespace Stripe;
/**
* Class File
*
* @property string $id
* @property string $object
* @property int $created
* @property string $filename
* @property Collection $links
* @property string $purpose
* @property int $size
* @property string $title
* @property string $type
* @property string $url
*
* @package Stripe
*/
class File extends ApiResource
{
// This resource can have two different object names. In latter API
// versions, only `file` is used, but since stripe-php may be used with
// any API version, we need to support deserializing the older
// `file_upload` object into the same class.
const OBJECT_NAME = "file";
const OBJECT_NAME_ALT = "file_upload";
use ApiOperations\All;
use ApiOperations\Create {
create as protected _create;
}
use ApiOperations\Retrieve;
public static function classUrl()
{
return '/v1/files';
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return \Stripe\File The created resource.
*/
public static function create($params = null, $options = null)
{
$opts = \Stripe\Util\RequestOptions::parse($options);
if (is_null($opts->apiBase)) {
$opts->apiBase = Stripe::$apiUploadBase;
}
// Manually flatten params, otherwise curl's multipart encoder will
// choke on nested arrays.
// TODO: use array_column() once we drop support for PHP 5.4
$flatParams = [];
foreach (\Stripe\Util\Util::flattenParams($params) as $pair) {
$flatParams[$pair[0]] = $pair[1];
}
return static::_create($flatParams, $opts);
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace Stripe;
/**
* Class FileLink
*
* @property string $id
* @property string $object
* @property int $created
* @property bool $expired
* @property int $expires_at
* @property string $file
* @property bool $livemode
* @property StripeObject $metadata
* @property string $url
*
* @package Stripe
*/
class FileLink extends ApiResource
{
const OBJECT_NAME = "file_link";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}

View file

@ -0,0 +1,6 @@
<?php
namespace Stripe;
// For backwards compatibility, the `File` class is aliased to `FileUpload`.
class_alias('Stripe\\File', 'Stripe\\FileUpload');

View file

@ -0,0 +1,21 @@
<?php
namespace Stripe\HttpClient;
interface ClientInterface
{
/**
* @param string $method The HTTP method being used
* @param string $absUrl The URL being requested, including domain and protocol
* @param array $headers Headers to be used in the request (full strings, not KV pairs)
* @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 \Stripe\Error\Api
* @throws \Stripe\Error\ApiConnection
* @return array An array whose first element is raw request body, second
* element is HTTP status code and third array of HTTP headers.
*/
public function request($method, $absUrl, $headers, $params, $hasFile);
}

View file

@ -0,0 +1,460 @@
<?php
namespace Stripe\HttpClient;
use Stripe\Stripe;
use Stripe\Error;
use Stripe\Util;
// cURL constants are not defined in PHP < 5.5
// @codingStandardsIgnoreStart
// PSR2 requires all constants be upper case. Sadly, the CURL_SSLVERSION
// constants do not abide by those rules.
// Note the values 1 and 6 come from their position in the enum that
// defines them in cURL's source code.
if (!defined('CURL_SSLVERSION_TLSv1')) {
define('CURL_SSLVERSION_TLSv1', 1);
}
if (!defined('CURL_SSLVERSION_TLSv1_2')) {
define('CURL_SSLVERSION_TLSv1_2', 6);
}
// @codingStandardsIgnoreEnd
if (!defined('CURL_HTTP_VERSION_2TLS')) {
define('CURL_HTTP_VERSION_2TLS', 4);
}
class CurlClient implements ClientInterface
{
private static $instance;
public static function instance()
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
protected $defaultOptions;
protected $userAgentInfo;
protected $enablePersistentConnections = null;
protected $enableHttp2 = null;
protected $curlHandle = null;
/**
* CurlClient constructor.
*
* Pass in a callable to $defaultOptions that returns an array of CURLOPT_* values to start
* off a request with, or an flat array with the same format used by curl_setopt_array() to
* provide a static set of options. Note that many options are overridden later in the request
* call, including timeouts, which can be set via setTimeout() and setConnectTimeout().
*
* Note that request() will silently ignore a non-callable, non-array $defaultOptions, and will
* throw an exception if $defaultOptions returns a non-array value.
*
* @param array|callable|null $defaultOptions
*/
public function __construct($defaultOptions = null, $randomGenerator = null)
{
$this->defaultOptions = $defaultOptions;
$this->randomGenerator = $randomGenerator ?: new Util\RandomGenerator();
$this->initUserAgentInfo();
// TODO: curl_reset requires PHP >= 5.5.0. Once we drop support for PHP 5.4, we can simply
// initialize this to true.
$this->enablePersistentConnections = function_exists('curl_reset');
$this->enableHttp2 = $this->canSafelyUseHttp2();
}
public function __destruct()
{
$this->closeCurlHandle();
}
public function initUserAgentInfo()
{
$curlVersion = curl_version();
$this->userAgentInfo = [
'httplib' => 'curl ' . $curlVersion['version'],
'ssllib' => $curlVersion['ssl_version'],
];
}
public function getDefaultOptions()
{
return $this->defaultOptions;
}
public function getUserAgentInfo()
{
return $this->userAgentInfo;
}
/**
* @return boolean
*/
public function getEnablePersistentConnections()
{
return $this->enablePersistentConnections;
}
/**
* @param boolean $enable
*/
public function setEnablePersistentConnections($enable)
{
$this->enablePersistentConnections = $enable;
}
/**
* @return boolean
*/
public function getEnableHttp2()
{
return $this->enableHttp2;
}
/**
* @param boolean $enable
*/
public function setEnableHttp2($enable)
{
$this->enableHttp2 = $enable;
}
// USER DEFINED TIMEOUTS
const DEFAULT_TIMEOUT = 80;
const DEFAULT_CONNECT_TIMEOUT = 30;
private $timeout = self::DEFAULT_TIMEOUT;
private $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT;
public function setTimeout($seconds)
{
$this->timeout = (int) max($seconds, 0);
return $this;
}
public function setConnectTimeout($seconds)
{
$this->connectTimeout = (int) max($seconds, 0);
return $this;
}
public function getTimeout()
{
return $this->timeout;
}
public function getConnectTimeout()
{
return $this->connectTimeout;
}
// END OF USER DEFINED TIMEOUTS
public function request($method, $absUrl, $headers, $params, $hasFile)
{
$method = strtolower($method);
$opts = [];
if (is_callable($this->defaultOptions)) { // call defaultOptions callback, set options to return value
$opts = call_user_func_array($this->defaultOptions, func_get_args());
if (!is_array($opts)) {
throw new Error\Api("Non-array value returned by defaultOptions CurlClient callback");
}
} elseif (is_array($this->defaultOptions)) { // set default curlopts from array
$opts = $this->defaultOptions;
}
$params = Util\Util::objectsToIds($params);
if ($method == 'get') {
if ($hasFile) {
throw new Error\Api(
"Issuing a GET request with a file parameter"
);
}
$opts[CURLOPT_HTTPGET] = 1;
if (count($params) > 0) {
$encoded = Util\Util::encodeParameters($params);
$absUrl = "$absUrl?$encoded";
}
} elseif ($method == 'post') {
$opts[CURLOPT_POST] = 1;
$opts[CURLOPT_POSTFIELDS] = $hasFile ? $params : Util\Util::encodeParameters($params);
} elseif ($method == 'delete') {
$opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
if (count($params) > 0) {
$encoded = Util\Util::encodeParameters($params);
$absUrl = "$absUrl?$encoded";
}
} else {
throw new Error\Api("Unrecognized method $method");
}
// It is only safe to retry network failures on POST requests if we
// add an Idempotency-Key header
if (($method == 'post') && (Stripe::$maxNetworkRetries > 0)) {
if (!$this->hasHeader($headers, "Idempotency-Key")) {
array_push($headers, 'Idempotency-Key: ' . $this->randomGenerator->uuid());
}
}
// Create a callback to capture HTTP headers for the response
$rheaders = new Util\CaseInsensitiveArray();
$headerCallback = function ($curl, $header_line) use (&$rheaders) {
// Ignore the HTTP request line (HTTP/1.1 200 OK)
if (strpos($header_line, ":") === false) {
return strlen($header_line);
}
list($key, $value) = explode(":", trim($header_line), 2);
$rheaders[trim($key)] = trim($value);
return strlen($header_line);
};
// By default for large request body sizes (> 1024 bytes), cURL will
// send a request without a body and with a `Expect: 100-continue`
// header, which gives the server a chance to respond with an error
// status code in cases where one can be determined right away (say
// on an authentication problem for example), and saves the "large"
// request body from being ever sent.
//
// Unfortunately, the bindings don't currently correctly handle the
// success case (in which the server sends back a 100 CONTINUE), so
// we'll error under that condition. To compensate for that problem
// for the time being, override cURL's behavior by simply always
// sending an empty `Expect:` header.
array_push($headers, 'Expect: ');
$absUrl = Util\Util::utf8($absUrl);
$opts[CURLOPT_URL] = $absUrl;
$opts[CURLOPT_RETURNTRANSFER] = true;
$opts[CURLOPT_CONNECTTIMEOUT] = $this->connectTimeout;
$opts[CURLOPT_TIMEOUT] = $this->timeout;
$opts[CURLOPT_HEADERFUNCTION] = $headerCallback;
$opts[CURLOPT_HTTPHEADER] = $headers;
$opts[CURLOPT_CAINFO] = Stripe::getCABundlePath();
if (!Stripe::getVerifySslCerts()) {
$opts[CURLOPT_SSL_VERIFYPEER] = false;
}
if (!isset($opts[CURLOPT_HTTP_VERSION]) && $this->getEnableHttp2()) {
// For HTTPS requests, enable HTTP/2, if supported
$opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2TLS;
}
list($rbody, $rcode) = $this->executeRequestWithRetries($opts, $absUrl);
return [$rbody, $rcode, $rheaders];
}
/**
* @param array $opts cURL options
*/
private function executeRequestWithRetries($opts, $absUrl)
{
$numRetries = 0;
while (true) {
$rcode = 0;
$errno = 0;
$this->resetCurlHandle();
curl_setopt_array($this->curlHandle, $opts);
$rbody = curl_exec($this->curlHandle);
if ($rbody === false) {
$errno = curl_errno($this->curlHandle);
$message = curl_error($this->curlHandle);
} else {
$rcode = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
}
if (!$this->getEnablePersistentConnections()) {
$this->closeCurlHandle();
}
if ($this->shouldRetry($errno, $rcode, $numRetries)) {
$numRetries += 1;
$sleepSeconds = $this->sleepTime($numRetries);
usleep(intval($sleepSeconds * 1000000));
} else {
break;
}
}
if ($rbody === false) {
$this->handleCurlError($absUrl, $errno, $message, $numRetries);
}
return [$rbody, $rcode];
}
/**
* @param string $url
* @param int $errno
* @param string $message
* @param int $numRetries
* @throws Error\ApiConnection
*/
private function handleCurlError($url, $errno, $message, $numRetries)
{
switch ($errno) {
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_OPERATION_TIMEOUTED:
$msg = "Could not connect to Stripe ($url). Please check your "
. "internet connection and try again. If this problem persists, "
. "you should check Stripe's service status at "
. "https://twitter.com/stripestatus, or";
break;
case CURLE_SSL_CACERT:
case CURLE_SSL_PEER_CERTIFICATE:
$msg = "Could not verify Stripe's SSL certificate. Please make sure "
. "that your network is not intercepting certificates. "
. "(Try going to $url in your browser.) "
. "If this problem persists,";
break;
default:
$msg = "Unexpected error communicating with Stripe. "
. "If this problem persists,";
}
$msg .= " let us know at support@stripe.com.";
$msg .= "\n\n(Network error [errno $errno]: $message)";
if ($numRetries > 0) {
$msg .= "\n\nRequest was retried $numRetries times.";
}
throw new Error\ApiConnection($msg);
}
/**
* Checks if an error is a problem that we should retry on. This includes both
* socket errors that may represent an intermittent problem and some special
* HTTP statuses.
* @param int $errno
* @param int $rcode
* @param int $numRetries
* @return bool
*/
private function shouldRetry($errno, $rcode, $numRetries)
{
if ($numRetries >= Stripe::getMaxNetworkRetries()) {
return false;
}
// Retry on timeout-related problems (either on open or read).
if ($errno === CURLE_OPERATION_TIMEOUTED) {
return true;
}
// Destination refused the connection, the connection was reset, or a
// variety of other connection failures. This could occur from a single
// saturated server, so retry in case it's intermittent.
if ($errno === CURLE_COULDNT_CONNECT) {
return true;
}
// 409 conflict
if ($rcode === 409) {
return true;
}
return false;
}
private function sleepTime($numRetries)
{
// Apply exponential backoff with $initialNetworkRetryDelay on the
// number of $numRetries so far as inputs. Do not allow the number to exceed
// $maxNetworkRetryDelay.
$sleepSeconds = min(
Stripe::getInitialNetworkRetryDelay() * 1.0 * pow(2, $numRetries - 1),
Stripe::getMaxNetworkRetryDelay()
);
// Apply some jitter by randomizing the value in the range of
// ($sleepSeconds / 2) to ($sleepSeconds).
$sleepSeconds *= 0.5 * (1 + $this->randomGenerator->randFloat());
// But never sleep less than the base sleep seconds.
$sleepSeconds = max(Stripe::getInitialNetworkRetryDelay(), $sleepSeconds);
return $sleepSeconds;
}
/**
* Initializes the curl handle. If already initialized, the handle is closed first.
*/
private function initCurlHandle()
{
$this->closeCurlHandle();
$this->curlHandle = curl_init();
}
/**
* Closes the curl handle if initialized. Do nothing if already closed.
*/
private function closeCurlHandle()
{
if (!is_null($this->curlHandle)) {
curl_close($this->curlHandle);
$this->curlHandle = null;
}
}
/**
* Resets the curl handle. If the handle is not already initialized, or if persistent
* connections are disabled, the handle is reinitialized instead.
*/
private function resetCurlHandle()
{
if (!is_null($this->curlHandle) && $this->getEnablePersistentConnections()) {
curl_reset($this->curlHandle);
} else {
$this->initCurlHandle();
}
}
/**
* Indicates whether it is safe to use HTTP/2 or not.
*
* @return boolean
*/
private function canSafelyUseHttp2()
{
// Versions of curl older than 7.60.0 don't respect GOAWAY frames
// (cf. https://github.com/curl/curl/issues/2416), which Stripe use.
$curlVersion = curl_version()['version'];
return (version_compare($curlVersion, '7.60.0') >= 0);
}
/**
* Checks if a list of headers contains a specific header name.
*
* @param string[] $headers
* @param string $name
* @return boolean
*/
private function hasHeader($headers, $name)
{
foreach ($headers as $header) {
if (strncasecmp($header, "{$name}: ", strlen($name) + 2) === 0) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,195 @@
<?php
namespace Stripe;
/**
* Class Invoice
*
* @property string $id
* @property string $object
* @property string $account_country
* @property string $account_name
* @property int $amount_due
* @property int $amount_paid
* @property int $amount_remaining
* @property int $application_fee_amount
* @property int $attempt_count
* @property bool $attempted
* @property bool $auto_advance
* @property string $billing
* @property string $billing_reason
* @property string $charge
* @property string $collection_method
* @property int $created
* @property string $currency
* @property array $custom_fields
* @property string $customer
* @property mixed $customer_address
* @property string $customer_email
* @property string $customer_name
* @property string $customer_phone
* @property mixed $customer_shipping
* @property string $customer_tax_exempt
* @property array $customer_tax_ids
* @property string $default_payment_method
* @property string $default_source
* @property array $default_tax_rates
* @property string $description
* @property Discount $discount
* @property int $due_date
* @property int $ending_balance
* @property string $footer
* @property string $hosted_invoice_url
* @property string $invoice_pdf
* @property Collection $lines
* @property bool $livemode
* @property StripeObject $metadata
* @property int $next_payment_attempt
* @property string $number
* @property bool $paid
* @property string $payment_intent
* @property int $period_end
* @property int $period_start
* @property int $post_payment_credit_notes_amount
* @property int $pre_payment_credit_notes_amount
* @property string $receipt_number
* @property int $starting_balance
* @property string $statement_descriptor
* @property string $status
* @property mixed $status_transitions
* @property string $subscription
* @property int $subscription_proration_date
* @property int $subtotal
* @property int $tax
* @property mixed $threshold_reason
* @property int $total
* @property array $total_tax_amounts
* @property int $webhooks_delivered_at
*
* @package Stripe
*/
class Invoice extends ApiResource
{
const OBJECT_NAME = "invoice";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of the invoice status.
* @link https://stripe.com/docs/api/invoices/object#invoice_object-status
*/
const STATUS_DRAFT = 'draft';
const STATUS_OPEN = 'open';
const STATUS_PAID = 'paid';
const STATUS_UNCOLLECTIBLE = 'uncollectible';
const STATUS_VOID = 'void';
/**
* Possible string representations of the billing.
* @link https://stripe.com/docs/api/invoices/object#invoice_object-billing
*/
const BILLING_SEND_INVOICE = 'send_invoice';
const BILLING_CHARGE_AUTOMATICALLY = 'charge_automatically';
/**
* Possible string representations of the billing reason.
* @link https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
*/
const BILLING_REASON_SUBSCRIPTION = 'subscription';
const BILLING_REASON_SUBSCRIPTION_CREATE = 'subscription_create';
const BILLING_REASON_SUBSCRIPTION_CYCLE = 'subscription_cycle';
const BILLING_REASON_SUBSCRIPTION_UPDATE = 'subscription_update';
const BILLING_REASON_SUBSCRIPTION_THRESHOLD = 'subscription_threshold';
const BILLING_REASON_MANUAL = 'manual';
const BILLING_REASON_UPCOMING = 'upcoming';
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The finalized invoice.
*/
public function finalizeInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/finalize';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The uncollectible invoice.
*/
public function markUncollectible($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/mark_uncollectible';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The paid invoice.
*/
public function pay($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/pay';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The sent invoice.
*/
public function sendInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/send';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The upcoming invoice.
*/
public static function upcoming($params = null, $opts = null)
{
$url = static::classUrl() . '/upcoming';
list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
$obj = Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The voided invoice.
*/
public function voidInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/void';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Stripe;
/**
* Class InvoiceItem
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $currency
* @property string $customer
* @property int $date
* @property string $description
* @property bool $discountable
* @property string $invoice
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $period
* @property Plan $plan
* @property bool $proration
* @property int $quantity
* @property string $subscription
* @property string $subscription_item
* @property array $tax_rates
* @property int $unit_amount
*
* @package Stripe
*/
class InvoiceItem extends ApiResource
{
const OBJECT_NAME = "invoiceitem";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}

View file

@ -0,0 +1,32 @@
<?php
namespace Stripe;
/**
* Class InvoiceLineItem
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $currency
* @property string $description
* @property bool $discountable
* @property string $invoice_item
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $period
* @property Plan $plan
* @property bool $proration
* @property int $quantity
* @property string $subscription
* @property string $subscription_item
* @property array $tax_amounts
* @property array $tax_rates
* @property string $type
*
* @package Stripe
*/
class InvoiceLineItem extends ApiResource
{
const OBJECT_NAME = "line_item";
}

View file

@ -0,0 +1,25 @@
<?php
namespace Stripe;
/**
* Class IssuerFraudRecord
*
* @property string $id
* @property string $object
* @property string $charge
* @property int $created
* @property int $post_date
* @property string $fraud_type
* @property bool $livemode
*
* @package Stripe
*/
class IssuerFraudRecord extends ApiResource
{
const OBJECT_NAME = "issuer_fraud_record";
use ApiOperations\All;
use ApiOperations\Retrieve;
}

View file

@ -0,0 +1,68 @@
<?php
namespace Stripe\Issuing;
/**
* Class Authorization
*
* @property string $id
* @property string $object
* @property bool $approved
* @property string $authorization_method
* @property int $authorized_amount
* @property string $authorized_currency
* @property \Stripe\Collection $balance_transactions
* @property Card $card
* @property Cardholder $cardholder
* @property int $created
* @property int $held_amount
* @property string $held_currency
* @property bool $is_held_amount_controllable
* @property bool $livemode
* @property mixed $merchant_data
* @property \Stripe\StripeObject $metadata
* @property int $pending_authorized_amount
* @property int $pending_held_amount
* @property mixed $request_history
* @property string $status
* @property \Stripe\Collection $transactions
* @property mixed $verification_data
*
* @package Stripe\Issuing
*/
class Authorization extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.authorization";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
/**
* @param array|null $params
* @param array|string|null $options
*
* @return Authorization The approved authorization.
*/
public function approve($params = null, $options = null)
{
$url = $this->instanceUrl() . '/approve';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return Authorization The declined authorization.
*/
public function decline($params = null, $options = null)
{
$url = $this->instanceUrl() . '/decline';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Stripe\Issuing;
/**
* Class Card
*
* @property string $id
* @property string $object
* @property mixed $authorization_controls
* @property mixed $billing
* @property string $brand
* @property Cardholder $cardholder
* @property int $created
* @property string $currency
* @property int $exp_month
* @property int $exp_year
* @property string $last4
* @property bool $livemode
* @property \Stripe\StripeObject $metadata
* @property string $name
* @property mixed $shipping
* @property string $status
* @property string $type
*
* @package Stripe\Issuing
*/
class Card extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.card";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
/**
* @param array|null $params
* @param array|string|null $options
*
* @return CardDetails The card details associated with that issuing card.
*/
public function details($params = null, $options = null)
{
$url = $this->instanceUrl() . '/details';
list($response, $opts) = $this->_request('get', $url, $params, $options);
$obj = \Stripe\Util\Util::convertToStripeObject($response, $opts);
$obj->setLastResponse($response);
return $obj;
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Stripe\Issuing;
/**
* Class CardDetails
*
* @property string $id
* @property string $object
* @property Card $card
* @property string $cvc
* @property int $exp_month
* @property int $exp_year
* @property string $number
*
* @package Stripe\Issuing
*/
class CardDetails extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.card_details";
}

View file

@ -0,0 +1,30 @@
<?php
namespace Stripe\Issuing;
/**
* Class Cardholder
*
* @property string $id
* @property string $object
* @property mixed $billing
* @property int $created
* @property string $email
* @property bool $livemode
* @property \Stripe\StripeObject $metadata
* @property string $name
* @property string $phone_number
* @property string $status
* @property string $type
*
* @package Stripe\Issuing
*/
class Cardholder extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.cardholder";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}

View file

@ -0,0 +1,30 @@
<?php
namespace Stripe\Issuing;
/**
* Class Dispute
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $created
* @property string $currency
* @property mixed $evidence
* @property bool $livemode
* @property \Stripe\StripeObject $metadata
* @property string $reason
* @property string $status
* @property Transaction $transaction
*
* @package Stripe\Issuing
*/
class Dispute extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.dispute";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}

View file

@ -0,0 +1,33 @@
<?php
namespace Stripe\Issuing;
/**
* Class Transaction
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $authorization
* @property string $balance_transaction
* @property string $card
* @property string $cardholder
* @property int $created
* @property string $currency
* @property string $dispute
* @property bool $livemode
* @property mixed $merchant_data
* @property \Stripe\StripeObject $metadata
* @property string $type
*
* @package Stripe\Issuing
*/
class Transaction extends \Stripe\ApiResource
{
const OBJECT_NAME = "issuing.transaction";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}

View file

@ -0,0 +1,18 @@
<?php
namespace Stripe;
/**
* Class LoginLink
*
* @property string $object
* @property int $created
* @property string $url
*
* @package Stripe
*/
class LoginLink extends ApiResource
{
const OBJECT_NAME = "login_link";
}

View file

@ -0,0 +1,93 @@
<?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)
{
$params = $params ?: [];
$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::encodeParameters($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)
{
$params = $params ?: [];
$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;
}
}

View file

@ -0,0 +1,64 @@
<?php
namespace Stripe;
/**
* Class Order
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $amount_returned
* @property string $application
* @property int $application_fee
* @property string $charge
* @property int $created
* @property string $currency
* @property string $customer
* @property string $email
* @property string $external_coupon_code
* @property OrderItem[] $items
* @property bool $livemode
* @property StripeObject $metadata
* @property Collection $returns
* @property string $selected_shipping_method
* @property mixed $shipping
* @property array $shipping_methods
* @property string $status
* @property mixed $status_transitions
* @property int $updated
* @property string $upstream_id
*
* @package Stripe
*/
class Order extends ApiResource
{
const OBJECT_NAME = "order";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* @return Order The paid order.
*/
public function pay($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/pay';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @return OrderReturn The newly created return.
*/
public function returnOrder($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/returns';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
return Util\Util::convertToStripeObject($response, $opts);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Stripe;
/**
* Class OrderItem
*
* @property string $object
* @property int $amount
* @property string $currency
* @property string $description
* @property string $parent
* @property int $quantity
* @property string $type
*
* @package Stripe
*/
class OrderItem extends StripeObject
{
const OBJECT_NAME = "order_item";
}

View file

@ -0,0 +1,27 @@
<?php
namespace Stripe;
/**
* Class OrderReturn
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $created
* @property string $currency
* @property OrderItem[] $items
* @property bool $livemode
* @property string $order
* @property string $refund
*
* @package Stripe
*/
class OrderReturn extends ApiResource
{
const OBJECT_NAME = "order_return";
use ApiOperations\All;
use ApiOperations\Retrieve;
}

View file

@ -0,0 +1,107 @@
<?php
namespace Stripe;
/**
* Class PaymentIntent
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $amount_capturable
* @property int $amount_received
* @property string $application
* @property int $application_fee_amount
* @property int $canceled_at
* @property string $cancellation_reason
* @property string $capture_method
* @property Collection $charges
* @property string $client_secret
* @property string $confirmation_method
* @property int $created
* @property string $currency
* @property string $customer
* @property string $description
* @property mixed $last_payment_error
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $next_action
* @property string $on_behalf_of
* @property string $payment_method
* @property string[] $payment_method_types
* @property string $receipt_email
* @property string $review
* @property mixed $shipping
* @property string $source
* @property string $statement_descriptor
* @property string $status
* @property mixed $transfer_data
* @property string $transfer_group
*
* @package Stripe
*/
class PaymentIntent extends ApiResource
{
const OBJECT_NAME = "payment_intent";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* These constants are possible representations of the status field.
*
* @link https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status
*/
const STATUS_CANCELED = 'canceled';
const STATUS_PROCESSING = 'processing';
const STATUS_REQUIRES_ACTION = 'requires_action';
const STATUS_REQUIRES_CAPTURE = 'requires_capture';
const STATUS_REQUIRES_CONFIRMATION = 'requires_confirmation';
const STATUS_REQUIRES_PAYMENT_METHOD = 'requires_payment_method';
const STATUS_SUCCEEDED = 'succeeded';
/**
* @param array|null $params
* @param array|string|null $options
*
* @return PaymentIntent The canceled payment intent.
*/
public function cancel($params = null, $options = null)
{
$url = $this->instanceUrl() . '/cancel';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return PaymentIntent The captured payment intent.
*/
public function capture($params = null, $options = null)
{
$url = $this->instanceUrl() . '/capture';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $options
*
* @return PaymentIntent The confirmed payment intent.
*/
public function confirm($params = null, $options = null)
{
$url = $this->instanceUrl() . '/confirm';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Stripe;
/**
* Class PaymentMethod
*
* @property string $id
* @property string $object
* @property mixed $billing_details
* @property mixed $card
* @property mixed $card_present
* @property int $created
* @property string $customer
* @property mixed $ideal
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $sepa_debit
* @property string $type
*
* @package Stripe
*/
class PaymentMethod extends ApiResource
{
const OBJECT_NAME = "payment_method";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return PaymentMethod The attached payment method.
*/
public function attach($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/attach';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
/**
* @param array|null $params
* @param array|string|null $opts
*
* @return PaymentMethod The detached payment method.
*/
public function detach($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/detach';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}
}

View file

@ -0,0 +1,93 @@
<?php
namespace Stripe;
/**
* Class Payout
*
* @property string $id
* @property string $object
* @property int $amount
* @property int $arrival_date
* @property bool $automatic
* @property string $balance_transaction
* @property int $created
* @property string $currency
* @property string $description
* @property string $destination
* @property string $failure_balance_transaction
* @property string $failure_code
* @property string $failure_message
* @property bool $livemode
* @property StripeObject $metadata
* @property string $method
* @property string $source_type
* @property string $statement_descriptor
* @property string $status
* @property string $type
*
* @package Stripe
*/
class Payout extends ApiResource
{
const OBJECT_NAME = "payout";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Types of payout failure codes.
* @link https://stripe.com/docs/api#payout_failures
*/
const FAILURE_ACCOUNT_CLOSED = 'account_closed';
const FAILURE_ACCOUNT_FROZEN = 'account_frozen';
const FAILURE_BANK_ACCOUNT_RESTRICTED = 'bank_account_restricted';
const FAILURE_BANK_OWNERSHIP_CHANGED = 'bank_ownership_changed';
const FAILURE_COULD_NOT_PROCESS = 'could_not_process';
const FAILURE_DEBIT_NOT_AUTHORIZED = 'debit_not_authorized';
const FAILURE_DECLINED = 'declined';
const FAILURE_INCORRECT_ACCOUNT_HOLDER_NAME = 'incorrect_account_holder_name';
const FAILURE_INSUFFICIENT_FUNDS = 'insufficient_funds';
const FAILURE_INVALID_ACCOUNT_NUMBER = 'invalid_account_number';
const FAILURE_INVALID_CURRENCY = 'invalid_currency';
const FAILURE_NO_ACCOUNT = 'no_account';
const FAILURE_UNSUPPORTED_CARD = 'unsupported_card';
/**
* Possible string representations of the payout methods.
* @link https://stripe.com/docs/api/payouts/object#payout_object-method
*/
const METHOD_STANDARD = 'standard';
const METHOD_INSTANT = 'instant';
/**
* Possible string representations of the status of the payout.
* @link https://stripe.com/docs/api/payouts/object#payout_object-status
*/
const STATUS_CANCELED = 'canceled';
const STATUS_IN_TRANSIT = 'in_transit';
const STATUS_FAILED = 'failed';
const STATUS_PAID = 'paid';
const STATUS_PENDING = 'pending';
/**
* Possible string representations of the type of payout.
* @link https://stripe.com/docs/api/payouts/object#payout_object-type
*/
const TYPE_BANK_ACCOUNT = 'bank_account';
const TYPE_CARD = 'card';
/**
* @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;
}
}

View file

@ -0,0 +1,108 @@
<?php
namespace Stripe;
/**
* Class Person
*
* @package Stripe
*
* @property string $id
* @property string $object
* @property string $account
* @property mixed $address
* @property mixed $address_kana
* @property mixed $address_kanji
* @property int $created
* @property bool $deleted
* @property mixed $dob
* @property string $email
* @property string $first_name
* @property string $first_name_kana
* @property string $first_name_kanji
* @property string $gender
* @property bool $id_number_provided
* @property string $last_name
* @property string $last_name_kana
* @property string $last_name_kanji
* @property string $maiden_name
* @property StripeObject $metadata
* @property string $phone
* @property mixed $relationship
* @property mixed $requirements
* @property bool $ssn_last_4_provided
* @property mixed $verification
*/
class Person extends ApiResource
{
const OBJECT_NAME = "person";
use ApiOperations\Delete;
use ApiOperations\Update;
/**
* Possible string representations of a person's gender.
* @link https://stripe.com/docs/api/persons/object#person_object-gender
*/
const GENDER_MALE = 'male';
const GENDER_FEMALE = 'female';
/**
* Possible string representations of a person's verification status.
* @link https://stripe.com/docs/api/persons/object#person_object-verification-status
*/
const VERIFICATION_STATUS_PENDING = 'pending';
const VERIFICATION_STATUS_UNVERIFIED = 'unverified';
const VERIFICATION_STATUS_VERIFIED = 'verified';
/**
* @return string The API URL for this Stripe account reversal.
*/
public function instanceUrl()
{
$id = $this['id'];
$account = $this['account'];
if (!$id) {
throw new Error\InvalidRequest(
"Could not determine which URL to request: " .
"class instance has invalid ID: $id",
null
);
}
$id = Util\Util::utf8($id);
$account = Util\Util::utf8($account);
$base = Account::classUrl();
$accountExtn = urlencode($account);
$extn = urlencode($id);
return "$base/$accountExtn/persons/$extn";
}
/**
* @param array|string $_id
* @param array|string|null $_opts
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Persons cannot be accessed without an account ID. " .
"Retrieve a Person using \$account->retrievePerson('person_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
/**
* @param string $_id
* @param array|null $_params
* @param array|string|null $_options
*
* @throws \Stripe\Error\InvalidRequest
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Persons cannot be accessed without an account ID. " .
"Retrieve a Person using \$account->retrievePerson('person_id') instead.";
throw new Error\InvalidRequest($msg, null);
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Stripe;
/**
* Class Plan
*
* @package Stripe
*
* @property string $id
* @property string $object
* @property bool $active
* @property string $aggregate_usage
* @property int $amount
* @property string $billing_scheme
* @property int $created
* @property string $currency
* @property string $interval
* @property int $interval_count
* @property bool $livemode
* @property StripeObject $metadata
* @property string $nickname
* @property string $product
* @property mixed $tiers
* @property string $tiers_mode
* @property mixed $transform_usage
* @property int $trial_period_days
* @property string $usage_type
*/
class Plan extends ApiResource
{
const OBJECT_NAME = "plan";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}

View file

@ -0,0 +1,47 @@
<?php
namespace Stripe;
/**
* Class Product
*
* @property string $id
* @property string $object
* @property bool $active
* @property string[] $attributes
* @property string $caption
* @property int $created
* @property string[] $deactivate_on
* @property string $description
* @property string[] $images
* @property bool $livemode
* @property StripeObject $metadata
* @property string $name
* @property mixed $package_dimensions
* @property bool $shippable
* @property string $statement_descriptor
* @property string $type
* @property string $unit_label
* @property int $updated
* @property string $url
*
* @package Stripe
*/
class Product extends ApiResource
{
const OBJECT_NAME = "product";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of the type of product.
* @link https://stripe.com/docs/api/service_products/object#service_product_object-type
*/
const TYPE_GOOD = 'good';
const TYPE_SERVICE = 'service';
}

View file

@ -0,0 +1,32 @@
<?php
namespace Stripe\Radar;
/**
* Class ValueList
*
* @property string $id
* @property string $object
* @property string $alias
* @property int $created
* @property string $created_by
* @property string $item_type
* @property Collection $list_items
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $name
* @property int $updated
* @property string $updated_by
*
* @package Stripe\Radar
*/
class ValueList extends \Stripe\ApiResource
{
const OBJECT_NAME = "radar.value_list";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Delete;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}

View file

@ -0,0 +1,26 @@
<?php
namespace Stripe\Radar;
/**
* Class ValueListItem
*
* @property string $id
* @property string $object
* @property int $created
* @property string $created_by
* @property string $list
* @property bool $livemode
* @property string $value
*
* @package Stripe\Radar
*/
class ValueListItem extends \Stripe\ApiResource
{
const OBJECT_NAME = "radar.value_list_item";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Delete;
use \Stripe\ApiOperations\Retrieve;
}

View file

@ -0,0 +1,48 @@
<?php
namespace Stripe;
/**
* Class Recipient
*
* @package Stripe
*
* @property string $id
* @property string $object
* @property mixed $active_account
* @property Collection $cards
* @property int $created
* @property string $default_card
* @property string $description
* @property string $email
* @property bool $livemode
* @property StripeObject $metadata
* @property string $migrated_to
* @property string $name
* @property string $rolled_back_from
* @property string $type
*/
class Recipient extends ApiResource
{
const OBJECT_NAME = "recipient";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* @param array|null $params
*
* @return Collection of the Recipient's Transfers
*/
public function transfers($params = null)
{
$params = $params ?: [];
$params['recipient'] = $this->id;
$transfers = Transfer::all($params, $this->_opts);
return $transfers;
}
}

View file

@ -0,0 +1,39 @@
<?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 StripeObject $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
{
const OBJECT_NAME = "recipient_transfer";
}

View file

@ -0,0 +1,61 @@
<?php
namespace Stripe;
/**
* Class Refund
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $balance_transaction
* @property string $charge
* @property int $created
* @property string $currency
* @property string $description
* @property string $failure_balance_transaction
* @property string $failure_reason
* @property StripeObject $metadata
* @property string $reason
* @property string $receipt_number
* @property string $source_transfer_reversal
* @property string $status
* @property string $transfer_reversal
*
* @package Stripe
*/
class Refund extends ApiResource
{
const OBJECT_NAME = "refund";
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
/**
* Possible string representations of the failure reason.
* @link https://stripe.com/docs/api/refunds/object#refund_object-failure_reason
*/
const FAILURE_REASON = 'expired_or_canceled_card';
const FAILURE_REASON_LOST_OR_STOLEN_CARD = 'lost_or_stolen_card';
const FAILURE_REASON_UNKNOWN = 'unknown';
/**
* Possible string representations of the refund reason.
* @link https://stripe.com/docs/api/refunds/object#refund_object-reason
*/
const REASON_DUPLICATE = 'duplicate';
const REASON_FRAUDULENT = 'fraudulent';
const REASON_REQUESTED_BY_CUSTOMER = 'requested_by_customer';
/**
* Possible string representations of the refund status.
* @link https://stripe.com/docs/api/refunds/object#refund_object-status
*/
const STATUS_CANCELED = 'canceled';
const STATUS_FAILED = 'failed';
const STATUS_PENDING = 'pending';
const STATUS_SUCCEEDED = 'succeeded';
}

View file

@ -0,0 +1,28 @@
<?php
namespace Stripe\Reporting;
/**
* Class ReportRun
*
* @property string $id
* @property string $object
* @property int $created
* @property string $error
* @property bool $livemode
* @property mixed $parameters
* @property string $report_type
* @property mixed $result
* @property string $status
* @property int $succeeded_at
*
* @package Stripe\Reporting
*/
class ReportRun extends \Stripe\ApiResource
{
const OBJECT_NAME = "reporting.report_run";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
}

View file

@ -0,0 +1,24 @@
<?php
namespace Stripe\Reporting;
/**
* Class ReportType
*
* @property string $id
* @property string $object
* @property int $data_available_end
* @property int $data_available_start
* @property string $name
* @property int $updated
* @property string $version
*
* @package Stripe\Reporting
*/
class ReportType extends \Stripe\ApiResource
{
const OBJECT_NAME = "reporting.report_type";
use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Retrieve;
}

View file

@ -0,0 +1,27 @@
<?php
namespace Stripe;
/**
* Class RequestTelemetry
*
* Tracks client request telemetry
* @package Stripe
*/
class RequestTelemetry
{
public $requestId;
public $requestDuration;
/**
* Initialize a new telemetry object.
*
* @param string $requestId The request's request ID.
* @param int $requestDuration The request's duration in milliseconds.
*/
public function __construct($requestId, $requestDuration)
{
$this->requestId = $requestId;
$this->requestDuration = $requestDuration;
}
}

View file

@ -0,0 +1,57 @@
<?php
namespace Stripe;
/**
* Class Review
*
* @property string $id
* @property string $object
* @property string $billing_zip
* @property string $charge
* @property string $closed_reason
* @property int $created
* @property string $ip_address
* @property mixed $ip_address_location
* @property bool $livemode
* @property bool $open
* @property string $opened_reason
* @property string $payment_intent
* @property string $reason
* @property mixed $session
*
* @package Stripe
*/
class Review extends ApiResource
{
const OBJECT_NAME = "review";
use ApiOperations\All;
use ApiOperations\Retrieve;
/**
* Possible string representations of the current, the opening or the closure reason of the review.
* Not all of these enumeration apply to all of the ´reason´ fields. Please consult the Review object to
* determine where these are apply.
* @link https://stripe.com/docs/api/radar/reviews/object
*/
const REASON_APPROVED = 'approved';
const REASON_DISPUTED = 'disputed';
const REASON_MANUAL = 'manual';
const REASON_REFUNDED = 'refunded';
const REASON_REFUNDED_AS_FRAUD = 'refunded_as_fraud';
const REASON_RULE = 'rule';
/**
* @param array|string|null $options
*
* @return Review The approved review.
*/
public function approve($params = null, $options = null)
{
$url = $this->instanceUrl() . '/approve';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}
}

Some files were not shown because too many files have changed in this diff Show more