我创建了一个PayPal沙盒事务,就像你在下面的代码中看到的那样。它工作正常。但是现在我想禁用PayPal站点上的送货地址对话框。我发现这个:
$inputfields = new PayPalApiInputFields();
$inputfields->getNoShipping(1);
但我明白它不起作用。还缺少什么?
$apiContext = new PayPalRestApiContext(
new PayPalAuthOAuthTokenCredential( 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 (PayPalExceptionPayPalConnectionException $e) { }
这是一个老问题,但我认为它仍然相关:
您必须将输入字段包装在配置文件中(例如WebProfile)。
use PayPalApiInputFields;
use PayPalApiWebProfile;
$inputFields = new PayPalApiInputFields();
$inputFields
->setAllowNote(true)
->setNoShipping(1)
->setAddressOverride(0);
$webProfile = new PayPalApiWebProfile();
$webProfile
->setName('testname' . uniqid())
->setId("999")
->setInputFields($inputFields)
->setTemporary(true);
然后创建配置文件并将其添加到付款中。
$webProfileId = $webProfile->create($apiContext)->getId("999");
$payment = new Payment();
$payment->setExperienceProfileId($webProfileId);