Search code examples
phppaypalpaypal-sandboxpaypal-rest-sdk

Send user to PayPal Guest Checkout


I would like to use PayPal to allow my clients pay with credit or debit card, I already allow payments with PayPal,I know under the button of the login PayPal form, its a button who says "Pay with credit or debit card" but I would like send the user directly from the script to PayPal Guest Checkout.

I use PayPal SDK and this my code:

if($Payment_Type == 0)
{

if(!isset($Payment_Type))
{
    die();
}

$product = 'Reservation';
$price = $Total;
$shipping = 0.00;

$total = $price + $shipping;

$payer = new Payer();
$payer->setPaymentMethod('paypal');

$item = new Item();
$item->setName($product)
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setPrice($price);

$itemList = new ItemList();
$itemList->setItems([$item]);

$details = new Details();
$details->setShipping($shipping)
    ->setSubtotal($price);

$amount = new Amount();
$amount->setCurrency('USD')
    ->setTotal($total)
    ->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
            ->setItemList($itemList)
            ->setDescription('Service My Transfer In Cabo')
            ->setInvoiceNumber(uniqid());

$redirectUrls = new RedirectUrls();     
$redirectUrls->setReturnUrl(SITE_URL . '/pay.php?success=true)
    ->setCancelUrl(SITE_URL . '/pay.php?success=false);

$payment = new Payment();   
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions([$transaction]);

try {   $payment->create($paypal); }   
catch(Exception $e){ die($e); }

$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");
}
elseif($Payment_Type == 2)
{ 

I need this place

Instead this one


Solution

  • Unfortunately, guest checkout is not yet supported in the REST API. You'll need to use Classic API Express Checkout if you'd like to force guest checkout.

    You can use our PayPal PHP class library to get the classic calls setup quickly and easily. Then you'll just need to setup the following parameters in your SetExpressCheckout request:

    • SOLUTIONTYPE=Sole
    • LANDINGPAGE=Billing
    • USERSELECTEDFUNDINGSOURCE=CreditCard