Git Product home page Git Product logo

saferpayjsonapi's Introduction

SaferpayJsonApi

Build Status

A php library to use the Saferpay Json API.

Installation

Add the library in your composer.json:

composer require ticketpark/saferpay-json-api

Usage

In order to perform a payment as you would typically do it in an online shop, you need to handle the following steps:

  1. Initialize the payment page (see /example/PaymentPage/example-initialize.php)
  2. Redirect the user to the payment page and let them enter their payment data
  3. Assert that the payment was successfully done (see /example/PaymentPage/example-assert.php)
  4. Capture the payment to make it final (see /example/Transaction/example-capture.php)

Have a look at the example folder for more.

Documentation

Find the most current documentation of the Saferpay JSON API here:
https://saferpay.github.io/jsonapi/

This library is currently based on v1.31 of the Saferpay JSON API.

Contribution

You are welcome to contribute to this repo.

saferpayjsonapi's People

Contributors

bacbos avatar codesource avatar fabianerni avatar geekdevs avatar giriroub avatar laravel-vesuvius avatar maldoinc avatar sprain avatar szepeviktor avatar thomasmeike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

saferpayjsonapi's Issues

composer installs release 3.0.1 on a php 8 system

If one requires the library on a php 8 system release 3.0.1 is installed, since it has the composer requirement
"php": ">=7.3"
This was changed for release 3.1 to
"php": "^7.3"
which makes all later releases incompatible with php 8.
Can the library be made compatible with php 8?

JSON schema

What do you think about creating a JSON schema for Saferpay API and generating our code/or automate things based on that?

Yes, I thought about this, too. It would definitely make development simpler. It can still be added later without breaking a v3 release.

I would contribute to it and get you some money to work on it.

@sprain What do you think?

I get an exception if i try to initialize.

If i initialize with same structure as you have in your 1-example-initialize.php but with my credentials, i get the following exception:

Uncaught exception 'Ticketpark\SaferpayJson\Exception\HttpRequestException' with message 'file_get_contents(https://test.saferpay.com/api//Payment/v1/PaymentPage/Initialize): failed to open stream: operation failed' in MYPATH\ticketpark\saferpay-json-api\lib\SaferpayJson\Message\Request.php:188

Do you have any ideas?

Best Regards
Priska

Composer version

why is there difference between code on github example folder (1-example-capture.php) and example folder when you install it via composer ?

You are likely not installing the most recent version.

Originally posted by @sprain in #47 (comment)

This is my composer version "ticketpark/saferpay-json-api": "^1.5"

Notification values seems to be not recognized by the API

As there's no example to set up an NotifyUrl I tried this:

$notification = new Container\Notification();
$notification->setNotifyUrl('https://domain.tld/success.php');
...
$initializeRequest = new InitializeRequest(
$requestConfig,
$terminalId,
$payment,
$returnUrls,
$notification
);

No error occured during the transaction, but the URL isn't called from https://test.saferpay.com/
I tried to find out what's wrong, is there a way to debug it to file?

Error message: Transaction already captured

When i get redirect to success url i get transaction id from AssertRequest which i pass to Capture but then i get Transaction already captured, what i am doing wrong ?

Some ideas from the top of my mind:

  • You are not using the correct token?
  • You are executing the same code more than once?
  • You have some kind of auto-capturing enabled in your Saferpay account?

Originally posted by @sprain in #47 (comment)

I have tried any idea that i can thinkof - really don't know what to do else.

I have created "steps" for each part of Saferpay API, the last one CAPTURE is where we stucked. After geting TransactionId we have started capturing and we get this message TRANSACTION_ALREADY_CAPTURED

I have checked everything (double loading of CAPTURE script, disabling CAPTURE script so we can get TranscationId).

If the process of CAPTURE didn't happend from our side (where we get message TRANSACTION_ALREADY_CAPTURED) then in saferpay Journal it will be Pending and if we do it then in saferpay Journal it will be Capture.

I am developer for 12 years so i am always checking steps back to find bug, but now need your help if it possible...

Missing LanguageCode parameter on InitializeRequest::class

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

Missing InitializeRequest for transaction

Hi,

I'm wondering how I would initialize a transaction via /Payment/v1/Transaction/Initialize. It seems that there is no InitializeRequest in the Request\Transaction namespace.

Error on RequestExecute

Hi,
Here is what I got:

Fatal error: Uncaught exception 'Ticketpark\SaferpayJson\Exception\HttpRequestException' with message 'file_get_contents(https://test.saferpay.com/api//Payment/v1/PaymentPage/Initialize): failed to open stream: operation failed' in /var/www/site/vendor/ticketpark/saferpay-json-api/lib/SaferpayJson/Message/Request.php:188
Stack trace:
#0 /var/www/site/eshop/eshop.pay.php(262): Ticketpark\SaferpayJson\Message\Request->execute()
#1 {main}
thrown in /data/zmodules_beta/vendor/ticketpark/saferpay-json-api/lib/SaferpayJson/Message/Request.php on line 188

/var/www/site/eshop/eshop.pay.php(262) is last line here:

$response = (new InitializeRequest($apiKey, $apiSecret))
->setRequestHeader($requestHeader)
->setPayment($payment)
->setTerminalId($terminalId)
->setReturnUrls($returnUrls)
->setNotification($notification)
->execute();

On script top I have
use \Ticketpark\SaferpayJson\PaymentPage\InitializeRequest;
use \Ticketpark\SaferpayJson\Container;
use \Ticketpark\SaferpayJson\Message\ErrorResponse;

I checked with ngrep, the connection to test.saferpay.com:443 happens.

What did I made wrong ?

Best regards

Multiple wrong return type hints

After running phpstan on level 3 i get the following errors on my project:

  56     Call to method setRequestId() on an unknown class Ticketpark\SaferpayJson\Container\Header.
  102    Call to method getErrorMessage() on an unknown class Ticketpark\SaferpayJson\Message\Ticketpark\SaferpayJson\Message\Response.
  105    Call to method getToken() on an unknown class Ticketpark\SaferpayJson\Message\Ticketpark\SaferpayJson\Message\Response.
  108    Call to method getRedirectUrl() on an unknown class Ticketpark\SaferpayJson\Message\Ticketpark\SaferpayJson\Message\Response.
  116    Call to method setRequestId() on an unknown class Ticketpark\SaferpayJson\Container\Header.
  127    Call to method getErrorMessage() on an unknown class Ticketpark\SaferpayJson\Message\Ticketpark\SaferpayJson\Message\Response.
  130    Call to method getTransaction() on an unknown class Ticketpark\SaferpayJson\Message\Ticketpark\SaferpayJson\Message\Response.
  140    Call to method setRequestId() on an unknown class Ticketpark\SaferpayJson\Container\Header.

It's because on some classes the return type in the docblock is wrong. E.g. the class RequestHeader is chainable but the return type is Header.

Response view

Hello, thank you very much for this script but i have 3 question.

  • how can i get "full" reponse from AssertRequest class or CaptureRequest so i can get some more information ?
  • in RecurringPayment where do i need to set $payment->setRecurring ?
  • When i get redirect to success url i get transaction id from AssertRequest which i pass to Capture but then i get Transaction already captured, what i am doing wrong ?

Thank you very much for your answers.

Request URLs contain a double slash

The Request class concatinates the Request::ROOT_URL constant with the API_PATH constant of the extending class, which results in a double slash in the URL.
saferpay.com seems to ignore this issue, but it may cause problems in case they will not accept such URLs in the future

Example
Request::ROOT_URL = 'https://www.saferpay.com/api/'
AliasAssertInsertRequest::API_PATH = '/Payment/v1/Alias/AssertInsert'

Request::getURL() will combine this to
https://www.saferpay.com/api//Payment/v1/Alias/AssertInsert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.