Disable shipping address option in PayPal Express Checkout

后端 未结 7 1758
温柔的废话
温柔的废话 2020-12-09 16:06

Working with the PayPal API and using the Name-Value Pair Interface PHP source codes from SDKs and Downloads: Simplify Integrations with Downloads and SDKs.

My quest

7条回答
  •  臣服心动
    2020-12-09 16:19

    The current right answer is depracated. To fix the issue in new API we should create Payment web experience profile resource with needed parameters and attach it to request Payment .

    Example in PHP:

    /** Note: Define some variables yourself. */
    
    $inputFields = new InputFields();
    $inputFields->setAllowNote(true)
        ->setNoShipping(1) // Important step
        ->setAddressOverride(0);
    
    $webProfile = new WebProfile();
    $webProfile->setName(uniqid())
        ->setInputFields($inputFields)
        ->setTemporary(true);
    
    $createProfile = $webProfile->create($apiContext);
    
    $payment = new Payment();
    
    $payment->setPayer($payer);
    $payment->setIntent($intent);
    $payment->setRedirectUrls($redirectUrls)
    $payment->setTransactions(array($transaction));
    $payment->setExperienceProfileId($createProfile->getId()); // Important step.
    
    $payment->create($apiContext);
    
    if ($payment->getState() === "created") {
        $approvalLink = $payment->getApprovalLink()
    
        header("Location: $approvalLink"); // Redirects user to PayPal page.
    }
    

    Note: You can find all above used classes by link: https://github.com/paypal/PayPal-PHP-SDK/tree/master/lib/PayPal/Api

提交回复
热议问题