我使用基于payum网站文档的paypal快速结账,我在结账详情方面遇到问题这是我的PaymentController的代码:
class PaymentController extends Controller{
public function processRequestAction (Request $request) {
$options = $this->get('doctrine.orm.entity_manager')
->getRepository('AdminBundle:Options')->getOption('admin_options');
$credits = $request->request->get('wizardPayment')['Credits'];
$total = $credits*$options['credits-rate'];
$user = $this->get('security.token_storage')->getToken()->getUser();
$paymentName = 'paypal_express_checkout';
$storage = $this->get('payum')->getStorage('Magnetomedia\AdminBundle\Entity\PaymentDetails');
$order = $storage->create();
$order->setCurrencyCode($options['currency']['code']);
$order->setTotalAmount($total);
$order->setDescription('Buy credits from verifyme.email');
$order->setClientId($user->getId());
$order->setClientEmail($user->getEmail());
$order->setDetails(array(
"SOLUTIONTYPE" => 'Sole',
"LANDINGPAGE" => 'Billing'
));
$storage->update($order);
$order->setNumber($order->getId().rand(1,10000));
$storage->update($order);
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
$paymentName,
$order,
'payment_response' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}
public function paymentResponseAction(Request $request){
$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
$entityManager = $this->get('doctrine')->getManager();
$options = $entityManager->getRepository('AdminBundle:Options')->getOption('admin_options');
try {
$payment->execute(new Sync($token));
} catch (RequestNotSupportedException $e) {}
$payment->execute($status = new GetHumanStatus($token));
$refundToken = null;
if ($status->isCaptured() || $status->isAuthorized()) {
$refundToken = array(
'status' => $status->getValue(),
'order' => array(
'client' => array(
'id' => $status->getFirstModel()->getClientId(),
'email' => $status->getFirstModel()->getClientEmail(),
),
'number' => $status->getFirstModel()->getNumber(),
'description' => $status->getFirstModel()->getCurrencyCode(),
'total_amount' => $status->getFirstModel()->getTotalAmount(),
'currency_code' => $status->getFirstModel()->getCurrencyCode(),
'details' => $status->getFirstModel()->getDetails(),
),
);
$user = $entityManager->find('AdminBundle:User',$refundToken['order']['client']['id']);
$userOrder = new UserOrder();
$userOrder->setStatus($refundToken['status']);
$userOrder->setUser($user);
$userOrder->setDate(new \DateTime());
$userOrder->setInfo(json_encode($refundToken['order']));
$entityManager->persist($userOrder);
$user->addCredits($refundToken['order']['total_amount']/$options['credits-rate']);
$entityManager->persist($user);
$this->addFlash(
"paymentMessage",
'Payment was successfully accepted, you got '
.$refundToken['order']['total_amount']/$options['credits-rate'].' Credits'
);
$paymentStatus = 'success';
} elseif(!$status->isCaptured()) {
$userOrder = new UserOrder();
$userOrder->setStatus($status->getValue());
$userOrder->setUser(
$entityManager->find('AdminBundle:User',$refundToken['order']['client']['id'])
);
$userOrder->setDate(new \DateTime());
$entityManager->persist($userOrder);
$paymentStatus ='danger';
$this->addFlash("paymentMessage",'We are sorry there was an error during the payment process , please try again later or contact us');
}
$entityManager->flush();
return $this->redirectToRoute('profile_page',array('paymentStatus'=>$paymentStatus));
}
}
我被重定向到Paypal,但即使我指定了数量和描述,paypal也说“当前购买”#39;它会列出描述和价格。当我改变这个:
$order->setDetails(array(
"SOLUTIONTYPE" => 'Sole',
"LANDINGPAGE" => 'Billing'
));
为:
$order->setDetails([
'L_PAYMENTREQUEST_0_AMT0' => 123,
'L_PAYMENTREQUEST_0_NAME0' => 'test',
]);
它会产生异常:
Myapp \ AdminBundle \ Entity \ User的查询缺少标识符ID 在vendor / doctrine / orm / lib / Doctrine / ORM / ORMException.php第294行
堆栈追踪:
at ORMException ::missingIdentifierField ('Myapp\AdminBundle\Entity\User', 'id')
in vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php at line 403
at EntityManager ->find ('AdminBundle:User', null, null, null)
in app/cache/dev/jms_diextra/doctrine/EntityManager_5613ae163997a.php at line 336
at EntityManager ->find ('AdminBundle:User', null)
in src/Myapp/AdminBundle/Controller/PaymentController.php at line 107
at PaymentController ->paymentResponseAction (object(Request))
at call_user_func_array (array(object(PaymentController), 'paymentResponseAction'), array(object(Request)))
in app/bootstrap.php.cache at line 3020
at HttpKernel ->handleRaw (object(Request), '1')
in app/bootstrap.php.cache at line 2982
at HttpKernel ->handle (object(Request), '1', true)
in app/bootstrap.php.cache at line 3131
at ContainerAwareHttpKernel ->handle (object(Request), '1', true)
in app/bootstrap.php.cache at line 2376
at Kernel ->handle (object(Request))
in httpdocs/app_dev.php at line 28
任何想法?