coretrekstein/vippsomnipay

Vipps driver for the Omnipay payment processing library

dev-main 2021-04-09 12:46 UTC

This package is auto-updated.

Last update: 2024-04-09 20:02:47 UTC


README

Packagist GitHub

Install

composer require coretrekstein/vippsomnipay

Simple html form for mobile number and amount

<form method="get">
    <input type="hidden" name="action" value="purchase">

    <label>Telefonnummer</label>
    <input type="tel" name="phone" value="91236172"><br>

    <label>Beløp (i ører)</label>
    <input type="number" name="amount"><br>

    <button>Betal med Vipps</button>
</form>

Initialize gateway, authorize, purchase and redirect to Vipps

use CoreTrekStein\VippsOmnipay;

$gateway = new VippsOmnipay\Gateway();

$gateway->initialize(array(
    'baseUrl'              => '',
    'clientId'             => '',
    'clientSecret'         => '',
    'ocpSubscription'      => '',
    'merchantSerialNumber' => ''
));

$gateway->authorize());

$card = new CreditCard(array(
    'number' => $_GET['phone']
));

$transaction = $gateway->purchase(array(
    'amount'   => $_GET['amount'],
    'currency' => 'NOK',
    'card'     => $card,
));
$response = $transaction->send();

header("Location: " . $response->getData()['url']);

Vipps sends a post request to website

$params = array(
    'access_token'         => $_GET['access_token'],
    'order_id'             => $_GET['order_id'],
    'transactionReference' => $_GET['order_id']
);

$response = $gateway->capture($params)->send();

echo json_encode(array());

Validate the payment

$response = $gateway->completePurchase()->send();