1. Go to this page and download the library: Download webmasterlv/swedbank-spp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webmasterlv / swedbank-spp example snippets
use Swedbank\SPP\Accreditation;
$accreditation = new Accreditation();
$accreditation -> setDev('devuser', 'devpass', 'http://dev.example.com/payments/');
$accreditation -> setProd('produser', 'prodpass', 'http://www.example.com/payments/');
use Swedbank\SPP\Merchant;
$merchant = new Merchant();
$merchant -> setRegion(Gateway::REGION_LAT);
$merchant -> setLanguage(Gateway::LANG_LAT);
use Swedbank\SPP\Gateway;
$gateway = new Gateway($accreditation, $merchant, Gateway::ENV_DEV);
$gateway -> setLogger($logger);
use Swedbank\SPP\Order;
$orderId = 12345;
$orderDescr = 'Payment for book';
$orderAmount = 10;
$order = new Order($orderId, $orderDescr, $orderAmount);
use Swedbank\SPP\Payment\CreditCard;
use Swedbank\SPP\Payment\InternetBank;
use Swedbank\SPP\Payment\PayPal;
// Internet banking
$method = new InternetBank(InternetBank::SWEDBANK);
// PayPal
$method = new PayPal();
// Credit Card
$method = new CreditCard();
$result = $gateway -> createTransaction($order, $customer, $method);
if ($result -> isSuccess()) {
// Save gateway order ID and payment method for later retrieval
$referenceId = $result -> getReference();
// Redirect customer to this URL
$redirectUrl = $result -> getRedirectUrl(); // User redirect URL
header("Location: ".$redirectUrl);
exit;
} else {
$errorCode = $result -> getStatus(); // Error code (see 5.2)
$errorMessage = $result -> getMessage(); // Error message
$internalCode = $result -> getRemoteStatus(); // Internal error code
}
$isExtended = false;
// Your internal order ID, this should always be present
$orderID = $_GET['_merchantRef'];
// The status returned from payment system. You should not rely on this! This is just to prematurely
// indicate whether payment was successful or not. If you cannot detect transaction status at this moment,
// just redirect customer to hinted page. Available values are 'success' or 'fail'.
$status = $_GET['_banklinkStatus'];
// Reference ID. May not be present! Use $orderID to determine reference ID.
$referenceId = $_GET['dts_reference'];
// Assuming you now have $referenceId
// Assuming you have your Gateway instance ready
$method = new CreditCard(); // or PayPal() or InternetBank() depending on original payment method.
$status = $gateway -> getStatus($order, $customer, $method, $referenceId, $isExtended);
if ($status -> isSuccess()) {
// Payment is successful!
// Update data about your order accordingly.
}