PHP SDK
Getting Started
GitHub-Repository: https://github.com/secuconnect/secuconnect-php-sdk
Requirements
PHP
You need at least the version 7.0.
We recommend to use the version 7.2.
Additionally you need the following extensions for PHP:
Multibyte String – http://php.net/manual/en/book.mbstring.php
You can find the install instructions for PHP here.
Composer
For the simplest installation method you need the "composer" tool.
You can found more information about this tool on the website getcomposer.org.
To install it you need only some simple php calls, which are described here.
Installing the SDK
We recommend installing secuconnect-php-sdk as dependency managed by composer.
You can also find other ways to install the secuconnect-php-sdk on the page Installing the SDK.
composer require
"secuconnect/secuconnect-php-sdk"
For more information please consult Composer documentation.
Configuration
See Configuration section for list of configuration parameters.
Authentication
See Authentication section to learn about authentication process, options and requirements.
Here you can see a working example for our testing environment which authenticate you against the secuconnect API and return you an "Access-Token", which you can use for all your upcoming calls:
require
__DIR__ .
'/vendor/autoload.php'
;
use
Secuconnect\Client\Configuration;
use
Secuconnect\Client\Authentication\Authenticator;
use
Secuconnect\Client\Authentication\OAuthClientCredentials;
$clientId
=
'...'
;
$clientSecret
=
'...'
;
// If you use cache solution, and want SDK to store tokens through it
// Configuration::getDefaultConfiguration()->setCache($yourPSR6Cache);
// Creates authenticator object with OAuth authentication and obtains token
$auth
=
new
Authenticator(OAuthClientCredentials::from(
$clientId
,
$clientSecret
));
$accessToken
=
$auth
->getToken();
// Saves the token to the Swagger default configuration
Configuration::getDefaultConfiguration()->setAccessToken(
$accessToken
);
A sample application
In this sample we create a first payment transaction (with the payment method "prepay") for the payer "John Doe".
// Build request objects
use
Secuconnect\Client\Model\Address;
use
Secuconnect\Client\Model\PaymentCustomersDTOContact;
use
Secuconnect\Client\Model\PaymentCustomersDTO;
use
Secuconnect\Client\Api\PaymentCustomersApi;
use
Secuconnect\Client\ApiException;
$contactAddress
=
new
Address();
$customerContact
=
new
PaymentCustomersDTOContact();
$customer
=
new
PaymentCustomersDTO();
$contactAddress
->setStreet(
'Frankfurter Str.'
)
->setStreetNumber(
'125a'
)
->setPostalCode(
'60326'
)
->setCity(
'Frankfurt am Main'
)
->setCountry(
'Germany'
);
$customerContact
->setSalutation(
'Mr.'
)
->setTitle(
'Dr.'
)
->setForename(
'John'
)
->setSurname(
'Doe'
)
->setCompanyname(
'My Company Inc.'
)
->setDob(
'1905-03-03'
)
->setEmail(
'mr-john-doe@mail.com'
)
->setPhone(
'0049-123-456789'
)
->setMobile(
'0049-987-654321'
)
->setAddress(
$contactAddress
);
$customer
->setContact(
$customerContact
);
// Make request
try
{
$api
=
new
PaymentCustomersApi();
$response
=
$api
->paymentCustomersPost(
$customer
);
// Success. $response contain PaymentCustomersProductModel
$customerId
=
$response
->getId();
echo
'Created new payment customer product with ID: '
.
$customerId
. PHP_EOL;
echo
'Payment customer product data after create:'
. PHP_EOL .
$response
. PHP_EOL;
}
catch
(ApiException
$e
) {
// Failure. $e->getResponseBody() contains ProductExceptionPayload
echo
$e
->getResponseBody() . PHP_EOL;
throw
$e
;
}
Sample Response
Created
new
payment customer product with ID: PCU_2H9PU0FD72MMV8TVASAXV353NAJBAH
Payment customer product data after create:
{
"object"
:
"payment.customers"
,
"id"
:
"PCU_2H9PU0FD72MMV8TVASAXV353NAJBAH"
,
"contract"
: {
"object"
:
"payment.contracts"
,
"id"
:
"PCR_2046JDZQA2MYSP0QQSAXV0QFNWFNAH"
},
"contact"
: {
"forename"
:
"John"
,
"surname"
:
"Doe"
,
"companyname"
:
"My Company Inc."
,
"salutation"
:
"Mr."
,
"title"
:
"Dr."
,
"email"
:
"mr-john-doe@mail.com"
,
"phone"
:
"0049-123-456789"
,
"mobile"
:
"0049-987-654321"
,
"dob"
:
"1905-03-03T00:00:00+01:00"
,
"address"
: {
"street"
:
"Frankfurter Str."
,
"street_number"
:
"125a"
,
"city"
:
"Frankfurt am Main"
,
"postal_code"
:
"60326"
,
"country"
:
"Germany"
}
},
"created"
:
"2018-04-24T17:04:30+02:00"
}