I'm trying to use JMSPaymentCoreBundle
with JMSPaymentPaypalBundle
and I can't find a clear example anywhere on how to do it.
I've done all steps specified in the documentation and I'm not able to get it working. Can anybody help me please?
I'm trying to use JMSPaymentCoreBundle
with JMSPaymentPaypalBundle
and I can't find a clear example anywhere on how to do it.
I've done all steps specified in the documentation and I'm not able to get it working. Can anybody help me please?
Payum 捆绑包支持通过桥接的 jms 支付。这些链接描述了如何开始。
使用捆绑包给您带来了几个优势:
PS 这不是完整的功能列表。
创建支付指令的默认方式是通过 jms_choose_payment_method 表单:
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => 12.99,
'currency' => 'EUR',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true),
'cancel_url' => $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true)
),
),
));
您也可以手动创建付款指令:
use JMS\Payment\CoreBundle\Entity\ExtendedData;
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 JMS\Payment\CoreBundle\Entity\PaymentInstruction;
$extendedData = new ExtendedData();
$extendedData->set('return_url', $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true));
$extendedData->set('cancel_url', $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true));
$instruction = new PaymentInstruction((float)$order->getCharge() > 0 ? $order->getCharge() : $order->getAmount(), 'EUR', 'paypal_express_checkout', $extendedData);
$this->get('payment.plugin_controller')->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($order);
$em->flush();
我的 payment_complete 路线如下所示:
public function completeAction(Booking $order)
{
$instruction = $order->getPaymentInstruction();
if (($instruction->getAmount() - $instruction->getDepositedAmount()) > 0) {
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->get('payment.plugin_controller')->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}
$result = $this->get('payment.plugin_controller')->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());
}
}
$order->setTransactionAmount((float)$order->getAmount());
$creditPurchased = (float)$order->getCharge() > (float)$order->getAmount() ? (float)$order->getCharge() - (float)$order->getAmount() : 0;
$em->persist($order);
$em->flush();
我已经通过http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage运行它