Php PayPal:格式错误的_请求,没有其他活动
以下是PHP:Php PayPal:格式错误的_请求,没有其他活动,php,paypal,paypal-rest-sdk,Php,Paypal,Paypal Rest Sdk,以下是PHP: public function processPayment($data) { // Create Payer object $payer = new Payer(); // Payment method is via PayPal. Take the customer to PayPal for processing. $payer->setPaymentMethod("paypal"); // Create billing
public function processPayment($data)
{
// Create Payer object
$payer = new Payer();
// Payment method is via PayPal. Take the customer to PayPal for processing.
$payer->setPaymentMethod("paypal");
// Create billingAddress as Address object and fill with customer's billing address.
$billingAddress = new Address();
$billingAddress->setLine1($data['payment_address_1'])
->setLine2($data['payment_address_2'])
->setCity($data['payment_city'])
->setState(/* TWO-LETTER STATE POSTAL ABBREV */)
->setPostalCode($data['payment_postcode'])
->setCountryCode(/* COUNTRY CODE */);
// Create PayerInfo object, populate with customer's billing
// info (name, billingAddress, phone, email)
$payerInfo = new PayerInfo();
$payerInfo->setFirstName($data['payment_firstname'])
->setLastName($data['payment_lastname'])
->setBillingAddress($billingAddress)
//->setPhone($data['telephone'])
->setEmail($data['email']);
// Assign payerInfo to payer.
$payer->setPayerInfo($payerInfo);
/**
* List of items sold and their details
* Add shipping address
*/
$itemList = new ItemList();
foreach ($data['products'] as $product)
{
if ($product['product_sku']) {
$item = new Item();
$item->setName($product['product_name'])
->setSku($product['product_sku'])
->setQuantity($product['quantity'])
->setPrice(number_format($product['price'], 2 , "." , "," ))
->setTax(number_format($product['tax'] , 2 , "." , "," ))
->setCurrency($data['currency_code']);
$itemList->addItem($item);
}
}
$shippingAddress = new ShippingAddress();
$shippingAddress->setRecipientName($data['shipping_firstname'].' '.$data['shipping_lastname'])
->setLine1($data['shipping_address_1'])
->setLine2($data['shipping_address_2'])
->setCity($data['shipping_city'])
->setState(/* TWO-LETTER STATE POSTAL ABBREV */)
->setPostalCode($data['shipping_postcode'])
->setCountryCode(/* COUNTRY CODE */);
$itemList->setShippingAddress($shippingAddress);
$details = new Details();
$details->setShipping(number_format($totals['shipping'] , 2 , "." , "," ))
->setTax(number_format($totals['tax'] , 2 , "." , "," ))
->setSubtotal(number_format($totals['subTotal'] , 2 , "." , "," ));
$amount = new Amount();
$amount->setCurrency($data['currency_code'])
->setTotal(number_format($data['total'] , 2 , "." , "," ))
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setInvoiceNumber($data['invoice_number'])
->setNotifyUrl(/* NOTIFY URL */);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(/* RETURN URL */)
->setCancelUrl(/* CANCEL URL */);
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->addTransaction($transaction)
->setPayee($this->payee); // payee created and populated in _constructor
echo '<h1>Redirecting. . . .</h1>';
try {
$payment->create($this->apiContext); // apiContext created and populated in _constructor
} catch (Exception $ex) {
echo $this->PayPalError($ex); // Print detailed error messages
}
echo "<pre>$payment</pre>";
return;
}
公共功能处理支付($data)
{
//创建付款人对象
$payer=新的付款人();
//付款方式是通过PayPal。将客户带到PayPal进行处理。
$payer->setPaymentMethod(“paypal”);
//创建billingAddress作为地址对象,并填写客户的帐单地址。
$billingAddress=新地址();
$billingAddress->setLine1($data['payment\u address\u 1']))
->setLine2($data['payment\u address\u 2']))
->setCity($data['payment_city'))
->setState(/*两个字母的州邮政缩写*/)
->setPostalCode($data['payment\u postcode']))
->设置国家代码(/*国家代码*/);
//创建PayerInfo对象,填充客户的账单
//信息(姓名、帐单地址、电话、电子邮件)
$payerInfo=新的payerInfo();
$payerInfo->setFirstName($data['payment\u firstname']))
->setLastName($data['payment\u lastname']))
->挫折地址($billingAddress)
//->设置电话($data['telephone']))
->setEmail($data['email']);
//将payerInfo分配给付款人。
$payer->setPayerInfo($payerInfo);
/**
*已售出物品清单及其详细信息
*添加送货地址
*/
$itemList=新的itemList();
foreach($data['products']作为$product)
{
if($product['product_sku'])){
$item=新项();
$item->setName($product['product\U name']))
->setSku($product['product_sku']))
->设置数量($product['quantity']))
->setPrice(数字格式($product['price'],2,“,”,”))
->setTax(数字格式($product['tax'],2,“.”,“,”))
->设置货币($data['currency_code']);
$itemList->addItem($item);
}
}
$shippingAddress=新的shippingAddress();
$shippingAddress->setRecipientName($data['shipping\u firstname'.'。$data['shipping\u lastname']))
->setLine1($data['shipping_address_1']))
->setLine2($data['shipping_address_2']))
->setCity($data['shipping_city'))
->setState(/*两个字母的州邮政缩写*/)
->setPostalCode($data['shipping\u postcode']))
->设置国家代码(/*国家代码*/);
$itemList->setShippingAddress($shippingAddress);
$details=新的详细信息();
$details->setShipping(数字格式($totals['shipping'],2,“,”,”))
->setTax(数字格式($totals['tax'],2,“,”,”))
->setSubtotal(数字格式($totals['subTotal'],2,“,”,”));
$amount=新金额();
$amount->setCurrency($data['currency\u code']))
->setTotal(数字格式($data['total'],2,“,”,”))
->setDetails($details);
$transaction=新事务();
$transaction->setAmount($amount)
->setItemList($itemList)
->setInvoiceNumber($data['invoice_number']))
->setNotifyUrl(/*通知URL*/);
$redirectUrls=新的重定向URL();
$redirectUrls->setReturnUrl(/*返回URL*/)
->setCancelUrl(/*取消URL*/);
$payment=新付款();
$payment->setIntent(“销售”)
->付款人(付款人)
->setRedirectUrls($redirectUrls)
->addTransaction($transaction)
->setPayee($this->payee);//在_构造函数中创建并填充的收款人
回声“重定向…”;
试一试{
$payment->create($this->apiContext);//在_构造函数中创建并填充apiContext
}捕获(例外$ex){
echo$this->PayPalError($ex);//打印详细的错误消息
}
回显“$payment”;
返回;
}
导致
"transactions": [{
"amount": {
"currency": "USD",
"total": "156.00",
"details": {
"shipping": "23.00",
"tax": "0.00",
"subtotal": "133.00"
}
},
"payee": {
"email": "SANDBOX MERCHANT EMAIL"
},
"item_list": {
"items": [{
"name": "PRODUCT NAME",
"sku": "PRODUCT SKU",
"quantity": 1,
"price": "133.00",
"tax": "0.00",
"currency": "USD"
}],
"shipping_address": {
"recipient_name": "Sandbox Buyer",
"line1": "SHIPPING ADDRESS LINE 1",
"line2": "",
"city": "SHIPPING CITY",
"state": "ST",
"postal_code": "ZIP",
"country_code": "US"
}
},
"invoice_number": "25",
"notify_url": "NOTIFY URL"
}]
重定向。
格式错误的_请求-传入的JSON请求未映射到API请求
{"response":{"name":"PAYEE_ACCOUNT_INVALID","message":"Payee account is invalid.","information_link":"https://developer.paypal.com/docs/api/#PAYEE_ACCOUNT_INVALID","debug_id":"feefw4543a1a5","httpStatusCode":400},"httpStatusCode":400}
{
“意图”:“出售”,
“付款人”:{
“付款方式”:“贝宝”,
“付款人信息”:{
“名字”:“沙箱”,
“姓氏”:“买方”,
“账单地址”:{
“第1行”:“账单地址第1行”,
“第2行”:“,
“城市”:“城市”,
“州”:“圣”,
“邮政编码”:“邮政编码”,
“国家/地区代码”:“美国”
},
“电子邮件”:“沙箱买家电子邮件”
}
},
“重定向URL”:{
“返回url”:“返回url”,
“取消url”:“取消url”
},
“交易”:[
{
“金额”:{
“货币”:“美元”,
“总计”:“156.00”,
“详情”:{
“装运”:“23.00”,
“税”:“0.00”,
“小计”:“133.00”
}
},
“项目清单”:{
“项目”:[
{
“名称”:“产品名称”,
“sku”:“产品sku”,
“数量”:1,
“价格”:“133.00”,
“税”:“0.00”,
“货币”:“美元”
}
],
“发货地址”:{
“收件人姓名”:“沙箱买家”,
“第1行”:“发货地址第1行”,
“第2行”:“,
“城市”:“航运城市”,
“州”:“圣”,
“邮政编码”:“邮政编码”,
“国家/地区代码”:“美国”
}
},
“发票编号”:25,
“通知url”:“通知url”
}
],
“收款人”:{
“电子邮件”:“沙箱商户电子邮件”,
“商户id”:“沙箱商户id”
}
}
我得到了格式错误的_请求和数据转储,没有其他活动。用户应该被带到PayPal(本例中为沙箱)进行支付处理(然后返回调用站点。我正在使用PayPal PHP SDK(REST)。我该怎么办?我可以看到JSON存在一些可能导致潜在错误的问题。一个是导致格式错误的\u请求错误,另一个是
{"response":{"name":"PAYEE_ACCOUNT_INVALID","message":"Payee account is invalid.","information_link":"https://developer.paypal.com/docs/api/#PAYEE_ACCOUNT_INVALID","debug_id":"feefw4543a1a5","httpStatusCode":400},"httpStatusCode":400}