gpt4 book ai didi

symfony - JMSPaymentPaypalBundle 空白订单摘要

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:18 24 4
gpt4 key购买 nike

您好,我想知道如何使用 JMSPaymentPaypalBundle 在 paypal 中显示订单摘要?!

我将不胜感激 ..

这是我的 paypalController 代码,以备不时之需

<?php
namespace Splurgin\EventsBundle\Controller;

use JMS\DiExtraBundle\Annotation as DI;
use JMS\Payment\CoreBundle\Entity\Payment;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;


class PaymentController
{
/** @DI\Inject */
private $request;

/** @DI\Inject */
private $router;

/** @DI\Inject("doctrine.orm.entity_manager") */
private $em;

/** @DI\Inject("payment.plugin_controller") */
private $ppc;
/**
* @DI\Inject("service_container")
*
*/
private $container;
/**
* @Template
*/
public function detailsAction($package)
{
// note this ticket at this point in inactive ...
$order = $this->container->get('ticket')->generateTicket($package);
$order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order);
$packageId = $order->getPackageId();
$package = $this->em->getRepository('SplurginEventsBundle:SplurginEventPackages')->find($package);
$price = $package->getPrice();
var_dump($price);
if($price == null){
throw new \RuntimeException('Package was not found: '.$result->getReasonCode());
}

$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $price,
'currency' => 'USD',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->router->generate('payment_complete', array(
'order' => $order->getId(),
), true),
'cancel_url' => $this->router->generate('payment_cancel', array(
'order' => $order->getId(),
), true)
),
),
));

if ('POST' === $this->request->getMethod()) {
$form->bindRequest($this->request);

if ($form->isValid()) {
$this->ppc->createPaymentInstruction($instruction = $form->getData());

$order->setPaymentInstruction($instruction);
$this->em->persist($order);
$this->em->flush($order);

return new RedirectResponse($this->router->generate('payment_complete', array(
'order' => $order->getId(),
)));
}
}
return array(
'form' => $form->createView(),
'order'=>$order->getId(),
);
}


/** @DI\LookupMethod("form.factory") */
protected function getFormFactory() { }



/**
*/
public function completeAction($order)
{
$order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order);

$instruction = $order->getPaymentInstruction();
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}

$result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();

if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();

if ($action instanceof VisitUrl) {
return new RedirectResponse($action->getUrl());
}

throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}

}

public function cancelAction($order)
{
die('cancel the payment');
}

}

最佳答案

我真的不知道为什么这不是文档的一部分,但是这个包能够设置开箱即用的结帐参数......

我是这样做的

$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => $price,
'currency' => 'USD',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->router->generate('payment_complete', array(
'order' => $order->getId(),
), true),
'cancel_url' => $this->router->generate('payment_cancel', array(
'order' => $order->getId(),
), true),
'checkout_params' => array(
'L_PAYMENTREQUEST_0_NAME0' => 'event',
'L_PAYMENTREQUEST_0_DESC0' => 'some event that the user is trying to buy',
'L_PAYMENTREQUEST_0_AMT0'=> 6.00, // if you get 10413 , then visit the api errors documentation , this number should be the total amount (usually the same as the price )
// 'L_PAYMENTREQUEST_0_ITEMCATEGORY0'=> 'Digital',
),
),

),

));

可以找到错误码here

SetExpressCheckout 请求字段 here

我会尽快向文档提供拉取请求 .. :)

关于symfony - JMSPaymentPaypalBundle 空白订单摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17120525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com