Я использую Symfony4 и у меня ошибка в функции doneAction
$payment->execute($status = new GetHumanStatus($token));
<--- здесь </p>
Ошибка:
"Запрос GetHumanStatus {model: ArrayObject} не поддерживается. Убедитесь, что шлюз поддерживает запросы, и существует действие, которое поддерживает этот запрос (метод возвращает true). Может быть ошибка, поэтому ищите связанную проблему по вопросу трекера. " Мой контроллер:
class PaymentController extends FOSRestController
{
/**
* @return Payum
*/
protected function getPayum()
{
return $this->get('payum');
}
/**
* @param Order $order
* @param CartService $cartService
* @return mixed
* @Rest\Post("/prepare-action/{order}", name="prepare-action")
*/
public function prepareAction(Order $order, CartService $cartService): View
{
if (true === $order->getIsPaid()) {
throw new BadRequestHttpException('Order already payed.');
}
/* @var $user User */
$user = $this->getUser();
$gatewayName = 'paypal_rest';
$storage = $this->getPayum()
->getStorage(Payment::class);
/* @var $payment Payment */
$payment = $storage->create();
$total = $cartService->getTotalSum();
$payment->setUserOrder($order);
$payment->setCurrencyCode('PLN');
$payment->setTotalAmount($total);
$payment->setDescription('Shop payment.');
$payment->setClientId(md5((string) $user->getId()));
$payment->setClientEmail($user->getEmail());
$details = [
'invoiceDisabled' => true, // use this only when you want to hide invoice checkbox on payment form
];
if (null !== $userInfo = $user->getUsername()) {
$details = [
'firstName' => $user->getUsername(),
];
}
$payment->setDetails($details);
$storage->update($payment);
$captureToken = $this->getPayum()
->getTokenFactory()
->createCaptureToken(
$gatewayName,
$payment,
'payum_capture_do');
return View::create($captureToken->getTargetUrl(), Response::HTTP_OK);
}
/**
* @param Request $request
* @return mixed
* @throws \Exception
* @Rest\Get("done", name="payum_capture_do")
*/
public function doneAction(Request $request)
{
$token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
$payment = $this->getPayum()->getGateway($token->getGatewayName());
$payment->execute($status = new GetHumanStatus($token));
$paymentId = $status->getToken()->getDetails()->getId();
$paymentClass = $status->getToken()->getDetails()->getClass();
$storage = $this->getPayum()->getStorage($paymentClass);
/* @var $payment Payment */
$payment = $storage->find($paymentId);
if (!$payment) {
throw new NotFoundHttpException('Payment not found');
}
$order = $payment->getUserOrder();
if ($status->isCaptured()) {
// payment succeeded
$order->setIsPaid(true);
$order->setStatus(Order::STATUS_ACCEPTED);
} elseif ($status->isPending()) {
// payment pending
} else {
// payment failed
$order->setIsPaid(false);
$order->setStatus(Order::STATUS_CANCELLED);
}
$em = $this->getDoctrine()->getManager();
$em->persist($order);
$em->flush();
return View::create($payment, Response::HTTP_OK);
}
}
Мой Payum.yaml
payum:
security:
token_storage:
App\Entity\PaymentToken:
filesystem:
storage_dir: "%kernel.root_dir%/Resources/payments"
id_property: hash
storages:
App\Entity\Payment:
filesystem:
storage_dir: "%kernel.root_dir%/Resources/payments"
id_property: id
gateways:
offline:
factory: offline
paypal_rest:
factory: "paypal_rest"
client_id: "someID"
client_secret: "someSecret"
config_path: '%kernel.root_dir%/sdk_config.ini'