Skip to content

Commit bad12a4

Browse files
committed
Initial commit
0 parents  commit bad12a4

File tree

13 files changed

+760
-0
lines changed

13 files changed

+760
-0
lines changed

.github/workflows/main.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Build tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
phpunit:
11+
name: "PHPUnit tests"
12+
13+
runs-on: "ubuntu-latest"
14+
15+
strategy:
16+
matrix:
17+
dependencies:
18+
- "highest"
19+
php-version:
20+
- "7.2"
21+
- "7.3"
22+
- "7.4"
23+
- "8.0"
24+
- "8.1"
25+
- "8.2"
26+
- "8.3"
27+
- "8.4"
28+
29+
include:
30+
- php-version: '7.2'
31+
dependencies: "lowest"
32+
33+
steps:
34+
- name: "Checkout"
35+
uses: "actions/checkout@v4"
36+
37+
- name: "Install PHP"
38+
uses: "shivammathur/setup-php@v2"
39+
with:
40+
coverage: "pcov"
41+
php-version: "${{ matrix.php-version }}"
42+
ini-values: memory_limit=-1
43+
tools: composer:v2
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
# Fixes any pubkeys failure (add a `composer diagnose` step to debug if necessary)
48+
- name: "Composer force self-update"
49+
run: "composer self-update"
50+
51+
- name: "Install lowest dependencies"
52+
if: ${{ matrix.dependencies == 'lowest' }}
53+
run: "composer update --prefer-lowest --no-interaction --no-progress"
54+
55+
- name: "Install highest dependencies"
56+
if: ${{ matrix.dependencies == 'highest' }}
57+
run: "composer update --no-interaction --no-progress"
58+
59+
- name: "Tests (PHPUnit 9)"
60+
if: ${{ matrix.php-version <= '8.0' }}
61+
run: "vendor/bin/phpunit --configuration phpunit9.xml.dist"
62+
63+
- name: "Tests (PHPUnit 10+)"
64+
if: ${{ matrix.php-version >= '8.1' }}
65+
run: "vendor/bin/phpunit"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
composer.lock
3+
composer.phar
4+
phpunit.xml
5+
/.phpunit.result.cache
6+
/build

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing Guidelines
2+
3+
* Fork the project.
4+
* Make your feature addition or bug fix.
5+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
6+
* Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files.
7+
* Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
8+
style and that all tests pass.
9+
* Send the pull request.
10+
* Check that the CI build passed. If not, rinse and repeat.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2025 Leith Caldwell
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Omnipay: Worldline
2+
3+
**Worldline driver for the Omnipay PHP payment processing library**
4+
5+
![Build Status](https://github.com/PatronBase/omnipay-worldline/actions/workflows/main.yml/badge.svg?branch=main)
6+
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/PatronBase/omnipay-worldline.svg?style=flat)](https://scrutinizer-ci.com/g/PatronBase/omnipay-worldline/code-structure)
7+
[![Code Quality](https://img.shields.io/scrutinizer/g/PatronBase/omnipay-worldline.svg?style=flat)](https://scrutinizer-ci.com/g/PatronBase/omnipay-worldline/?branch=main)
8+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
9+
[![Latest Stable Version](https://poser.pugx.org/PatronBase/omnipay-worldline/version.png)](https://packagist.org/packages/patronbase/omnipay-worldline)
10+
[![Total Downloads](https://poser.pugx.org/patronbase/omnipay-worldline/d/total.png)](https://packagist.org/packages/patronbase/omnipay-worldline)
11+
12+
13+
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
14+
processing library for PHP 7.2+. This package implements Worldline support for Omnipay. It includes
15+
support for the hosted checkout (redirect, 3-party) version of the gateway via v2 of their API.
16+
17+
## Installation
18+
19+
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
20+
to your `composer.json` file:
21+
22+
```json
23+
{
24+
"require": {
25+
"PatronBase/omnipay-worldline": "~3.0"
26+
}
27+
}
28+
```
29+
30+
And run composer to update your dependencies:
31+
32+
$ curl -s http://getcomposer.org/installer | php
33+
$ php composer.phar update
34+
35+
## Basic Usage
36+
37+
The following gateways are provided by this package:
38+
39+
* Worldline
40+
41+
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
42+
repository.
43+
44+
## Support
45+
46+
If you are having general issues with Omnipay, we suggest posting on
47+
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
48+
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
49+
50+
If you want to keep up to date with release anouncements, discuss ideas for the project,
51+
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
52+
you can subscribe to.
53+
54+
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/PatronBase/omnipay-worldline/issues),
55+
or better yet, fork the library and submit a pull request.

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "patronbase/omnipay-worldline",
3+
"type": "library",
4+
"description": "Worldline driver for the Omnipay payment processing library",
5+
"keywords": [
6+
"gateway",
7+
"merchant",
8+
"omnipay",
9+
"pay",
10+
"payment",
11+
"worldline",
12+
"hosted",
13+
"checkout",
14+
"redirect"
15+
],
16+
"homepage": "https://github.com/PatronBase/omnipay-worldline",
17+
"license": "MIT",
18+
"authors": [
19+
{
20+
"name": "Leith Caldwell",
21+
"email": "[email protected]"
22+
}
23+
],
24+
"autoload": {
25+
"psr-4": { "Omnipay\\Worldline\\" : "src/" }
26+
},
27+
"autoload-dev": {
28+
"psr-4": { "Omnipay\\Worldline\\" : "tests/" }
29+
},
30+
"require": {
31+
"php": "^7.2|^8.0",
32+
"omnipay/common": "^3.1"
33+
},
34+
"require-dev": {
35+
"omnipay/tests": "^4.1",
36+
"squizlabs/php_codesniffer": "^3.5",
37+
"http-interop/http-factory-guzzle": "^1.1"
38+
},
39+
"scripts": {
40+
"test": "phpunit",
41+
"check-style": "phpcs -p --standard=PSR2 src/",
42+
"fix-style": "phpcbf -p --standard=PSR2 src/"
43+
},
44+
"extra": {
45+
"branch-alias": {
46+
"dev-main": "3.0.x-dev"
47+
}
48+
},
49+
"prefer-stable": true,
50+
"config": {
51+
"allow-plugins": {
52+
"php-http/discovery": true
53+
}
54+
}
55+
}

phpunit.xml.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
backupGlobals="false"
6+
backupStaticProperties="false"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="false">
10+
<coverage>
11+
<report>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
<html outputDirectory="build/coverage"/>
14+
<text outputFile="build/coverage.txt"/>
15+
</report>
16+
</coverage>
17+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
18+
<include>
19+
<directory suffix=".php">src/</directory>
20+
</include>
21+
</source>
22+
<testsuites>
23+
<testsuite name="Omnipay Test Suite">
24+
<directory>tests</directory>
25+
</testsuite>
26+
</testsuites>
27+
<logging>
28+
<junit outputFile="build/report.junit.xml"/>
29+
</logging>
30+
</phpunit>

phpunit9.xml.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
colors="true"
8+
verbose="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false">
14+
<coverage>
15+
<include>
16+
<directory suffix=".php">src/</directory>
17+
</include>
18+
<report>
19+
<clover outputFile="build/logs/clover.xml"/>
20+
<html outputDirectory="build/coverage"/>
21+
<text outputFile="build/coverage.txt"/>
22+
</report>
23+
</coverage>
24+
<testsuites>
25+
<testsuite name="Omnipay Test Suite">
26+
<directory>tests</directory>
27+
</testsuite>
28+
</testsuites>
29+
<logging>
30+
<junit outputFile="build/report.junit.xml"/>
31+
</logging>
32+
</phpunit>

src/Gateway.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Omnipay\Worldline;
4+
5+
use Omnipay\Common\AbstractGateway;
6+
use Omnipay\Worldline\Message\CompletePurchaseRequest;
7+
use Omnipay\Worldline\Message\PurchaseRequest;
8+
9+
/**
10+
* Worldline Hosted Checkout Gateway
11+
*
12+
* @link http://www..worldline-solutions.com/
13+
*
14+
* @see https://docs.direct.worldline-solutions.com/en/api-reference#tag/HostedCheckout
15+
*/
16+
class Gateway extends AbstractGateway
17+
{
18+
public function getName()
19+
{
20+
return 'Worldline';
21+
}
22+
23+
public function getDefaultParameters()
24+
{
25+
return array(
26+
'apiKey' => '',
27+
'apiSecret' => '',
28+
'merchantId' => '',
29+
'testMode' => false,
30+
);
31+
}
32+
33+
public function getApiKey()
34+
{
35+
return $this->getParameter('apiKey');
36+
}
37+
38+
public function setApiKey($value)
39+
{
40+
return $this->setParameter('apiKey', $value);
41+
}
42+
43+
public function getApiSecret()
44+
{
45+
return $this->getParameter('apiSecret');
46+
}
47+
48+
public function setApiSecret($value)
49+
{
50+
return $this->setParameter('apiSecret', $value);
51+
}
52+
53+
public function getMerchantId()
54+
{
55+
return $this->getParameter('merchantId');
56+
}
57+
58+
public function setMerchantId($value)
59+
{
60+
return $this->setParameter('merchantId', $value);
61+
}
62+
63+
public function purchase(array $parameters = [])
64+
{
65+
return $this->createRequest(PurchaseRequest::class, $parameters);
66+
}
67+
68+
public function completePurchase(array $parameters = [])
69+
{
70+
return $this->createRequest(CompletePurchaseRequest::class, $parameters);
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Omnipay\Worldline\Message;
4+
5+
/**
6+
* Worldline Complete Purchase Request
7+
*
8+
* @see https://docs.direct.worldline-solutions.com/en/api-reference#tag/HostedCheckout/operation/GetHostedCheckoutApi
9+
*/
10+
class CompletePurchaseRequest extends PurchaseRequest
11+
{
12+
public function getHostedCheckoutId()
13+
{
14+
return $this->getParameter('hostedCheckoutId');
15+
}
16+
17+
public function setHostedCheckoutId($value)
18+
{
19+
return $this->setParameter('hostedCheckoutId', $value);
20+
}
21+
22+
public function getData()
23+
{
24+
return $this->httpRequest->request->all();
25+
}
26+
27+
protected function createResponse($data)
28+
{
29+
return $this->response = new CompletePurchaseResponse($this, json_decode($data));
30+
}
31+
32+
protected function getAction()
33+
{
34+
return '/v2/'.$this->getMerchantId().'/hostedcheckouts/'.$this->getHostedCheckoutId();
35+
}
36+
37+
protected function getRequestMethod()
38+
{
39+
return 'GET';
40+
}
41+
}

0 commit comments

Comments
 (0)