/** * Kontrola provedeni platby uzivatele * - verifikace parametru z redirectu * - kontrola provedeni platby * * @param long $paymentSessionId - identifikator platby * @param long $eshopGoId - identifikator uzivatele - GoId * @param string $variableSymbol - identifikator objednavky * @param int $totalPriceInCents - celkova cena objednavky v halerich * @param string $productName - popis objednavky zobrazujici se na platebni brane * @param string $secret - kryptovaci heslo pridelene uzivateli * * @return $result * result["code"] - kod vysledku volani * result["description"] - popis vysledku volani */ public static function isBuyerPaymentDone($paymentSessionId, $buyerGoId, $variableSymbol, $totalPriceInCents, $productName, $secret) { $result = array(); try { //inicializace WS ini_set("soap.wsdl_cache_enabled", "0"); $go_client = new SoapClient(GopayConfig::ws(), array()); //sestaveni dotazu na stav platby $sessionEncryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatPaymentSession((double) $buyerGoId, (double) $paymentSessionId, $secret)), $secret); $payment_session = array("buyerGoId" => (double) $buyerGoId, "paymentSessionId" => (double) $paymentSessionId, "encryptedSignature" => $sessionEncryptedSignature); /* * Kontrola stavu platby na strane GoPay prostrednictvim WS */ $payment_status = $go_client->__call('paymentStatusGW2', array('paymentSessionInfo' => $payment_session)); $result["description"] = $payment_status->resultDescription; $result["code"] = $payment_status->sessionState; /* * Kontrola zaplacenosti objednavky, verifikace parametru objednavky */ if (!GopayHelper::checkBuyerPaymentStatus($payment_status, 'PAYMENT_DONE', (double) $buyerGoId, $variableSymbol, (int) $totalPriceInCents, $productName, $secret)) { /* * Platba neprobehla korektne */ $result["code"] = GopayHelper::FAILED; } } catch (SoapFault $f) { /* * Chyba v komunikaci s GoPay serverem */ $result["code"] = GopayHelper::FAILED; $result["description"] = GopayHelper::FAILED; } return $result; }
$firstName = $customer->firstname; $lastName = $customer->lastname; $city = $address->city; $street = $address->address1; $postalCode = $address->postcode; $email = $customer->email; $phoneNumber = $address->phone; $countryId = $address->id_country; $country = new Country($countryId); $convertedCountryCode = GopayTools::getConvertedCountryCode($country->iso_code); } if (isset($order)) { // vytvoreni platby $paymentSessionId = GopaySoap::createCustomerEshopPayment($goId, $productNameConcat, $amount, $orderId, $successUrl, $failedUrl, $gopaySecret, $paymentChannels, $firstName, $lastName, $city, $street, $postalCode, $convertedCountryCode, $email, $phoneNumber); if ($paymentSessionId > 0) { $encryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatPaymentSession($goId, $paymentSessionId, $gopaySecret)), $gopaySecret); } else { $gpErrors = 'paymentCreationFailed'; } } else { $gpErrors = 'undefinedOrderFaultyState'; } if (empty($gpErrors)) { $redirectUrl = "{$gwUrl}?sessionInfo.paymentSessionId={$paymentSessionId}&sessionInfo.eshopGoId={$goId}&sessionInfo.encryptedSignature={$encryptedSignature}"; if (isset($param)) { $redirectUrl .= "{$param}"; } Tools::redirectLink($redirectUrl); } else { Tools::redirectLink("{$infopageUrl}?gp_errors={$gpErrors}"); }
/** * Vraceni platby * * @param float $paymentSessionId - identifikator platby * @param float $targetGoId - identifikator prijemnce - GoId * @param string $secureKey - kryptovaci klic prideleny GoPay * @return string * @throws \Exception */ public static function refundPayment($paymentSessionId, $targetGoId, $secureKey) { try { //inicializace WS ini_set("soap.wsdl_cache_enabled", "0"); $go_client = GopayConfig::createSoapClient(); $sessionEncryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatPaymentSession((double) $targetGoId, (double) $paymentSessionId, $secureKey)), $secureKey); $paymentSession = array("targetGoId" => (double) $targetGoId, "paymentSessionId" => (double) $paymentSessionId, "encryptedSignature" => $sessionEncryptedSignature); $paymentResult = $go_client->__call('refundPayment', array('sessionInfo' => $paymentSession)); 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"); } }