PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/clfc/wp-content/plugins/marketpress/marketpress-includes/plugins-gateway/stripe-files/lib/Stripe/ApiResource.php

https://gitlab.com/Henaway/CLFC
PHP | 97 lines | 93 code | 3 blank | 1 comment | 1 complexity | 9089b72044eadd79a423c9439e73bfd3 MD5 | raw file
  1. <?php
  2. abstract class Stripe_ApiResource extends Stripe_Object
  3. {
  4. protected static function _scopedRetrieve($class, $id, $apiKey=null)
  5. {
  6. $instance = new $class($id, $apiKey);
  7. $instance->refresh();
  8. return $instance;
  9. }
  10. public function refresh()
  11. {
  12. $requestor = new Stripe_ApiRequestor($this->_apiKey);
  13. $url = $this->instanceUrl();
  14. list($response, $apiKey) = $requestor->request('get', $url);
  15. $this->refreshFrom($response, $apiKey);
  16. return $this;
  17. }
  18. public static function classUrl($class)
  19. {
  20. // Useful for namespaces: Foo\Stripe_Charge
  21. if ($postfix = strrchr($class, '\\'))
  22. $class = substr($postfix, 1);
  23. if (substr($class, 0, strlen('Stripe')) == 'Stripe')
  24. $class = substr($class, strlen('Stripe'));
  25. $class = str_replace('_', '', $class);
  26. $name = urlencode($class);
  27. $name = strtolower($name);
  28. return "/${name}s";
  29. }
  30. public function instanceUrl()
  31. {
  32. $id = $this['id'];
  33. $class = get_class($this);
  34. if (!$id) {
  35. throw new Stripe_InvalidRequestError("Could not determine which URL to request: $class instance has invalid ID: $id");
  36. }
  37. $id = Stripe_ApiRequestor::utf8($id);
  38. $base = self::classUrl($class);
  39. $extn = urlencode($id);
  40. return "$base/$extn";
  41. }
  42. private static function _validateCall($method, $params=null, $apiKey=null)
  43. {
  44. if ($params && !is_array($params))
  45. throw new Stripe_Error("You must pass an array as the first argument to Stripe API method calls. (HINT: an example call to create a charge would be: \"StripeCharge::create(array('amount' => 100, 'currency' => 'usd', 'card' => array('number' => 4242424242424242, 'exp_month' => 5, 'exp_year' => 2015)))\")");
  46. if ($apiKey && !is_string($apiKey))
  47. throw new Stripe_Error('The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string. (HINT: you can set a global apiKey by "Stripe::setApiKey(<apiKey>)")');
  48. }
  49. protected static function _scopedAll($class, $params=null, $apiKey=null)
  50. {
  51. self::_validateCall('all', $params, $apiKey);
  52. $requestor = new Stripe_ApiRequestor($apiKey);
  53. $url = self::classUrl($class);
  54. list($response, $apiKey) = $requestor->request('get', $url, $params);
  55. return Stripe_Util::convertToStripeObject($response, $apiKey);
  56. }
  57. protected static function _scopedCreate($class, $params=null, $apiKey=null)
  58. {
  59. self::_validateCall('create', $params, $apiKey);
  60. $requestor = new Stripe_ApiRequestor($apiKey);
  61. $url = self::classUrl($class);
  62. list($response, $apiKey) = $requestor->request('post', $url, $params);
  63. return Stripe_Util::convertToStripeObject($response, $apiKey);
  64. }
  65. protected function _scopedSave($class)
  66. {
  67. self::_validateCall('save');
  68. if ($this->_unsavedValues) {
  69. $requestor = new Stripe_ApiRequestor($this->_apiKey);
  70. $params = array();
  71. foreach ($this->_unsavedValues->toArray() as $k)
  72. $params[$k] = $this->$k;
  73. $url = $this->instanceUrl();
  74. list($response, $apiKey) = $requestor->request('post', $url, $params);
  75. $this->refreshFrom($response, $apiKey);
  76. }
  77. return $this;
  78. }
  79. protected function _scopedDelete($class, $params=null)
  80. {
  81. self::_validateCall('delete');
  82. $requestor = new Stripe_ApiRequestor($this->_apiKey);
  83. $url = $this->instanceUrl();
  84. list($response, $apiKey) = $requestor->request('delete', $url, $params);
  85. $this->refreshFrom($response, $apiKey);
  86. return $this;
  87. }
  88. }