Migration from secucard-connect-php-sdk
Install SDK / composer file
secucard-connect SDK (old)
{
"require"
: {
"secucard/secucard-connect"
:
"^1.26.0"
}
}
secuconnect SDK (new)
{
"require"
: {
"secuconnect/secuconnect-php-sdk"
:
"^2.40.0"
}
}
See also
Initialize SDK Client
Please note that the default server for the new SDK is our testing environment (in the old SDK it was the live environment by default).
secucard-connect SDK (old)
date_default_timezone_set(
'Europe/Berlin'
);
require_once
__DIR__ .
"./vendor/autoload.php"
;
// Change environment to live / testing (default is "live")
$config
= \SecucardConnect\ApiClientConfiguration::createFromArray([
'base_url'
=>
'https://connect-testing.secupay-ag.de'
, // demo server
// 'base_url' => 'https://connect.secucard.com', // live
'debug'
=> false
// TODO Set to TRUE to display the http client logs
]);
// Create logger
$logger
=
new
Logger(
fopen
(
"php://stdout"
,
"a"
), false); // TODO Set to TRUE to display the sdk logging stuff
// Create cache storage
$store
=
new
FileStorage(__DIR__ .
'/.cache'
);
// Set credentials
$clientId
=
'...'
;
$clientSecret
=
'...'
;
$cred
=
new
ClientCredentials(
$clientId
,
$clientSecret
);
$secucard
=
new
SecucardConnect(
$config
,
$logger
,
$store
,
$store
,
$cred
);
$token
=
$secucard
->authenticate();
echo
'Auth token: '
.
$token
;
/*
* Sample output:
* ==============
* Auth token: dprfdtmuttqhm6k1omm7bnl7d0
*/
secuconnect SDK (new)
<?php
date_default_timezone_set(
'Europe/Berlin'
);
require_once
__DIR__ .
'/../../vendor/autoload.php'
;
use
Secuconnect\Client\ApiException;
use
Secuconnect\Client\Authentication\Authenticator;
use
Secuconnect\Client\Cache\FileCache;
use
Secuconnect\Client\Configuration;
try
{
// Change environment to live / testing (default is "testing")
Configuration::getDefaultConfiguration()->setHost(
'https://connect-testing.secupay-ag.de/api/v2'
); // demo server
// Configuration::getDefaultConfiguration()->setHost('https://connect.secucard.com/api/v2'); // live
Configuration::getDefaultConfiguration()->setAuthHost(
'https://connect-testing.secupay-ag.de/'
); // demo server
// Configuration::getDefaultConfiguration()->setAuthHost('https://connect.secucard.com/'); // live
// Create logger
// -> not needed anymore
// Create cache storage
Configuration::getDefaultConfiguration()->setCache(
new
FileCache(__DIR__ .
'/.cache'
));
// Set credentials
$token
= Authenticator::authenticateByClientCredentials(
'...'
,
'...'
);
echo
'Auth token: '
.
$token
;
/*
* Sample output:
* ==============
* Auth token: dprfdtmuttqhm6k1omm7bnl7d0
*/
}
catch
(ApiException
$e
) {
echo
$e
->getTraceAsString();
print_r(
$e
->getResponseBody());
$supportId
=
''
;
if
(isset(
$e
->getResponseBody()->supportId)) {
$supportId
=
' Support-ID: '
.
$e
->getResponseBody()->supportId;
}
throw
new
Exception(
'Request was not successful, check the log for details.'
.
$supportId
);
}
See also
Create a credit card payment
secucard-connect SDK (old)
$contact
=
new
Contact();
$contact
->salutation =
'Mr.'
;
$contact
->title =
'Dr.'
;
$contact
->forename =
'John'
;
$contact
->surname =
'Doe'
;
$contact
->companyname =
'Testfirma'
;
$contact
->dob =
'1971-02-03'
;
$contact
->birthplace =
'MyBirthplace'
;
$contact
->nationality =
'DE'
;
// specifying email for customer is important, so the customer can receive Mandate information
$contact
->email =
'example@example.com'
;
$contact
->phone =
'+49123456789'
;
$address
=
new
Address();
$address
->street =
'Example Street'
;
$address
->street_number =
'6a'
;
$address
->city =
'ExampleCity'
;
$address
->country =
'DE'
;
$address
->postal_code =
'01234'
;
$contact
->address =
$address
;
$customer
=
new
Customer();
$customer
->contact =
$contact
;
/**
* @var \SecucardConnect\Product\Payment\SecupayCreditcardsService $service
*/
$service
=
$secucard
->payment->secupaycreditcards;
$creditcard
=
new
SecupayCreditcard();
$creditcard
->amount = 100;
// Amount in cents (or in the smallest unit of the given currency)
$creditcard
->currency =
'EUR'
;
// The ISO-4217 code of the currency
$creditcard
->purpose =
'Your purpose from TestShopName'
;
$creditcard
->order_id =
'201600123'
;
// The shop order id
$creditcard
->customer =
$customer
;
$creditcard
->redirect_url =
new
RedirectUrl();
// The customer will be redirected to "url_success" after you (the shop) has show him the iframe
// and he has filled out the form in this iframe.
// The url of this iframe will be returned in the response of this save request in the variable called "iframe_url".
$creditcard
->redirect_url->url_success =
'http://shop.example.com/success.php'
;
// The customer will be redirected to "url_failure" if we don't accept him for credit card payments.
// You should offer him to pay with other payment methods on this page.
$creditcard
->redirect_url->url_failure =
'http://shop.example.com/failure.php'
;
try
{
$creditcard
=
$service
->save(
$creditcard
);
}
catch
(\Exception
$e
) {
echo
'Error message: '
.
$e
->getMessage() .
"\n"
;
}
if
(
$creditcard
->id) {
echo
'Created secupay creditcard transaction with id: '
.
$creditcard
->id .
"\n"
;
echo
'Creditcard data: '
. print_r(
$creditcard
, true) .
"\n"
;
}
else
{
echo
'Creditcard creation failed'
.
"\n"
;
}
secuconnect SDK (new)
<?php
require
__DIR__ .
'/init.php'
;
use
Secuconnect\Client\Api\SmartTransactionsApi;
use
Secuconnect\Client\ApiException;
use
Secuconnect\Client\Model\Address;
use
Secuconnect\Client\Model\Contact;
use
Secuconnect\Client\Model\PaymentContext;
use
Secuconnect\Client\Model\ProductInstanceID;
use
Secuconnect\Client\Model\SmartTransactionPaymentCustomerDTO;
use
Secuconnect\Client\Model\SmartTransactionsApplicationContext;
use
Secuconnect\Client\Model\SmartTransactionsApplicationContextReturnUrls;
use
Secuconnect\Client\Model\SmartTransactionsBasketInfo;
use
Secuconnect\Client\Model\SmartTransactionsDTO;
try
{
$contact
=
new
Contact();
$contact
->setSalutation(
'Mr.'
);
$contact
->setTitle(
'Dr.'
);
$contact
->setForename(
'John'
);
$contact
->setSurname(
'Doe'
);
$contact
->setCompanyname(
'Testfirma'
);
$contact
->setDob(
'1971-02-03'
);
$contact
->setBirthplace(
'MyBirthplace'
);
$contact
->setNationality(
'DE'
);
// specifying email for customer is important, so the customer can receive Mandate information
$contact
->setEmail(
'example@example.com'
);
$contact
->setPhone(
'+49123456789'
);
$address
=
new
Address();
$address
->setStreet(
'Example Street'
);
$address
->setStreetNumber(
'6a'
);
$address
->setCity(
'ExampleCity'
);
$address
->setCountry(
'DE'
);
$address
->setPostalCode(
'01234'
);
$contact
->setAddress(
$address
);
$customer
=
new
SmartTransactionPaymentCustomerDTO();
$customer
->setContact(
$contact
);
$creditcard
=
new
SmartTransactionsDTO();
$creditcard
->setContract(
new
ProductInstanceID([
'id'
=>
'GCR_2H69XY35227V2VKP9WRA3SJ0W95RP0'
]));
$basket_info
=
new
SmartTransactionsBasketInfo();
$basket_info
->setSum(100);
// Amount in cents (or in the smallest unit of the given currency)
$basket_info
->setCurrency(
'EUR'
);
// The ISO-4217 code of the currency
$creditcard
->setBasketInfo(
$basket_info
);
$creditcard
->setTransactionRef(
'Your purpose from TestShopName'
);
$creditcard
->setMerchantRef(
'201600123'
);
// The shop order id
h2.
$creditcard
->setCustomer(
$customer
);
$application_context
=
new
SmartTransactionsApplicationContext();
$application_context
->setCheckoutTemplate(
'COT_WD0DE66HN2XWJHW8JM88003YG0NEA2'
);
// The customer will be redirected to "url_success" after you (the shop) has shown him the iframe,
// and he has filled out the form in this iframe.
// The url of this iframe will be returned in the response of this save request in the variable called "iframe_url".
$return_urls
=
new
SmartTransactionsApplicationContextReturnUrls();
$return_urls
->setUrlSuccess(
'http://shop.example.com/success.php'
);
// The customer will be redirected to "url_failure" if we don't accept him for credit card payments.
// You should offer him to pay with other payment methods on this page.
$return_urls
->setUrlError(
'http://shop.example.com/failure.php'
);
$application_context
->setReturnUrls(
$return_urls
);
$creditcard
->setApplicationContext(
$application_context
);
$payment_context
=
new
PaymentContext();
$payment_context
->setAutoCapture(true);
// $payment_context->setAccrual(true);
$creditcard
->setPaymentContext(
$payment_context
);
$creditcard
= (
new
SmartTransactionsApi())->addTransaction(
$creditcard
);
if
(
$creditcard
->getId()) {
echo
'Created secupay creditcard transaction with id: '
.
$creditcard
->getId() .
"\n"
;
echo
'Creditcard data: '
. print_r(
$creditcard
->__toString(), true) .
"\n"
;
echo
'Iframe-Link: '
.
$creditcard
->getPaymentLinks()[
'creditcard'
] .
"\n"
;
}
else
{
echo
'Creditcard creation failed'
.
"\n"
;
}
/*
* Sample output:
* ==============
* Created secupay creditcard transaction with id: STX_WC3HTTY372PAYSVPVCN9ZM5R0YM9AK
* Creditcard data: {
* ...
* Iframe-Link: https://pay-dev.secuconnect.com?payment-method=creditcard&stx=STX_WC3HTTY372PAYSVPVCN9ZM5R0YM9AK&contract=GCR_2H69XY35227V2VKP9WRA3SJ0W95RP0&server=testing
*/
}
catch
(ApiException
$e
) {
echo
$e
->getTraceAsString();
print_r(
$e
->getResponseBody());
$supportId
=
''
;
if
(isset(
$e
->getResponseBody()->supportId)) {
$supportId
=
' Support-ID: '
.
$e
->getResponseBody()->supportId;
}
throw
new
Exception(
'Request was not successful, check the log for details.'
.
$supportId
);
}
More
Please visit https://github.com/secuconnect/secuconnect-php-sdk-demo/tree/master/src/migrate for more examples.