15 paypal
我在尝试创建付款时遇到错误,我得到的错误是:
-url:" https://api.sandbox.paypal.com/v1/payments/payment "-data:"{"name":"MALFORMED_REQUEST","message":"传入的JSON请求未映射到API请求" ,"information_link":" https://developer.paypal.com/webapps/developer/doc▶ "#message:"访问https://api.sandbox.paypal.com/v1/payments/时获得Http响应代码400 付款."
我试图通过将其添加到列表然后将其添加到事务中来创建这样的付款
// type of paypal payment (redirect)
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
// iniate the item
$item = Paypal::item();
// iniate the ammount
$amount = PayPal:: Amount();
switch($type)
{
case 'job':
$item
->setName('Job advertisement on '. Config('app.name'))
->setDescription('Job advertisement on '. Config('app.name'))
->setCurrency('GBP')
->setQuantity(1)
->setTax(0.2)
->setPrice(Config('settings.job_price'));
$details = Paypal::Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
$amount->setCurrency('GBP')
->setDetails($details)
->setTotal(Config('settings.job_price'));
break;
case 'course':
$item
->setName('Course advertisement on '. Config('app.name'))
->setDescription('Course advertisement on '. Config('app.name'))
->setCurrency('GBP')
->setQuantity(1)
->setTax(0.2)
->setPrice(Config('settings.course_price'));
$details = Paypal::Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.50);
$amount->setCurrency('GBP')
->setDetails($details)
->setTotal(Config('settings.course_price'));
break;
}
// geerate the item list
$itemList = Paypal::itemList();
$itemList->setItems($item);
// now create the transactions
$transaction = Paypal::transaction();
$transaction
->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// setup the redirect uri's'
$redirectUrls = PayPal:: RedirectUrls();
$redirectUrls
->setReturnUrl(route('payment.complete'))
->setCancelUrl(route('payment.cancelled'));
// set up the person's information
$payment = PayPal::Payment();
$payment
->setIntent('authorize')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
print_r($payment);
try{
dd($payment->create($this->_apiContext));
$response = $payment->create($this->_apiContext);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
dd($ex);
} catch (Exception $ex) {
die($ex);
}
$redirectUrl = $response->links[1]->href;
// redirect to paypal for payment
return Redirect::to( $redirectUrl );
Run Code Online (Sandbox Code Playgroud)
发送的数据如下:
PayPal\Api\Payment Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[intent] => authorize [payer] => PayPal\Api\Payer Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[payment_method] => paypal
)
)
[redirect_urls] => PayPal\Api\RedirectUrls Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[return_url] => http://localhost/payment/payment-done
[cancel_url] => http://localhost/payment/payment-cancelled
)
)
[transactions] => Array (
[0] => PayPal\Api\Transaction Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[amount] => PayPal\Api\Amount Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[currency] => GBP
[details] => PayPal\Api\Details Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[shipping] => 1.20
[tax] => 1.30
[subtotal] => 17.50
)
)
[total] => 125
)
)
[item_list] => PayPal\Api\ItemList Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[items] => PayPal\Api\Item Object (
[_propMap:PayPal\Common\PayPalModel:private] => Array (
[name] => Job advertisement on Laravel
[description] => Job advertisement on Laravel
[currency] => GBP
[quantity] => 1
[tax] => 0.20
[price] => 125
)
)
)
)
[description] => Payment description
[invoice_number] => 599cd8d03b626
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
这已经足够了
$payment->setIntent('authorize')
Run Code Online (Sandbox Code Playgroud)
代替
$payment->setIntent('sale')
Run Code Online (Sandbox Code Playgroud)
并消除执行
$execution = new PaymentExecution(); $result = $payment->execute($execution, $apiContext);
Run Code Online (Sandbox Code Playgroud)
然后
$payment->create
Run Code Online (Sandbox Code Playgroud)
我使用了"href"
$payment->links
Run Code Online (Sandbox Code Playgroud)
做重定向.一切都很顺利
归档时间: |
|
查看次数: |
928 次 |
最近记录: |