Open patrickyan opened 11 years ago
I guess I need explanation on this line:
If you want response data saved from the Stripe response into a section, that section needs to have the filter and the section's field handles must match Stripe's response (_ are automatically converted into -, and vice a versa). This allows the greatest flexibility allowing the Symphony CMS developer to choose what information they want to save in the section.
Take this response
{
"object": "customer",
"created": 1378743556,
"id": "cus_2XccWEuqu6Wuqg",
"livemode": false,
"description": null,
"email": null,
"delinquent": false,
"subscription": null,
"discount": null,
"account_balance": 0,
"cards": {
"object": "list",
"count": 1,
"url": "/v1/customers/cus_2XccWEuqu6Wuqg/cards",
"data": [
{
"id": "card_2XccD5dkwFCzmU",
"object": "card",
"last4": "4242",
"type": "Visa",
"exp_month": 3,
"exp_year": 2054,
"fingerprint": "qhjxpr7DiCdFYTlH",
"customer": "cus_2XccWEuqu6Wuqg",
"country": "US",
"name": "Asfds Sgf",
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": null,
"address_country": null,
"cvc_check": "pass",
"address_line1_check": null,
"address_zip_check": null
}
]
},
"default_card": "card_2XccD5dkwFCzmU"
}
I guess I need to add an event on the page for my users section. Then I need to have fields in that section called id
, etc. But how does the cards
data get stored in a field?
I also ran into the problem of getting stripes 2nd dimension values stored into fields. Looking through the code, I figured how to get them, but I think there is a mistake in how it works.
Creating a field called "handle-handle" or "object-object" in the section's event will capture those responses inside "card". I think this was suppose to be "card-handle" and "card-object". You can make this more sensible naming scheme work if you edit stripe/lib/class.stripegeneral.php
on line 90:
foreach($val as $k => $v) {
if(!empty($v)) {
$key = str_replace('_', '-', $k);
$result[$key . '-' . $k] = $v;
}
}
to this:
foreach($val as $k => $v) {
if(!empty($v)) {
$k = str_replace('_', '-', $k); // $key to $k
$result[$key . '-' . $k] = $v;
}
}
Also, the Stripe response your trying to store is up to 3 dimensions with the array. To get the stuff inside [cards][data] you could add some more lines to search for those values like this:
foreach($val as $k => $v) {
if(!is_object($v) && !is_array($v) && !empty($v)) {
$k = str_replace('_', '-', $k);
$result[$key . '-' . $k] = $v;
} elseif (!is_object($v) && !empty($v)) {
foreach($v as $k2 => $v2) {
$k2 = str_replace('_', '-', $k);
$result[$key . '-' . $k . '-' . $k2];
}
}
}
You should then be able to post to section fields with cards-data-id or cards-data-last4, etc. @lewiswharf : Can I suggest these lines be changed in your repo?
@colinbrogan sorry I missed this issue. Have your modifications been working?
Yes, the first change is in one of my forks. I'm pretty certain that was a coding mistake, no? Did you actually want cards > count
in the json to be grabbed from count-count
.
I never tried the code for pulling from the 3rd level of nesting in the json, but I'm pretty confident it should work.
This is a bad-ass plugin for a bad-ass payment platform, btw.
I'm pretty certain that was a coding mistake, no?
Yes. Thank you for your comments above. I was pulling hairs getting this extension to work with event filters. It's part of a slow project that is actually going live next week so I will get a chance to find some more stupid mistakes In the coming days.
On the forum thread, you mention some sections and fields, but it looks like that was actually before you made the extension.
I get that you pass all the arguments with inputs
stripe[blah]
. But how does this translate into your Symphony sections?E.g., after you create a customer, how does the stripe customer ID (example response) get into your Symphony users section? Likewise with the charges.
And along with that, what's the customer link for?