【问题标题】:Payum Stripe data flow with Symfony使用 Symfony 的 Payum Stripe 数据流
【发布时间】:2016-09-20 23:20:59
【问题描述】:

我正在尝试创建一个结帐功能,允许用户创建付费帐户(如果您愿意,可以使用高级帐户)。用户将创建一个帐户(标记为未付款),用户将付款,然后在成功付款后,该帐户被标记为已付款。我可以创建一个帐户,我可以进行收费。我的问题是将这两件事联系在一起。我不确定如何从成功收费中引用创建的帐户。这是我目前所拥有的。

Payment.php

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\ArrayObject;

/**
 * @ORM\Table
 * @ORM\Entity
 */
class Payment extends ArrayObject
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     *
     * @var integer $id
     */
    protected $id;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
}

创建配置文件控制器.php 创建动作

public function createASquareAction(Request $request, $coupon)
{
    $newUser = new User();
    $registrationForm = $this->getRegistrationForm($newUser);

    $registrationForm->handleRequest($request);

    if ($registrationForm->isSubmitted() && $registrationForm->isValid()) {
        $newSquare = new Square();
        $newSquare->setProduct($registrationForm->get('product')->getData());
        $newUser->addSquare($newSquare);

        $cost = $this->getTotal($newSquare->getProduct(), $registrationForm->get('coupon')->getData());
        $noPayment = $this->isAdmin() || $cost == 0;

        $em = $this->getDoctrine()->getManager();
        $em->persist($newUser);
        $em->flush();

        if ($noPayment) {
            $newSquare->setVerified(true);
            $em->persist($newSquare);
            $em->flush();

            return $this->redirectToRoute('edit', array(
                'id' => $newSquare->getMsid()
            ));
        } else {
            $gatewayName = 'stripe_checkout_test';
            $storage = $this->get('payum')->getStorage('AppBundle\Entity\Payment');
            $payment = $storage->create();
            $payment["amount"] = $cost;
            $payment["currency"] = 'USD';
            $payment["description"] = "Memorysquare";
            $storage->update($payment);

            $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
                $gatewayName,
                $payment,
                'test_payment_done' // the route to redirect after capture;
            );
            return $this->redirect($captureToken->getTargetUrl());
        }

    }

    return $this->render('create-a-square/create-a-square.html.twig', [
        'registrationForm' => $registrationForm->createView(),
        'coupon' => $coupon,
    ]);
}

付款完成操作

public function testPaymentDoneAction(Request $request)
{
    $token = $this->get('payum')->getHttpRequestVerifier()->verify($request);

    $identity = $token->getDetails();
    $model = $this->get('payum')->getStorage($identity->getClass())->find($identity);

    $gateway = $this->get('payum')->getGateway($token->getGatewayName());

    // or Payum can fetch the model for you while executing a request (Preferred).
    $gateway->execute($status = new GetHumanStatus($token));
    $details = $status->getFirstModel();

    return new JsonResponse(array(
        'status' => $status->getValue(),
        'details' => iterator_to_array($details),
    ));
}

如果能帮助我走上正轨,我们将不胜感激。

【问题讨论】:

    标签: symfony orm doctrine stripe-payments payum


    【解决方案1】:

    对此的答案是将我的订单实体(或您想要的任何实体)添加到支付(或 PaymentDetails)实体中(注意级联持续存在):

    Payment.php

    // ... all previous code ... //
    
    /**
     * @ORM\OneToOne(targetEntity="Order", cascade={"persist"})
     * @ORM\JoinColumn(name="orderid", referencedColumnName="orderid")
     */
    private $order;
    
    /**
     * Set order
     *
     * @param \AppBundle\Entity\Order $order
     *
     * @return Payment
     */
    public function setOrder(\AppBundle\Entity\Order $order = null)
    {
        $this->order = $order;
    
        return $this;
    }
    
    /**
     * Get order
     *
     * @return \AppBundle\Entity\Order
     */
    public function getOrder()
    {
        return $this->order;
    }
    

    然后在付款准备中,我将新订单添加到$payment对象中

    public function createASquareAction(Request $request, $coupon)
    {
        // ... previous code ... //
    
        $newOrder = new Order();
        // do some setting on my order 
        $payment->setOrder($newOrder);
        $storage->update($payment);
    
        // ... rest of code ... //
    }
    

    也许这会对将来的某人有所帮助。我还创建了一个事件订阅者在更新时检查订单,如果条带支付成功,则标记为已付款。

    【讨论】:

      猜你喜欢
      • 2017-01-02
      • 2016-04-26
      • 2016-05-03
      • 2017-10-03
      • 2015-05-21
      • 1970-01-01
      • 2017-10-29
      • 2015-04-10
      • 2014-07-20
      相关资源
      最近更新 更多