Example #1
0
 /**
  * Creates/sends request to gateway.
  */
 public function pay()
 {
     $this->check();
     $payment = $this->client->createPayment();
     $payment->setReturnUrl($this->link('//response!'));
     $this->onInit($this, $payment);
     if ($payment->getOriginalPayId()) {
         $response = NULL;
         try {
             if ($this->client->isRecurrentPaymentSupported()) {
                 $response = $this->client->paymentRecurrent($payment);
             } else {
                 $initResponse = $this->client->paymentOneclickInit($payment);
                 $response = $this->client->paymentOneclickStart($initResponse->getPayId());
             }
         } catch (Csob\Exception $e) {
             if ($response === NULL && $e instanceof Csob\ExceptionWithResponse) {
                 $response = $e->getResponse();
             }
             if ($response !== NULL && $response->getPayId()) {
                 $this->onCreated($this, $response);
             }
             $this->onError($this, $e, $response);
             return;
         }
         $this->onCreated($this, $response);
         $this->onResponse($this, $response);
     } else {
         $response = NULL;
         try {
             $response = $this->client->paymentInit($payment);
         } catch (Csob\Exception $e) {
             if ($response === NULL && $e instanceof Csob\ExceptionWithResponse) {
                 $response = $e->getResponse();
             }
             if ($response !== NULL && $response->getPayId()) {
                 $this->onCreated($this, $response);
             }
             $this->onError($this, $e, $response);
             return;
         }
         $this->onCreated($this, $response);
         $redirect = $this->client->paymentProcess($response->getPayId());
         $this->onProcess($this, $redirect);
     }
 }