Forum
PayPal Express Integration Shop
Having trouble with PayPal integration.
Template is as follows:
<?php
if (perch_member_logged_in()) {
// your 'success' return URL
$return_url = '/shop/success';
$cancel_url = '/shop/failure';
PerchUtil::hold_redirects();
perch_shop_checkout('paypal-express', [
'return_url' => $return_url,
'cancel_url' => $cancel_url,
]);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title><?php perch_pages_title(); ?></title>
<?php perch_page_attributes(); ?>
</head>
<body>
<?php
if (perch_member_logged_in()) {
echo 'Logged in';
}
perch_shop_complete_payment('paypal-express');
if (perch_shop_order_successful()) {
echo '<h1>Thank you for your order!</h1>';
}else{
echo '<h1>Sorry!</h1>';
}
?>
</body>
</html>
On load the page refreshes. Then display the 'Sorry!' message. An order confirmation email is generated, however no order is created in admin area and the $return_url is not displayed.
At no point are we passed to PayPal to log in or complete payment.
Paypal express settings are correct (sandbox credentials removed):
'paypal-express' => [
'enabled' => true,
'test_mode' => true,
'live' => [
'username' => 'paypal_api_username',
'password' => 'paypal_api_password',
'signature' => 'paypal_api_signature',
],
'test' => [
'username' => 'sandbox username',
'password' => 'sandbox password',
'signature' => 'sandbox signature',
],
],
Can anyone help here?
Hello Tony,
I think your return and cancel URLs need to be full URLs. e.g.
https://example.com/shop/success
Thank you Hussein, That fixed it.
I also changed the email notification to fire on 'Paid' rather than created and that fixed the order confirmation issue too.