Skip to content

Documentation 1.x

Jakub Piasecki edited this page Dec 6, 2017 · 3 revisions

Basic usage (configuration)

You must pass client_id obtained from Vipps Developer Portal in order to make requests to Vipps API.

// Create Vipps client;
$client = new \zaporylie\Vipps\Client('xxxx');
// Initiate Vipps App with a previously initiatet client;
$app = new \zaporylie\Vipps\Vipps($client);

Http client will be determined automatically, but if your application uses more than one client and you want to choose which one will be used for Vipps calls you can pass instantiated adaptor object to \zaporylie\Vipps\Client constructor.

// Initiate guzzle client in debug mode.
$httpClient = new Http\Adapter\Guzzle6\Client(new GuzzleHttp\Client(['debug' => TRUE]));
// Create Vipps client;
$client = new \zaporylie\Vipps\Client('xxxxxxxxxxxxxxxxxxxxxxxx', [
    'http_client' => $httpClient,
]);
// Initiate Vipps App with a previously initiatet client;
$app = new \zaporylie\Vipps\Vipps($client);

In following examples $app is an instance of \zaporylie\Vipps\Vipps.

Authorization

$auth = $app->authorization('<access_subscription_key>');
$auth->getToken('<client_secret>');

By default Token will be stored in-memory storage. You can modify default behaviour by providing custom TokenStorage which implements TokenStorageInterface to \zaporylie\Vipps\Client().

Initiate Payment

// Get payment API - pass product's subcription key obtainted from Developer Portal.
// @see \zaporylie\Vipps\Vipps::payment()
$payment = $app->payment('<subscription_key>', '<merchant_serial_number>');
// Initiate new payment.
// @see \zaporylie\Vipps\Api\Payment::initiatePayment()
$payment_details = $payment->initiatePayment('<unique-order-id>', '<vipps-user-mobile-phone-number>', '<amount-in-ore>', '<payment-description>', '<callback-url>');

::initiatePayment() method takes parameters:

  • unique order id
  • user's mobile phone number
  • transaction amount in ore
  • payment description
  • callback url - to this URL Vipps will push information about finalized or canceled payment
  • Ref. Order ID (optional)

If everything goes smooth, ::initiatePayment() method returns an instance of \zaporylie\Vipps\Model\Payment\ResponseInitiatePayment method.

If API throws an error, \zaporylie\Vipps\Exceptions\VippsException is thrown.

Get payment details

// Get payment API.
$payment = $app->payment('<subscription_key>', '<merchant_serial_number>');
// Get order status (basic informations about payment).
$status = $payment->getStatus('<order_id>');
// Get transaction details including capture/refund history.
$details = $payment->getDetails('<order_id>');

Using production server

By default all requests are made against Vipps Test Environment. If you want to use production environment you must pass endpoint option to Vipps client.

$client = new \zaporylie\Vipps\Client('xxxxxxxxxxxxxxxxxxxxxxxx', [
    'endpoint' => 'live',
]);