【问题标题】:How to disable PayPal shipping option with PHP如何使用 PHP 禁用 PayPal 运输选项
【发布时间】:2016-07-08 00:22:07
【问题描述】:

我已经创建了一个 PayPal 沙盒交易,就像您在下面的代码中看到的那样。它工作正常。但现在我想禁用贝宝网站上的送货地址对话框。 我发现了这个:

$inputfields = new \PayPal\Api\InputFields();
$inputfields->getNoShipping(1);

但我知道它不起作用。还缺少什么?

$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential( PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET ));

$amount = new Amount();
$amount->setCurrency('EUR'); 
$amount->setTotal($price);             
$amount->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setDescription( ... )
    ->setNotifyUrl(  ... );

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl( ... );
    ->setCancelUrl( ... );      

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

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));

try {   
    $payment->create($apiContext);
} catch (\PayPal\Exception\PayPalConnectionException $e) { }

【问题讨论】:

    标签: php paypal sdk paypal-sandbox


    【解决方案1】:

    这是一个老问题,但我认为它仍然相关:

    您必须将 InputFields 包装在配置文件中(例如 WebProfile)。

    use PayPal\Api\InputFields;
    use PayPal\Api\WebProfile;
    
    $inputFields = new \PayPal\Api\InputFields();
    $inputFields
       ->setAllowNote(true)
       ->setNoShipping(1)
       ->setAddressOverride(0);
    
    $webProfile = new \PayPal\Api\WebProfile();
    $webProfile
       ->setName('testname' . uniqid())
       ->setId("999")
       ->setInputFields($inputFields)
       ->setTemporary(true);
    

    然后创建配置文件并将其添加到付款。

    $webProfileId = $webProfile->create($apiContext)->getId("999");
    
    $payment = new Payment();
    $payment->setExperienceProfileId($webProfileId);
    

    【讨论】:

      猜你喜欢
      • 2013-03-06
      • 1970-01-01
      • 2022-08-15
      • 2017-09-06
      • 2012-06-25
      • 2015-11-29
      • 2013-05-10
      • 2014-12-10
      • 1970-01-01
      相关资源
      最近更新 更多