2017 © Pedro Peláez
 

library swish-php

PHP-wrapper for the Swish api

image

fredrik01/swish-php

PHP-wrapper for the Swish api

  • Thursday, June 28, 2018
  • by Fredrik01
  • Repository
  • 1 Watchers
  • 0 Stars
  • 413 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 7 Versions
  • 53 % Grown

The README.md

Swish-PHP

This is a fork of helmutschneider/swish-php that supports Docker., (*1)

Swish-PHP is a small wrapper for the swish merchant api. See https://www.getswish.se/handel/ for more information., (*2)

Dependencies

  • PHP 5.5.9 or newer
  • curl
  • openssl

Dev dependencies

  • Just Docker and Docker Compose

Installation

git clone https://github.com/Fredrik01/swish-php.git
docker-compose run --rm swish composer install

Obtaining test certificates

Swish documentation as of 2018-06-27: https://developer.getswish.se/content/uploads/2017/04/MerchantsAPI_Getswish_180517_v1.91.pdf Test certificate bundle as of 2018-06-27: https://developer.getswish.se/content/uploads/2017/04/Merchants_Test-1.zip, (*3)

Begin by obtaining the SSL certificates required by Swish. The Swish server itself uses a self-signed root certificated so a CA-bundle to verify its origin is needed. You will also need a client certificate and corresponding private key so the Swish server can identify you., (*4)

As of 2018-06-27 the test certificates are called Swish Merchant Test Certificate 1231181189.key, Swish Merchant Test Certificate 1231181189.pem and Swish TLS Root CA.pem. You must concatenate Swish Merchant Test Certificate 1231181189.key and Swish Merchant Test Certificate 1231181189.pem together, otherwise they will not work with cURL. This bundle is your client certificate., (*5)

Usage

The client closely mirrors the swish api:, (*6)

class Client
{

    /**
     * @param PaymentRequest $request
     * @return string payment request id
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws ValidationException
     */
    public function createPaymentRequest(PaymentRequest $request): string;

    /**
     * @param string $id Payment request id
     * @return PaymentRequest
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getPaymentRequest(string $id): PaymentRequest;

    /**
     * @param Refund $refund
     * @return string refund id
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws ValidationException
     */
    public function createRefund(Refund $refund): string;

    /**
     * @param string $id Refund id
     * @return Refund
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getRefund(string $id): Refund;
}

When you have the SSL certificates ready you may instantiate the client:, (*7)

use HelmutSchneider\Swish\Client;
use HelmutSchneider\Swish\Util;

// Swish CA root cert
$rootCert = 'path/to/swish-root.crt'; // forwarded to guzzle's "verify" option

// .pem-bundle containing your client cert and it's corresponding private key. forwarded to guzzle's "cert" option
// you may use an empty string for "password" if you are using the test certificates.
$clientCert = ['path/to/client-cert.pem', 'password'];

$client = Client::make($rootCert, $clientCert);

$pr = new PaymentRequest([
    'callbackUrl' => 'https://localhost/swish',
    'payeePaymentReference' => '12345',
    'payerAlias' => '4671234768',
    'payeeAlias' => '1231181189',
    'amount' => '100',
])

$id = $client->createPaymentRequest($pr);

var_dump($id);

//
//  string(32) "0D3AD8F1AE484A57B82A87FAB8C602EB"
//

Notes for OSX

The bundled PHP in OSX 10.12 and earlier is not compatible with the above approach of forwarding SSL certificates. You must obtain a PHP-version that is compiled with cURL linked against OpenSSL or similar., (*8)

Run the tests

To run the tests you need certificates for the Swish test server. Place the root certificate in tests/_data/root.pem and the client certificate in tests/_data/client.pem., (*9)

docker-compose run --rm swish ./extract.sh bundle.p12 swish swish

Place the generated certs in tests/_data and run the tests., (*10)

docker-compose run --rm swish composer install
docker-compose run --rm swish phpunit

The Versions

28/06 2018

dev-master

9999999-dev

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk
by Fredrik Andersson

28/06 2018

1.1.1

1.1.1.0

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk
by Fredrik Andersson

27/06 2018

dev-upstream

dev-upstream

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk

27/06 2018

1.1.0

1.1.0.0

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk

22/03 2018

1.0.2

1.0.2.0

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk

28/02 2017

1.0.1

1.0.1.0

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk

18/02 2017

1.0.0

1.0.0.0

PHP-wrapper for the Swish api

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan Björk