Forum
Perch Shop Checkout with PayPal Express
Hi,
I'm trying to call PayPal Express through the perch_shop_checkout function as below:
if (perch_member_logged_in()) {
// your 'success' return URL
$return_url = 'https://mysite.com/payment';
$cancel_url = 'https://mysite.com/';
perch_shop_checkout('paypal-express', [
'return_url' => $return_url,
'cancel_url' => $cancel_url,
]);
}
We've set-up the api details under perch/config/shop.php, but not the testing ones yet.
However, when calling the checkout, nothing happens, but I've left debug mode on, and there is an error related to shipping (order shipping total cannot be null):
Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='a10e098d97fe1075c6ba97dc5795289b4f6958ba' AND sessionHttpFootprint='5e2ba474617694890918708760dff203f74e6d0d' AND sessionExpires>'2016-05-20 16:23:48' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/shop/checkout.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
[10] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/shop/checkout.php' OR regionPage='*' ORDER BY regionPage DESC
Checking out with paypal-express
Member ID: 1
[1] SELECT * FROM perch2_shop_customers WHERE memberID=1
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=8
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='1' AND orderID IS NULL AND addressSlug='default'
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='1' AND orderID IS NULL AND addressSlug='shipping'
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_customers WHERE memberID=1
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=8
[47] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Tax mode: exc
[4] SELECT * FROM perch2_shop_cart_items WHERE cartID=8 ORDER BY itemID ASC
[1] SELECT * FROM perch2_shop_products WHERE productID=17 AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
[0] SELECT r.rateValue FROM perch2_shop_tax_group_rates gr, perch2_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
[1] SELECT * FROM perch2_shop_products WHERE productID=13 AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
[0] SELECT r.rateValue FROM perch2_shop_tax_group_rates gr, perch2_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
[1] SELECT * FROM perch2_shop_products WHERE productID=15 AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
[0] SELECT r.rateValue FROM perch2_shop_tax_group_rates gr, perch2_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
[1] SELECT * FROM perch2_shop_products WHERE productID=6 AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
[0] SELECT r.rateValue FROM perch2_shop_tax_group_rates gr, perch2_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=8
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='1' AND orderID IS NULL AND addressSlug='shipping'
[1] SELECT z.* FROM perch2_shop_shipping_zones z LEFT JOIN perch2_shop_shipping_zone_countries c ON z.zoneID=c.zoneID WHERE z.zoneActive=1 AND z.zoneDeleted IS NULL AND (c.countryID=236 OR zoneIsDefault=1) ORDER BY zoneIsDefault ASC LIMIT 1
[1] SELECT * FROM perch2_shop_shippings WHERE shippingDeleted IS NULL
Rejecting shipping method ‘Standard Delivery’ because: no price available for chosen shipping zone
[nil] SELECT * FROM perch2_shop_promotions WHERE promoFrom<='2016-05-20 16:23:00' AND promoTo>'2016-05-20 16:23:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
[1] SELECT * FROM perch2_shop_cart WHERE cartID=8
INSERT INTO perch2_shop_orders(orderStatus,orderGateway,orderTotal,currencyID,orderItemsSubtotal,orderItemsTax,orderItemsTotal,orderShippingSubtotal,orderShippingDiscounts,orderShippingTax,orderShippingTaxDiscounts,orderShippingTotal,orderDiscountsTotal,orderTaxDiscountsTotal,orderSubtotal,orderTaxTotal,orderItemsRefunded,orderTaxRefunded,orderShippingRefunded,orderTotalRefunded,orderTaxID,orderShippingWeight,orderCreated,orderPricing,orderDynamicFields,customerID,shippingID,orderShippingTaxRate,orderBillingAddress,orderShippingAddress) VALUES('created','paypal-express','20.50','47','20.50','0.00',20.5,NULL,'0.00',NULL,'0.00',NULL,'0.00','0.00',20.5,'0.00',0,0,0,0,NULL,'0.00','2016-05-20 16:23:48','standard','[]','1',NULL,NULL,'1','2')
Invalid query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'orderShippingSubtotal' cannot be null
[1] SELECT * FROM perch2_shop_order_statuses WHERE statusKey='created' AND statusActive=1 AND statusDeleted IS NULL
[nil] SELECT * FROM perch2_shop_emails WHERE emailStatus=1 AND emailActive=1
Array
(
[type] => 8
[message] => Undefined index: shipping_tax_rate
[file] => /Users/alexbennett/Desktop/Job Folder/Cooks Lane Herbs/New Shop Site/admin/addons/apps/perch_shop/lib/PerchShop_Orders.class.php
[line] => 69
)
Should I be adding a shipping function before calling checkout to add a value here? Sorry if this is a stupid question. I've set-up two shipping methods, one standard and a free one for over a certain amount.
Thanks, Alex
Is one of the shipping rates applied to the cart?
I realised I'd not clicked available - UK on my two shipping methods so that probably didn't help.
I'd not applied shipping rates to the cart page, but now I've added the shipping method form to the checkout page, so now it's like this:
So now I can apply a shipping rate to my cart and this shows up in the debug output, but the perch_shop_checkout code won't output anything, can you see what I've done wrong here? Here's the debug out put for this page now:
Thanks, Alex
Does your call to
perch_shop_checkout()
appear before any HTML is output to the page?No - why should it? Should it be the only thing on the page with the runtime include?
If
perch_shop_checkout()
is to be able to redirect the user to a payment gateway, it needs to be placed before you've started sending the page response body. You can't send headers once the body has started.Woo hoo - it's working! Thank you so much for all your pointers. It's all starting to make sense now...
Just in case anyone else reads this, my very crude checkout page now looks like this:
I had a slight glitch, which was because I had test mode set to true on my config/shop.php for PayPal express, even though we hadn't entered any API details for that yet. Now it works I just need to make everything look prettier etc.
Thanks again for your help Drew - support as ever on here is amazing.
Regards, Alex