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. private static $isMbstringAvailable = null; 
  3.  
  4. /** 
  5. * Whether the provided array (or other) is a list rather than a dictionary. 
  6. * @param array|mixed $array 
  7. * @return boolean True if the given object is a list. 
  8. */ 
  9. public static function isList($array) 
  10. if (!is_array($array)) { 
  11. return false; 
  12.  
  13. // TODO: generally incorrect, but it's correct given Stripe's response 
  14. foreach (array_keys($array) as $k) { 
  15. if (!is_numeric($k)) { 
  16. return false; 
  17. return true; 
  18.  
  19. /** 
  20. * Recursively converts the PHP Stripe object to an array. 
  21. * @param array $values The PHP Stripe object to convert. 
  22. * @return array 
  23. */ 
  24. public static function convertStripeObjectToArray($values) 
  25. $results = array(); 
  26. foreach ($values as $k => $v) { 
  27. // FIXME: this is an encapsulation violation 
  28. if ($k[0] == '_') { 
  29. continue; 
  30. if ($v instanceof StripeObject) { 
  31. $results[$k] = $v->__toArray(true); 
  32. } elseif (is_array($v)) { 
  33. $results[$k] = self::convertStripeObjectToArray($v); 
  34. } else { 
  35. $results[$k] = $v; 
  36. return $results; 
  37.  
  38. /** 
  39. * Converts a response from the Stripe API to the corresponding PHP object. 
  40. * @param array $resp The response from the Stripe API. 
  41. * @param array $opts 
  42. * @return StripeObject|array 
  43. */ 
  44. public static function convertToStripeObject($resp, $opts) 
  45. $types = array( 
  46. 'account' => 'PPP\\Stripe\\Account',  
  47. 'alipay_account' => 'PPP\\Stripe\\AlipayAccount',  
  48. 'apple_pay_domain' => 'PPP\\Stripe\\ApplePayDomain',  
  49. 'bank_account' => 'PPP\\Stripe\\BankAccount',  
  50. 'balance_transaction' => 'PPP\\Stripe\\BalanceTransaction',  
  51. 'card' => 'PPP\\Stripe\\Card',  
  52. 'charge' => 'PPP\\Stripe\\Charge',  
  53. 'country_spec' => 'PPP\\Stripe\\CountrySpec',  
  54. 'coupon' => 'PPP\\Stripe\\Coupon',  
  55. 'customer' => 'PPP\\Stripe\\Customer',  
  56. 'dispute' => 'PPP\\Stripe\\Dispute',  
  57. 'list' => 'PPP\\Stripe\\Collection',  
  58. 'invoice' => 'PPP\\Stripe\\Invoice',  
  59. 'invoiceitem' => 'PPP\\Stripe\\InvoiceItem',  
  60. 'event' => 'PPP\\Stripe\\Event',  
  61. 'file' => 'PPP\\Stripe\\FileUpload',  
  62. 'token' => 'PPP\\Stripe\\Token',  
  63. 'transfer' => 'PPP\\Stripe\\Transfer',  
  64. 'transfer_reversal' => 'PPP\\Stripe\\TransferReversal',  
  65. 'order' => 'PPP\\Stripe\\Order',  
  66. 'order_return' => 'PPP\\Stripe\\OrderReturn',  
  67. 'plan' => 'PPP\\Stripe\\Plan',  
  68. 'product' => 'PPP\\Stripe\\Product',  
  69. 'recipient' => 'PPP\\Stripe\\Recipient',  
  70. 'refund' => 'PPP\\Stripe\\Refund',  
  71. 'sku' => 'PPP\\Stripe\\SKU',  
  72. 'source' => 'PPP\\Stripe\\Source',  
  73. 'subscription' => 'PPP\\Stripe\\Subscription',  
  74. 'subscription_item' => 'PPP\\Stripe\\SubscriptionItem',  
  75. 'three_d_secure' => 'PPP\\Stripe\\ThreeDSecure',  
  76. 'fee_refund' => 'PPP\\Stripe\\ApplicationFeeRefund',  
  77. 'bitcoin_receiver' => 'PPP\\Stripe\\BitcoinReceiver',  
  78. 'bitcoin_transaction' => 'PPP\\Stripe\\BitcoinTransaction',  
  79. ); 
  80. if (self::isList($resp)) { 
  81. $mapped = array(); 
  82. foreach ($resp as $i) { 
  83. array_push($mapped, self::convertToStripeObject($i, $opts)); 
  84. return $mapped; 
  85. } elseif (is_array($resp)) { 
  86. if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']])) { 
  87. $class = $types[$resp['object']]; 
  88. } else { 
  89. $class = 'PPP\\Stripe\\StripeObject'; 
  90. return $class::constructFrom($resp, $opts); 
  91. } else { 
  92. return $resp; 
  93.  
  94. /** 
  95. * @param string|mixed $value A string to UTF8-encode. 
  96. * @return string|mixed The UTF8-encoded string, or the object passed in if 
  97. * it wasn't a string. 
  98. */ 
  99. public static function utf8($value) 
  100. if (self::$isMbstringAvailable === null) { 
  101. self::$isMbstringAvailable = function_exists('mb_detect_encoding'); 
  102.  
  103. if (!self::$isMbstringAvailable) { 
  104. trigger_error("It looks like the mbstring extension is not enabled. " . 
  105. "UTF-8 strings will not properly be encoded. Ask your system " . 
  106. "administrator to enable the mbstring extension, or write to " . 
  107. "support@stripe.com if you have any questions.", E_USER_WARNING); 
  108.  
  109. if (is_string($value) && self::$isMbstringAvailable && mb_detect_encoding($value, "UTF-8", true) != "UTF-8") { 
  110. return utf8_encode($value); 
  111. } else { 
  112. return $value;