Ingenico-ePayments / connect-sdk-php

Ingenico Connect PHP Server SDK
https://docs.connect.worldline-solutions.com/documentation/sdk/server/php/
MIT License
39 stars 16 forks source link

Invalid content type; got 'text/html;charset=UTF-8', expected 'application/json' when creating Hosted Checkout #7

Closed driesvb closed 5 years ago

driesvb commented 6 years ago

This error is given when using the example code here.

The currenct exact code (API details omitted) of my implementation:

$communicatorConfig = new CommunicatorConfiguration('
            xxx',
            xxx',
            'https://payment.pay1.sandbox.secured-by-ingenico.com',
            'xxx');

        $connection = new DefaultConnection();
        $communicator = new Communicator($connection, $communicatorConfig);
        $client = new Client($communicator);

        $hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
        $hostedCheckoutSpecificInput->locale = "en_GB";
        $hostedCheckoutSpecificInput->variant = "testVariant";

        $amountOfMoney = new AmountOfMoney();
        $amountOfMoney->amount = 2345;
        $amountOfMoney->currencyCode = "USD";

        $billingAddress = new Address();
        $billingAddress->countryCode = "US";

        $customer = new Customer();
        $customer->billingAddress = $billingAddress;

        $order = new Order();
        $order->amountOfMoney = $amountOfMoney;
        $order->customer = $customer;

        $body = new CreateHostedCheckoutRequest();
        $body->hostedCheckoutSpecificInput = $hostedCheckoutSpecificInput;
        $body->order = $order;

        $response = $client->merchant("1121")->hostedcheckouts()->create($body);

An InvalidResponseException is thrown with Invalid content type; got 'text/html;charset=UTF-8', expected 'application/json' as its message. This happens every time when executing the script.

The correct content type seems to be used in the API implementation though.

rob-spoor commented 6 years ago

The endpoint URL is incorrect. That is not one of the endpoints defined on https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/java/endpoints.html. For the sandbox environment you should be using https://eu.sandbox.api-ingenico.com.

driesvb commented 6 years ago

Ah my mistake. Thanks.