Markette\Gopay\Service\PaymentService::pay PHP Method

pay() public method

Executes payment via redirecting to GoPay payment gate
public pay ( Markette\Gopay\Entity\Payment $payment, string $channel, callable $callback ) : Nette\Application\Responses\RedirectResponse
$payment Markette\Gopay\Entity\Payment
$channel string
$callback callable
return Nette\Application\Responses\RedirectResponse
    public function pay(Payment $payment, $channel, $callback)
    {
        $paymentSessionId = $this->buildPayment($payment, $channel);
        $url = GopayConfig::fullIntegrationURL() . "?sessionInfo.targetGoId=" . $this->gopay->config->getGopayId() . "&sessionInfo.paymentSessionId=" . $paymentSessionId . "&sessionInfo.encryptedSignature=" . $this->createSignature($paymentSessionId);
        call_user_func_array($callback, [$paymentSessionId]);
        return new RedirectResponse($url);
    }

Usage Example

Example #1
0
 /**
  * Creates and redirect payment request to GoPay
  *
  * @param int $id
  * @param string $channel
  */
 public function actionPay($id, $channel)
 {
     // setup success and failure callbacks
     $this->paymentService->setSuccessUrl($this->link('//success', ['orderId' => $id]));
     $this->paymentService->setFailureUrl($this->link('//failure', ['orderId' => $id]));
     // your custom communication with model
     $order = $this->model->findOrderById($id);
     // prepare data about customer)
     $customer = ['firstName' => $order->name, 'email' => $order->email];
     // creation of payment
     $payment = $this->paymentService->createPayment(['sum' => $order->getPrice(), 'variable' => $order->varSymbol, 'specific' => $order->specSymbol, 'productName' => $order->product, 'customer' => $customer]);
     // to be able to connect our internal Order with Gopay Payment,
     // we have to store its generated ID (which will be created during
     // 'pay' method call - this callback will be provided in next step
     $storePaymentId = function ($paymentId) use($order) {
         $order->storePaymentId($paymentId);
     };
     // here we communicate with Gopay Web Service (via soap)
     $toPayResponse = $this->paymentService->pay($payment, $channel, $storePaymentId);
     // redirect to Gopay Payment Gate
     $this->sendResponse($toPayResponse);
 }