netbums/laravel-quickpay

A fluent api around the quickpay api for Laravel applications

0.1.3-alpha 2024-01-12 09:17 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This laravel package will help you utilize the Quickpay API Client, without knowing too much about the endpoints. It provides a fluent api for using the API. See examples below.

Support me

Consider supporting me by sponsoring my work

Installation

  1. You can install the package via composer:
composer require netbums/laravel-quickpay
  1. Publish the config file with:
php artisan vendor:publish --tag="laravel-quickpay-config"

This is the contents of the published config file:

// config/quickpay.php
return [
    'api_key' => env('QUICKPAY_API_KEY'),
    'login' => env('QUICKPAY_LOGIN'),
    'password' => env('QUICKPAY_PASSWORD'),
    'merchant_id' => env('QUICKPAY_MERCHANT_ID'),
];
  1. Add the environment variables to your .env file:
QUICKPAY_API_KEY=
QUICKPAY_LOGIN=
QUICKPAY_PASSWORD=
QUICKPAY_MERCHANT_ID=

Usage

The following examples uses this:

use \Netbums\Quickpay\Quickpay;

Payments

Get all payments

$payments = Quickpay::api()->payments()->all();

Get a payment

Getting a single payment by id

$payment = Quickpay::api()->payments()->find($paymentId);

Create a payment

// First create a basket with items
$basket = new \Netbums\Quickpay\DataObjects\Basket(
    items: [
        new \Netbums\Quickpay\DataObjects\BasketItem(
            qty: 1,
            item_name: 'Test item',
            item_no: 'sku-1234',
            item_price: 100, // in smallest currency unit
            vat_rate: 0.25, // 25%
        )
    ]
)

// Then create a payment with the basket, and a unique order id
$paymentData = new \Netbums\Quickpay\DataObjects\Payment(
    currency: 'DKK',
    order_id: '1234',
    basket:  $basket,
)

// Then create the payment
$createdPayment = \Netbums\Quickpay\Quickpay::api()->payments()->create(
    payment: $paymentData
)

After a payment is created you can create a payment link for it, and redirect the user to the payment link.

Create a payment link

$paymentLinkData = new \Netbums\Quickpay\DataObjects\PaymentLink(
    id: 437296737, 
    amount: 100
);

$paymentLink = \Netbums\Quickpay\Quickpay::api()->payments()->createLink($paymentLinkData);

This will return a URL, that you can redirect the user to.

Update a payment


Capture a payment

Capture a payment. This will capture the amount of the payment specified.

$payment = Quickpay::api()->payments()->capture(
    id: $paymentId,
    amount: 100, // in smallest currency unit
);

Refund a payment

Refund a payment. This will refund the amount of the payment specified.

$payment = Quickpay::api()->payments()->refund(
    id: $paymentId,
    amount: 100, // in smallest currency unit
);

Authorize a payment

Authorize a payment. This will reserve the amount on the card, but not capture it.

$payment = Quickpay::api()->payments()->authorize(
    id: $paymentId,
    amount: 100, // in smallest currency unit
);

Renew authorization of a payment

Renew the authorization of a payment. This will reserve the amount on the card, but not capture it.

$payment = Quickpay::api()->payments()->renew(
    id: $paymentId,
);

Cancel a payment

Cancel a payment. This will cancel the payment, and release the reserved amount on the card.

$payment = Quickpay::api()->payments()->cancel(
    id: $paymentId,
);

Create a payment link

Create a payment link for a payment. Optional parameters are: language, continue_url, cancel_url, callback_url:

$paymentLinkData = new \Netbums\Quickpay\DataObjects\PaymentLink(
    id: $paymentId,
    amount: 100, // in smallest currency unit
    language: 'da',
    continue_url: 'https://example.com/continue',
    cancel_url: 'https://example.com/cancel',
    callback_url: 'https://example.com/callback',
);

$paymentLink = Quickpay::api()->payments()->createPaymentLink(
    paymentLink: $paymentLinkData,
);

Create a payment session

$session = Quickpay::api()->payments()->session(
    id: $paymentId,
    amount: 100, // in smallest currency unit
);

Create Fraud Report

Create a fraud report for a payment. Optional parameters are: description:

$fraudReport = new \Netbums\Quickpay\Quickpay()->payments()->createFraudReport(
    id: $paymentId,
    description: 'Fraudulent payment',
);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.