Passing more order information to Stripe
I'm currently using the following on my cart page:
if (perch_member_logged_in() && perch_post('stripeToken')) {
$return_url = '/pay/success';
$cancel_url = '/pay/error';
perch_shop_checkout('stripe', [
'return_url' => $return_url,
'cancel_url' => $cancel_url,
'token' => perch_post('stripeToken')
]);
}
When the orders show up in Stripe they come through as "Order X" with just the customers email address. How can I pass over more information? I'd like to pass over the SKU of the items ordered, for example. I've also noticed that the customer address doesn't get passed over, so in Stripe you get:
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": "MK17 6UT",
The postcode is there because I have that as an optional extra field when the customer enters their card details. How do I get the rest of the info filled in?
I think you can set
metadata
as an array of key/value pairs.Great. Here's what I've got so far:
For my $customer_order is there a way I can pass in what the customer has in their cart?
Yes, everything you need should be available from
perch_shop_cart()
withskip-template
.It works for the 'perch:shop' cart values but I can't seem to be able to grab the 'perch:cartitem' values which is what I need (title/description). Here's what I've got:
No? What do you get?
The following works fine so I know I can access the template data:
But if I use the following nothing gets output (as if 'title' doesn't exist in the template):
I'm trying to access <perch:cartitem id="title" />
What does
print_r($cart)
show you?I can see the information I want inside that array (sku, title, slug) but how do I get it out...
Looks like it's
$cart['items']
If I do:
That outputs "Array". How do I specify the title and sku within the items array?
You'd need to loop through the array and find the items you want.
Could you help me with that please? My brain is hurting trying to figure it out!
This is PHP rather than Perch specific, a Google for information about how to loop through a PHP array would be a good start.
With some help I have done it. For anyone else who needs this in future:
Can I also use the metadata to pass information to Paypal? The order description in paypal currently shows as "Order #X" which isn't very.... descriptive.
What result are you getting?
No result - nothing is being passed to the paypal checkout or is visible in the transaction details. I tried:
Ok, I'll have to dig through the Omnipay driver and see if they've implemented it.
That would be great because currently in Paypal there's no way of knowing what the customer bought, only the amount they paid. You'd have to cross-check with the Perch admin to find out the purchase.
Will you post back here when you've found the answer?
Thanks.
Why do you need to know this at the PayPal end when you have it in Perch?