M2_Stripe_Util

The Membership 2 M2 Stripe Util class.

Defined (1)

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

/lib/stripe-php/lib/Stripe/Util.php  
  1. abstract class M2_Stripe_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 M2_Stripe_Object) { 
  29. $results[$k] = $v->__toArray(true); 
  30. } else if (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 string $apiKey 
  40. * @return Stripe_Object|array 
  41. */ 
  42. public static function convertToStripeObject($resp, $apiKey) 
  43. $types = array( 
  44. 'card' => 'M2_Stripe_Card',  
  45. 'charge' => 'M2_Stripe_Charge',  
  46. 'customer' => 'M2_Stripe_Customer',  
  47. 'list' => 'M2_Stripe_List',  
  48. 'invoice' => 'M2_Stripe_Invoice',  
  49. 'invoiceitem' => 'M2_Stripe_InvoiceItem',  
  50. 'event' => 'M2_Stripe_Event',  
  51. 'transfer' => 'M2_Stripe_Transfer',  
  52. 'plan' => 'M2_Stripe_Plan',  
  53. 'recipient' => 'M2_Stripe_Recipient',  
  54. 'refund' => 'M2_Stripe_Refund',  
  55. 'subscription' => 'M2_Stripe_Subscription' 
  56. ); 
  57. if (self::isList($resp)) { 
  58. $mapped = array(); 
  59. foreach ($resp as $i) 
  60. array_push($mapped, self::convertToStripeObject($i, $apiKey)); 
  61. return $mapped; 
  62. } else if (is_array($resp)) { 
  63. if (isset($resp['object']) 
  64. && is_string($resp['object']) 
  65. && isset($types[$resp['object']])) { 
  66. $class = $types[$resp['object']]; 
  67. } else { 
  68. $class = 'M2_Stripe_Object'; 
  69. return M2_Stripe_Object::scopedConstructFrom($class, $resp, $apiKey); 
  70. } else { 
  71. return $resp;