PHP code example of olssonm / swish-php
1. Go to this page and download the library: Download olssonm/swish-php 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' );
olssonm / swish-php example snippets
use Swish ;
use Olssonm \Swish \Payment ;
$response = Swish::create(new Payment([
'callbackUrl' => 'https://callback-url.com' ,
'payeePaymentReference' => 'XVY77' ,
'payeeAlias' => '123xxxxx' ,
'payerAlias' => '321xxxxx' ,
'amount' => '100' ,
'currency' => 'SEK' ,
'message' => 'My product' ,
]));
try {
$response = $client->create($payment);
} catch (ValidationException $exception) {
$errors = $exception->getErrors();
foreach ($errors as $error) {
$error->errorCode;
$error->errorMessage;
}
}
use Olssonm \Swish \Callback ;
$paymentOrRefund = Callback::parse();
class SwishController
{
public function Callback (Request $request)
{
$data = Callback::parse($request->getContent());
if (get_class($data) == \Olssonm\Swish\Payment::class) {
} else if (get_class($data) == \Olssonm\Swish\Refund::class) {
} else if (get_class($data) == \Olssonm\Swish\Payout::class) {
}
}
}
composer
php artisan vendor:publish --provider="Olssonm\Swish\Providers\SwishServiceProvider"
php
return [
'certificates' => [
'client' => env('SWISH_CLIENT_CERTIFICATE_PATH' ),
'password' => env('SWISH_CLIENT_CERTIFICATE_PASSWORD' ),
'root' => env('SWISH_ROOT_CERTIFICATE_PATH' , true ),
'signing' => env('SWISH_SIGNING_CERTIFICATE_PATH' , null ),
'signing_password' => env('SWISH_CLIENT_SIGNING_PASSWORD' , null ),
],
'endpoint' => env('SWISH_URL' , \Olssonm\Swish\Client::PRODUCTION_ENDPOINT),
];
php
$payment = $client->get(Payment(['id' => '5D59DA1B1632424E874DDB219AD54597' ]));
php
$payout = new Payout([
'signingCertificateSerialNumber' => '4512B3EBDA6E3CE6BFB14ABA6274A02C'
])
php
$id = 'EBB5C73503084E3C9AEA8A270AEBFE15' ;
$id = 'ebb5c735-0308-4e3c-9aea-8a270aebfe15' ;
$payment = new Payment([
'id' => $id
]);