slevomat / csob-gateway

Client library for CSOB card payment gateway
MIT License
27 stars 10 forks source link

Bad Request #42

Closed theedov closed 4 years ago

theedov commented 4 years ago

Zdravím, můžete mě trochu nasměrovat správným směrem. Snažím se nastavit testovací rozhraní a dostávám tuhle chybu:

[2020-02-18 22:26:31] request.CRITICAL: Uncaught PHP Exception SlevomatCsobGateway\Api\BadRequestException: "Bad Request" at /httpdocs/vendor/slevomat/csob-gateway/src/Api/ApiClient.php line 250 {"exception":"[object] (SlevomatCsobGateway\\Api\\BadRequestException(code: 0): Bad Request at //httpdocs/vendor/slevomat/csob-gateway/src/Api/ApiClient.php:250)"} []

Problém je určitě v klíčích. Můj postup byl takový, že jsem šel na web https://iplatebnibrana.csob.cz/keygen/ a vygeneroval anonymní merchant id A4406sKhTJ, stáhl private, public key a klikl na tlačítko odeslal veřejný klíč bance.

Tohle je můj kód:


        $apiClient = new ApiClient(
            new CurlDriver(),
            new CryptoService(
                $this->container->get('kernel')->getRootDir() . '/../config/certificates/csob/A4406sKhTJ.key',
                $this->container->get('kernel')->getRootDir() . '/../config/certificates/csob/A4406sKhTJ.pub'
            ),
        'https://iapi.iplatebnibrana.csob.cz/api/v1.8'
        );

        $requestFactory = new RequestFactory('A4406sKhTJ');

        $cart = new Cart(Currency::get(Currency::CZK));
        $cart->addItem('Nákup', 1, ($ammount * 100));

        $paymentResponse = $requestFactory->createInitPayment(
            $orderNumber,
            PayOperation::get(PayOperation::PAYMENT),
            PayMethod::get(PayMethod::CARD),
            true,
            $this->router->generate('payment_return', [], UrlGeneratorInterface::ABSOLUTE_URL),
            HttpMethod::get(HttpMethod::POST),
            $cart,
            null,
            null,
            Language::get(Language::CZ)
        )->send($apiClient);
        $payId = $paymentResponse->getPayId();

        $processPaymentResponse = $requestFactory->createProcessPayment($payId)->send($apiClient);

Zkoušel jsem použit i mips_iplatebnibrana.csob.cz.pub key z https://github.com/csob/paymentgateway/tree/master/keys, ale potom dostávám tuhle chybu:

[2020-02-18 22:39:38] request.CRITICAL: Uncaught PHP Exception SlevomatCsobGateway\Crypto\PublicKeyFileException: "Public key could not be loaded from file '/httpdocs/src/../config/certificates/csob/mips_iplatebnibrana.csob.cz.pub'. Please make sure that the file contains valid public key." at /httpdocs/vendor/slevomat/csob-gateway/src/Crypto/CryptoService.php line 82 {"exception":"[object] (SlevomatCsobGateway\\Crypto\\PublicKeyFileException(code: 0): Public key could not be loaded from file '/httpdocs/src/../config/certificates/csob/mips_iplatebnibrana.csob.cz.pub'. Please make sure that the file contains valid public key. at /httpdocs/vendor/slevomat/csob-gateway/src/Crypto/CryptoService.php:82)"} []

theedov commented 4 years ago

Chyba byla v mips_iplatebnibrana.csob.cz.pub, nějak divně se mi stáhl...