PPPStripeUtilUtil

The Gravity Forms + Stripe PPP Stripe Util class.

Defined (1)

The class is defined in the following location(s).

/includes/api/stripe-php/lib/Util/Util.php  
  1. abstract class Util 
  2. /** 
  3. * Whether the provided array (or other) is a list rather than a dictionary. 
  4. * @param array|mixed $array 
  5. * @return boolean True if the given object is a list. 
  6. */ 
  7. public static function isList($array) 
  8. if (!is_array($array)) { 
  9. return false; 
  10.  
  11. // TODO: generally incorrect, but it's correct given Stripe's response 
  12. foreach (array_keys($array) as $k) { 
  13. if (!is_numeric($k)) { 
  14. return false; 
  15. return true; 
  16.  
  17. /** 
  18. * Recursively converts the PHP Stripe object to an array. 
  19. * @param array $values The PHP Stripe object to convert. 
  20. * @return array 
  21. */ 
  22. public static function convertStripeObjectToArray($values) 
  23. $results = array(); 
  24. foreach ($values as $k => $v) { 
  25. // FIXME: this is an encapsulation violation 
  26. if ($k[0] == '_') { 
  27. continue; 
  28. if ($v instanceof Object) { 
  29. $results[$k] = $v->__toArray(true); 
  30. } elseif (is_array($v)) { 
  31. $results[$k] = self::convertStripeObjectToArray($v); 
  32. } else { 
  33. $results[$k] = $v; 
  34. return $results; 
  35.  
  36. /** 
  37. * Converts a response from the Stripe API to the corresponding PHP object. 
  38. * @param array $resp The response from the Stripe API. 
  39. * @param array $opts 
  40. * @return Object|array 
  41. */ 
  42. public static function convertToStripeObject($resp, $opts) 
  43. $types = array( 
  44. 'account' => 'PPP\\Stripe\\Account',  
  45. 'card' => 'PPP\\Stripe\\Card',  
  46. 'charge' => 'PPP\\Stripe\\Charge',  
  47. 'country_spec' => 'PPP\\Stripe\\CountrySpec',  
  48. 'coupon' => 'PPP\\Stripe\\Coupon',  
  49. 'customer' => 'PPP\\Stripe\\Customer',  
  50. 'list' => 'PPP\\Stripe\\Collection',  
  51. 'invoice' => 'PPP\\Stripe\\Invoice',  
  52. 'invoiceitem' => 'PPP\\Stripe\\InvoiceItem',  
  53. 'event' => 'PPP\\Stripe\\Event',  
  54. 'file' => 'PPP\\Stripe\\FileUpload',  
  55. 'token' => 'PPP\\Stripe\\Token',  
  56. 'transfer' => 'PPP\\Stripe\\Transfer',  
  57. 'plan' => 'PPP\\Stripe\\Plan',  
  58. 'recipient' => 'PPP\\Stripe\\Recipient',  
  59. 'refund' => 'PPP\\Stripe\\Refund',  
  60. 'subscription' => 'PPP\\Stripe\\Subscription',  
  61. 'fee_refund' => 'PPP\\Stripe\\ApplicationFeeRefund',  
  62. 'bitcoin_receiver' => 'PPP\\Stripe\\BitcoinReceiver',  
  63. 'bitcoin_transaction' => 'PPP\\Stripe\\BitcoinTransaction',  
  64. ); 
  65. if (self::isList($resp)) { 
  66. $mapped = array(); 
  67. foreach ($resp as $i) { 
  68. array_push($mapped, self::convertToStripeObject($i, $opts)); 
  69. return $mapped; 
  70. } elseif (is_array($resp)) { 
  71. if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']])) { 
  72. $class = $types[$resp['object']]; 
  73. } else { 
  74. $class = 'PPP\\Stripe\\Object'; 
  75. return $class::constructFrom($resp, $opts); 
  76. } else { 
  77. return $resp;