public function testCompletePurchase() { $soapResponse = PaymentStatusResponseTest::paymentStatusWithState(GopayHelper::CREATED); $this->soapClient->expects($this->once())->method('paymentStatus')->with($this->anything())->will($this->returnValue($soapResponse)); $this->getHttpRequest()->query->replace(array('targetGoId' => self::GO_ID, 'paymentSessionId' => '98765', 'orderNumber' => '111', 'encryptedSignature' => GopayHelper::getPaymentIdentitySignature(self::GO_ID, '98765', null, '111', self::SECURE_KEY))); $this->assertSame($soapResponse, $this->gateway->completePurchase(array())->send()->getData()); }
/** * Gets the redirect target url. */ public function getRedirectUrl() { /** @noinspection PhpUndefinedMethodInspection */ $url = $this->getRequest()->getTestMode() ? GopayConfig::TEST_FULL_URL : GopayConfig::PROD_FULL_URL; /** @noinspection PhpUndefinedMethodInspection */ $goId = $this->getRequest()->getGoId(); $paymentSessionId = $this->getData()->paymentSessionId; /** @noinspection PhpUndefinedMethodInspection */ $secureKey = $this->getRequest()->getSecureKey(); return $url . '?' . http_build_query(array('sessionInfo.targetGoId' => $goId, 'sessionInfo.paymentSessionId' => $paymentSessionId, 'sessionInfo.encryptedSignature' => GopayHelper::getPaymentSessionSignature($goId, $paymentSessionId, $secureKey))); }
public function testSendSuccess() { $notificationParams = array('targetGoId' => 12345, 'paymentSessionId' => 1111, 'orderNumber' => 2222, 'encryptedSignature' => GopayHelper::getPaymentIdentitySignature(12345, 1111, null, 2222, GatewayTest::SECURE_KEY)); $paymentStatusParams = array('targetGoId' => 12345, 'paymentSessionId' => 1111, 'encryptedSignature' => GopayHelper::getPaymentSessionSignature(12345, 1111, GatewayTest::SECURE_KEY)); $paymentStatusResponse = PaymentStatusResponseTest::paymentStatusWithState(GopayHelper::CREATED); $this->getHttpRequest()->query->replace($notificationParams); $this->soapClient->expects($this->once())->method('paymentStatus')->with($paymentStatusParams)->will($this->returnValue($paymentStatusResponse)); $this->request = new CompletePurchaseRequest($this->soapClient, $this->getHttpClient(), $this->getHttpRequest()); $this->request->setGoId('12345'); $this->request->setSecureKey(GatewayTest::SECURE_KEY); $response = $this->request->send(); $this->assertSame($paymentStatusResponse, $response->getData()); }
public static function paymentStatusWithState($sessionState) { $data = new stdClass(); $data->targetGoId = 12345; $data->productName = 'Product Description'; $data->totalPrice = 1000; $data->currency = 'CZK'; $data->orderNumber = '1234'; $data->recurrentPayment = ''; $data->parentPaymentSessionId = ''; $data->preAuthorization = ''; $data->result = GopayHelper::CALL_COMPLETED; $data->sessionState = $sessionState; $data->sessionSubState = ''; $data->paymentChannel = ''; $data->paymentSessionId = 11112222; $data->encryptedSignature = GopayHelper::encrypt(GopayHelper::hash(GopayHelper::concatPaymentStatus($data, self::SECURE_KEY)), self::SECURE_KEY); return $data; }
/** * Kontrola parametru predavanych ve zpetnem volani po potvrzeni/zruseni platby - verifikace podpisu. * * @param float $returnedPaymentSessionId - paymentSessionId vracene v redirectu * @param string $returnedEncryptedSignature - kontrolni podpis vraceny v redirectu * @param float $paymentResult - vysledek volani * @param float $paymentSessionId - identifikator platby na GoPay * @param string $secureKey - kryptovaci klic prideleny eshopu / uzivateli, urceny k podepisovani komunikace * * @throws Exception */ public static function checkPaymentResult($returnedPaymentSessionId, $returnedEncryptedSignature, $paymentResult, $paymentSessionId, $secureKey) { if ($returnedPaymentSessionId != $paymentSessionId) { throw new Exception("PaymentResult invalid PSID"); } $hashedSignature = GopayHelper::hash(GopayHelper::concatPaymentResult((double) $paymentSessionId, $paymentResult, $secureKey)); $decryptedHash = GopayHelper::decrypt($returnedEncryptedSignature, $secureKey); if ($decryptedHash != $hashedSignature) { throw new Exception("PaymentResult invalid signature"); } }
/** * Send the request with specified data * * @param mixed $data The data to send * @return ResponseInterface */ public function sendData($data) { $paymentSession = array("targetGoId" => (double) $this->getGoId(), "paymentSessionId" => (double) $data['paymentSessionId'], "encryptedSignature" => GopayHelper::getPaymentSessionSignature($this->getGoId(), $data['paymentSessionId'], $this->getSecureKey())); $paymentStatus = $this->soapClient->paymentStatus($paymentSession); return new PaymentStatusResponse($this, $paymentStatus); }
/** * Dokončení platby * * @param float $paymentSessionId - identifikator platby * @param float $targetGoId - identifikator prijemnce - GoId * @param string $secureKey - kryptovaci klic prideleny GoPay * @throws \Exception * @return float payment session ID */ public function capturePayment($paymentSessionId, $targetGoId, $secureKey) { try { //inicializace WS $go_client = self::createSoapClient(); $sessionEncryptedSignature = GopayHelper::getPaymentSessionSignature($targetGoId, $paymentSessionId, $secureKey); $paymentSession = array("targetGoId" => (double) $targetGoId, "paymentSessionId" => (double) $paymentSessionId, "encryptedSignature" => $sessionEncryptedSignature); $paymentResult = $go_client->__call('capturePayment', array('sessionInfo' => $paymentSession)); if ($paymentResult->result == GopayHelper::CALL_RESULT_FAILED) { throw new Exception("payment not captured [" . $paymentResult->resultDescription . "]"); } else { if ($paymentResult->result == GopayHelper::CALL_RESULT_ACCEPTED) { // dokonceni 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"); } }
print_r($purchaseData); $purchaseResponse = null; try { $purchaseResponse = $gateway->purchase($purchaseData)->send(); echo $gateway->getSoapClient()->__getLastRequest(); } catch (Exception $e) { echo $gateway->getSoapClient()->__getLastRequest(); throw $e; } echo "Received response:"; print_r($purchaseResponse->getData()); if (!$purchaseResponse->isSuccessful() && !$purchaseResponse->isRedirect()) { print "Response is not successful and not a redirect: " . $purchaseResponse->getMessage(); exit(1); } // Simulate notification $_GET['paymentSessionId'] = $purchaseResponse->getData()->paymentSessionId; $_GET['targetGoId'] = $purchaseResponse->getData()->targetGoId; $_GET['orderNumber'] = $purchaseResponse->getData()->orderNumber; $_GET['encryptedSignature'] = GopayHelper::getPaymentIdentitySignature($_GET['targetGoId'], $_GET['paymentSessionId'], null, $_GET['orderNumber'], $secureKey); // Recreate gateway to pick up the GET parameters $gateway = createGateway($goId, $secureKey); try { $completePurchaseResponse = $gateway->completePurchase()->send(); echo $gateway->getSoapClient()->__getLastRequest(); } catch (Exception $e) { echo $gateway->getSoapClient()->__getLastRequest(); throw $e; } echo "Received response to completePurchase (payment status):"; print_r($completePurchaseResponse->getData());