Ticketpark / SaferpayJsonApi

A php library to use the Saferpay Json API
MIT License
32 stars 25 forks source link

Missing LanguageCode parameter on InitializeRequest::class #50

Closed mathmul closed 3 years ago

mathmul commented 3 years ago

The story

I tried this package and everything works great. After Initialization I get a Response with a Redirect URL. Redirecting to that URL immediately re-redirects again (both on Saferpay's domain) and on that second site you may choose language via menu. The language is changed by means of a GET query parameter VTLanguage={LanguageCode}. I tried appending that to the Redirect URL given by Initialization Response, but to no avail. I then contacted Saferpay Integration Support and they tell me:

The language of the payment page can be set in the initialize request by the parameter LanguageCode

How to reproduce

Trying the following snippet

$initializeRequest = (new InitializeRequest(
    requestConfig: $requestConfig,
    terminalId: $terminalId,
    payment: $payment,
    returnUrls: $returnUrls
))->setLanguageCode($languageCode);

results in Fatal Error: Method setLanguageCode() not found.

Expected behaviour

No error. $initializeRequest should be an object of class InitializeRequest with the appropriate language code set for the Redirect URL.

Note

If language code is not set, Saferpay determines language from browser agent's language preference list, so this issue is not that urgent. But let's say a client has a language preference of Slovene, but prefers to browse the e-commerce website in English, we can agree that they would prefer to stay with the English language when moved to Saferpay's domain.

Note 2

In Integration Support's email the corresponded also quoted a list of supported language codes:

de - German de-ch - Swiss German en - English fr - French da - Danish cs - Czech et - Estonian hr - Croatian it - Italian hu - Hungarian lv - Latvian lt - Lithuanian nl - Dutch nn - Norwegian pl - Polish pt - Portuguese ru - Russian ro - Romanian sk - Slovak sl - Slovenian fi - Finnish sv - Swedish tr - Turkish el - Greek ja - Japanese zh - Chinese

sprain commented 3 years ago

Hi @mathmul – thanks for the report. ~You are right, setting the language code is currently not implemented in this library. A pull request to do so would be welcome.~

The language code is supported. See https://github.com/Ticketpark/SaferpayJsonApi/issues/50#issuecomment-897380588

mathmul commented 3 years ago

Well that would be a first for me. Such a noob, I know. I am trying though..

Just added

    /**
     * @var string|null
     * @SerializedName("LanguageCode")
     */
    private $languageCode;

    // ...

    public function getLanguageCode(): ?string
    {
        return $this->languageCode;
    }

    public function setLanguageCode(?string $languageCode): self
    {
        $this->languageCode = $languageCode;

        return $this;
    }

to InitializeRequest.php, but I've no idea how to proceed so it will actually be sent in the Request.

I will be VERY happy to send my first PR. Really hoping now no one beats me to the punch.

But if someone would guide me through, I'd learn a lot faster and be very grateful for it :) Google here I come!

sprain commented 3 years ago

Great!

The @SerializedName annotation should actually take care of sending it to the request. I suppose, your code should already work. If not, still submit it as a pr and we can debug together.

mathmul commented 3 years ago

Alright alright alright :)

PR was easier than expected!

Hope it went through.

EDIT: Ugh... Scrutinizer sure has a lot 👎 to say about it ':)

sprain commented 3 years ago

As noticed over in #51, the behaviour is actually already implemented in the library. Setting the languageCode is part of the Payer container and can be used like this:

$initializeRequest = new InitializeRequest(
    $requestConfig,
    $terminalId,
    $payment,
    $returnUrls
);

$payer = new Container\Payer();
$payer->setLanguageCode('fr');

$initializeRequest->setPayer($payer);
mathmul commented 3 years ago

Works great!