我创建了一个PayPal沙盒交易,就像您在下面看到的代码一样。它工作正常。但现在我想禁用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) { }
答案 0 :(得分:3)
这是一个老问题,但我认为它仍然相关:
您必须将InputField包装在配置文件中(例如WebProfile)。
$inputfields = new \PayPal\Api\InputFields();
$inputfields
->getNoShipping(1)
->setAddressOverride(0);;
$webProfile = new \PayPal\Api\WebProfile();
$webProfile
->setName('testname' . uniqid())
->setInputFields($inputFields)
->setTemporary(true);
然后创建个人资料并将其添加到付款。
$webProfileId = $webProfile->create($apiContext)->getId();
$payment = new Payment();
$payment->setExperienceProfileId($webProfileId);