mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
cc586b0afa
Summary: various stripe stuff, including - external stripe library - payment form - test controller to play with payment form, sample business logic My main questions / discussion topics are... - is the stripe PHP library too big? (ie should I write something more simple just for phabricator?) -- if its cool, what is the best way to include the client? (ie should I make it a submodule rather than the flat copy here?) - is the JS I wrote (too) ridiculous? -- particularly unhappy with the error message stuff being in JS *but* it seemed the best choice given the most juicy error messages come from the stripe JS such that the overall code complexity is lowest this way. - how should the stripe JS be included? -- flat copy like I did here? -- some sort of external? -- can we just load it off stripe servers at request time? (I like that from the "if stripe is down, stripe is down" perspective) - wasn't sure if the date control was too silly and should just be baked into the form? -- for some reason I feel like its good to be prepared to walk away from Stripe / switch providers here, though I think this is on the wrong side of pragmatic Test Plan: - played around with sample client form Reviewers: epriestley Reviewed By: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2096
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
abstract class Stripe_Util
|
|
{
|
|
public static function isList($array)
|
|
{
|
|
if (!is_array($array))
|
|
return false;
|
|
// TODO: this isn't actually correct in general, but it's correct given Stripe's responses
|
|
foreach (array_keys($array) as $k) {
|
|
if (!is_numeric($k))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function convertStripeObjectToArray($values)
|
|
{
|
|
$results = array();
|
|
foreach ($values as $k => $v) {
|
|
// FIXME: this is an encapsulation violation
|
|
if (Stripe_Object::$_permanentAttributes->includes($k)) {
|
|
continue;
|
|
}
|
|
if ($v instanceof Stripe_Object) {
|
|
$results[$k] = $v->__toArray(true);
|
|
}
|
|
else if (is_array($v)) {
|
|
$results[$k] = self::convertStripeObjectToArray($v);
|
|
}
|
|
else {
|
|
$results[$k] = $v;
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
public static function convertToStripeObject($resp, $apiKey)
|
|
{
|
|
$types = array('charge' => 'Stripe_Charge',
|
|
'customer' => 'Stripe_Customer',
|
|
'invoice' => 'Stripe_Invoice',
|
|
'invoiceitem' => 'Stripe_InvoiceItem', 'event' => 'Stripe_Event');
|
|
if (self::isList($resp)) {
|
|
$mapped = array();
|
|
foreach ($resp as $i)
|
|
array_push($mapped, self::convertToStripeObject($i, $apiKey));
|
|
return $mapped;
|
|
} else if (is_array($resp)) {
|
|
if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']]))
|
|
$class = $types[$resp['object']];
|
|
else
|
|
$class = 'Stripe_Object';
|
|
return Stripe_Object::scopedConstructFrom($class, $resp, $apiKey);
|
|
} else {
|
|
return $resp;
|
|
}
|
|
}
|
|
}
|