Example #1
0
 /**
  * Executes payment via INLINE GoPay payment gate
  *
  * @param Payment $payment
  * @param string $channel
  * @param callable $callback
  * @return RedirectResponse
  * @throws InvalidArgumentException on undefined channel
  * @throws GopayFatalException on maldefined parameters
  * @throws GopayException on failed communication with WS
  */
 public function payInline(Payment $payment, $channel, $callback)
 {
     $paymentSessionId = $this->buildPayment($payment, $channel);
     $response = ["url" => GopayConfig::fullNewIntegrationURL() . '/' . $paymentSessionId, "signature" => $this->createSignature($paymentSessionId)];
     call_user_func_array($callback, [$paymentSessionId]);
     return $response;
 }
Example #2
0
 /**
  * Castecne vraceni platby
  *
  * @param float $paymentSessionId - identifikator platby
  * @param float $amount - castka na vraceni
  * @param String $currency - mena
  * @param String $description - popis vraceni platby
  * @param float $targetGoId - identifikator prijemnce - GoId
  * @param string $secureKey - kryptovaci klic prideleny GoPay
  */
 public function refundPaymentPartially($paymentSessionId, $amount, $currency, $description, $targetGoId, $secureKey)
 {
     try {
         //inicializace WS
         ini_set("soap.wsdl_cache_enabled", "0");
         $go_client = new SoapClient(GopayConfig::ws(), array());
         $sessionEncryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatRefundRequest((double) $targetGoId, (double) $paymentSessionId, $amount, $currency, $description, $secureKey)), $secureKey);
         $refundRequest = array("targetGoId" => (double) $targetGoId, "paymentSessionId" => (double) $paymentSessionId, "amount" => $amount, "currency" => $currency, "description" => $description, "encryptedSignature" => $sessionEncryptedSignature);
         $paymentResult = $go_client->__call("partiallyRefundPayment", array("refundRequest" => $refundRequest));
         if ($paymentResult->result == GopayHelper::CALL_RESULT_FAILED) {
             throw new Exception("payment not refunded [" . $paymentResult->resultDescription . "]");
         } else {
             if ($paymentResult->result == GopayHelper::CALL_RESULT_ACCEPTED) {
                 //vraceni platby bylo zarazeno ke zpracovani
                 throw new Exception(GopayHelper::CALL_RESULT_ACCEPTED);
             }
         }
         return $paymentResult->paymentSessionId;
     } catch (SoapFault $f) {
         /*
          * Chyba v komunikaci s GoPay serverem
          */
         throw new Exception("SOAP error");
     }
 }
Example #3
0
 /**
  * Sestaveni platebniho tlacitka formou odkazu pro jednoduchou integraci
  *
  * @param float $targetGoId - identifikace prijemce - GoId pridelene GoPay
  * @param string $productName - nazev objednavky / zbozi
  * @param int $totalPrice - cena objednavky v halerich
  * @param string $currency - identifikator meny
  * @param string $orderNumber - identifikace objednavky u prijemce
  * @param string $successURL - URL, kam se ma prejit po uspesnem zaplaceni
  * @param string $failedURL - URL, kam se ma prejit po neuspesnem zaplaceni
  * @param array $paymentChannels - pole plat. metod, ktere se zobrazi na brane
  * @param string $secureKey - kryptovaci klic prideleny prijemci, urceny k podepisovani komunikace
  *
  * @param boolean $preAuthorization - jedna-li se o predautorizovanou platbu
  * @param boolean $recurrentPayment - jedna-li se o opakovanou platbu
  * @param date $recurrenceDateTo - do kdy se ma opakovana platba provadet
  * @param string $recurrenceCycle - frekvence opakovresultane platby - mesic/tyden/den
  * @param int $recurrencePeriod - pocet plateb v cyklu $recurrenceCycle - kolikrat v mesici/... se opakovana platba provede
  *
  * Informace o zakaznikovi
  * @param string $firstName   - Jmeno zakaznika
  * @param string $lastName    - Prijmeni
  *
  * Adresa
  * @param string $city        - Mesto
  * @param string $street      - Ulice
  * @param string $postalCode  - PSC
  * @param string $countryCode - Kod zeme. Validni kody jsou uvedeny ve tride CountryCode
  * @param string $email       - Email zakaznika
  * @param string $phoneNumber - Tel. cislo
  *
  * @param string $p1 - $p4 - volitelne parametry, ketre budou po navratu z platebni brany predany e-shopu
  *
  * @param string $lang - jazyk platebni brany
  *
  * @return HTML kod platebniho tlacitka
  */
 public static function createPaymentHref($targetGoId, $productName, $totalPrice, $currency, $orderNumber, $successURL, $failedURL, $preAuthorization, $recurrentPayment, $recurrenceDateTo, $recurrenceCycle, $recurrencePeriod, $paymentChannels, $defaultPaymentChannel, $secureKey, $firstName, $lastName, $city, $street, $postalCode, $countryCode, $email, $phoneNumber, $p1, $p2, $p3, $p4, $lang)
 {
     $paymentChannelsString = !empty($paymentChannels) ? join($paymentChannels, ",") : "";
     $encryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatPaymentCommand((double) $targetGoId, $productName, (int) $totalPrice, $currency, $orderNumber, $failedURL, $successURL, $preAuthorization, $recurrentPayment, $recurrenceDateTo, $recurrenceCycle, $recurrencePeriod, $paymentChannelsString, $secureKey)), $secureKey);
     $params = "";
     $params .= "paymentCommand.targetGoId=" . $targetGoId;
     $params .= "&paymentCommand.productName=" . urlencode($productName);
     $params .= "&paymentCommand.totalPrice=" . $totalPrice;
     $params .= "&paymentCommand.currency=" . $currency;
     $params .= "&paymentCommand.orderNumber=" . urlencode($orderNumber);
     $params .= "&paymentCommand.successURL=" . urlencode($successURL);
     $params .= "&paymentCommand.failedURL=" . urlencode($failedURL);
     $params .= "&paymentCommand.paymentChannels=" . urlencode($paymentChannelsString);
     $params .= "&paymentCommand.defaultPaymentChannel=" . urlencode($defaultPaymentChannel);
     $params .= "&paymentCommand.encryptedSignature=" . urlencode($encryptedSignature);
     $params .= "&paymentCommand.preAuthorization=" . GopayHelper::castBoolean2String($preAuthorization);
     $params .= "&paymentCommand.recurrentPayment=" . GopayHelper::castBoolean2String($recurrentPayment);
     $params .= "&paymentCommand.recurrenceDateTo=" . urlencode($recurrenceDateTo);
     $params .= "&paymentCommand.recurrenceCycle=" . urlencode($recurrenceCycle);
     $params .= "&paymentCommand.recurrencePeriod=" . $recurrencePeriod;
     $params .= "&paymentCommand.customerData.firstName=" . urlencode($firstName);
     $params .= "&paymentCommand.customerData.lastName=" . urlencode($lastName);
     $params .= "&paymentCommand.customerData.city=" . urlencode($city);
     $params .= "&paymentCommand.customerData.street=" . urlencode($street);
     $params .= "&paymentCommand.customerData.postalCode=" . urlencode($postalCode);
     $params .= "&paymentCommand.customerData.countryCode=" . urlencode($countryCode);
     $params .= "&paymentCommand.customerData.email=" . urlencode($email);
     $params .= "&paymentCommand.customerData.phoneNumber=" . urlencode($phoneNumber);
     $params .= "&paymentCommand.p1=" . urlencode($p1);
     $params .= "&paymentCommand.p2=" . urlencode($p2);
     $params .= "&paymentCommand.p3=" . urlencode($p3);
     $params .= "&paymentCommand.p4=" . urlencode($p4);
     $params .= "&paymentCommand.lang=" . $lang;
     $ouput = "";
     $ouput .= "<a target='_blank' href='" . GopayConfig::baseIntegrationURL() . "?" . $params . "'>";
     $ouput .= " Zaplatit ";
     $ouput .= "</a>";
     return $ouput;
 }
Example #4
0
 /**
  * @param bool $testMode
  */
 protected function setTestMode($testMode = TRUE)
 {
     $this->testMode = (bool) $testMode;
     GopayConfig::$version = $this->testMode ? GopayConfig::TEST : GopayConfig::PROD;
 }
Example #5
0
 /**
  * Executes payment via redirecting to GoPay payment gate
  *
  * @param  Payment
  * @param  string|null
  * @param  callback
  * @return RedirectResponse
  * @throws \InvalidArgumentException on undefined channel or provided ReturnedPayment
  * @throws GopayFatalException on maldefined parameters
  * @throws GopayException on failed communication with WS
  */
 public function recurrentPay(Payment $payment, $channel, $callback)
 {
     if ($payment instanceof ReturnedPayment) {
         throw new \InvalidArgumentException("Cannot use instance of 'ReturnedPayment'! This payment has been already used for paying");
     }
     if (!isset($this->channels[$channel]) && $channel !== self::METHOD_USER_SELECT) {
         throw new \InvalidArgumentException("Payment channel '{$channel}' is not supported");
     }
     try {
         $customer = $payment->getCustomer();
         $paymentSessionId = $this->soap->createRecurrentPayment($this->gopayId, $payment->getProductName(), $payment->getSumInCents(), $payment->getCurrency(), $payment->getVariable(), $this->successUrl, $this->failureUrl, $this->recurrenceDateTo, $this->recurrenceCycle, $this->recurrencePeriod, array_keys($this->channels), $channel, $this->gopaySecretKey, $customer->firstName, $customer->lastName, $customer->city, $customer->street, $customer->postalCode, $customer->countryCode, $customer->email, $customer->phoneNumber, NULL, NULL, NULL, NULL, $this->lang);
     } catch (\Exception $e) {
         throw new GopayException($e->getMessage(), 0, $e);
     }
     $url = GopayConfig::fullIntegrationURL() . "?sessionInfo.targetGoId=" . $this->gopayId . "&sessionInfo.paymentSessionId=" . $paymentSessionId . "&sessionInfo.encryptedSignature=" . $this->createSignature($paymentSessionId);
     Nette\Utils\Callback::invokeArgs($callback, array($paymentSessionId));
     return new RedirectResponse($url);
 }
Example #6
0
 /**
  * Executes payment via INLINE GoPay payment gate
  *
  * @param  Payment
  * @param  string|null
  * @param  callback
  * @return RedirectResponse
  * @throws \InvalidArgumentException on undefined channel or provided ReturnedPayment
  * @throws GopayFatalException on maldefined parameters
  * @throws GopayException on failed communication with WS
  */
 public function payInline(Payment $payment, $channel, $callback)
 {
     $paymentSessionId = $this->createPaymentInternal($payment, $channel);
     $response = array("url" => GopayConfig::fullNewIntegrationURL() . '/' . $paymentSessionId, "signature" => $this->createSignature($paymentSessionId));
     Nette\Utils\Callback::invokeArgs($callback, array($paymentSessionId));
     return $response;
 }