Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #42 from heidelpay/develop
Browse files Browse the repository at this point in the history
Release fixes and changes
  • Loading branch information
Simon Gabriel authored Jan 2, 2019
2 parents 3e64f67 + d509799 commit dbabd9b
Show file tree
Hide file tree
Showing 29 changed files with 277 additions and 91 deletions.
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.0.1][1.0.0.1]

### Fixed
* Fixed a bug which resulted in an error on getOrderId when the order id has not been set.
* Fixed namespace configuration in composer.json.
* Fixed a bug which resulted in metadata not being referenced by charge transactions.

### Changed
* Set error code to string in HeidelpayApiException by default.
* Disabled pretty print of json string in response.
* Re-enabled skipped test.

### Added
* Examples: Added shortId of the transaction to the success and failure pages.
* Examples: Added an example debug handler.
* Readme: Added list of supported payment types.
* Added missing ApiResponseCodes.
* Added additional getter to fetch the merchant message from a HeidelpayApiException.
* Extended integration tests to test with matching addresses and with unmatching addresses.
* Added additional badges to readme file.

## [1.0.0.0][1.0.0.0]

### Fix
### Fixed
* Fixed license information.
* Fixed package information.
* Fixed return values for several getters.
Expand Down Expand Up @@ -39,7 +60,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [1.0.0-beta.2][1.0.0-beta.2]

### Fix
### Fixed
* Fix result urls.
* Fix PhpDoc.

Expand All @@ -51,3 +72,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
[1.0.0-beta.1]: https://github.com/heidelpay/heidelpayPHP/tree/1.0.0-beta.1
[1.0.0-beta.2]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.0-beta.1..1.0.0-beta.2
[1.0.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.0-beta.2..1.0.0.0
[1.0.0.1]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.0.0..1.0.0.1
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/heidelpay/heidelpay-php.svg?style=flat-square)](https://packagist.org/packages/heidelpay/heidelpay-php)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a5fceb1b4f674fb49db39929559f3959)](https://www.codacy.com/app/heidelpay/heidelpayPHP?utm_source=github.com&utm_medium=referral&utm_content=heidelpay/heidelpayPHP&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/a5fceb1b4f674fb49db39929559f3959)](https://www.codacy.com/app/heidelpay/heidelpayPHP?utm_source=github.com&utm_medium=referral&utm_content=heidelpay/heidelpayPHP&utm_campaign=Badge_Coverage)
[![PHP 7.0](https://img.shields.io/badge/php-7.0-blue.svg)](http://www.php.net)
[![PHP 7.1](https://img.shields.io/badge/php-7.1-blue.svg)](http://www.php.net)
[![PHP 7.2](https://img.shields.io/badge/php-7.2-blue.svg)](http://www.php.net)

![Logo](https://dev.heidelpay.com/devHeidelpay_400_180.jpg)

Expand All @@ -13,6 +17,17 @@ Please refer to the following documentation for installation instructions and us
* [How to use the examples](https://docs.heidelpay.com/v1.0/docs/php-sdk#section-using-the-example-implementations)
* [Debugging](https://docs.heidelpay.com/v1.0/docs/php-sdk#section-debugging)

## Supported payment types
* Card (credit card and debit card)
* Giropay
* iDEAL
* Invoice (guaranteed)
* PayPal
* Prepayment
* Przelewy24
* SEPA direct debit (guaranteed)
* SOFORT

## Support
For any issues or questions please get in touch with our support.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"autoload": {
"psr-4": {
"heidelpayPHP\\": "src"
"heidelpayPHP\\": "src",
"heidelpayPHP\\examples\\": "examples"
}
},
"autoload-dev": {
Expand Down
7 changes: 5 additions & 2 deletions examples/CreditCard3DAuthorization/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Customer;
Expand All @@ -52,11 +53,13 @@ function redirect($url)
try {
//####### 2. Create a heidelpay object using your private key #####################################################
$heidelpay = new Heidelpay('s-priv-2a10BF2Cq2YvAo6ALSGHc3X7F42oWAIp');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

//####### 3. Create an authorization (aka reservation) ############################################################
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer);
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer);
$_SESSION['PaymentId'] = $authorization->getPaymentId();
$_SESSION['ShortId'] = $authorization->getShortId();
redirect($authorization->getRedirectUrl());
} catch (HeidelpayApiException $e) {
redirect(FAILURE_URL);
Expand Down
3 changes: 3 additions & 0 deletions examples/CreditCard3DAuthorization/ReturnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;

Expand All @@ -47,6 +48,8 @@ function redirect($url)
$paymentId = $_SESSION['PaymentId'];
try {
$heidelpay = new Heidelpay('s-priv-2a10BF2Cq2YvAo6ALSGHc3X7F42oWAIp');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

$payment = $heidelpay->fetchPayment($paymentId);
if ($payment->isPending()) {
redirect(SUCCESS_URL);
Expand Down
11 changes: 7 additions & 4 deletions examples/CreditCard3DCharge/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Customer;
Expand All @@ -52,12 +53,14 @@ function redirect($url)
try {
//####### 2. Create a heidelpay object using your private key #####################################################
$heidelpay = new Heidelpay('s-priv-2a10BF2Cq2YvAo6ALSGHc3X7F42oWAIp');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

//####### 3. Create an authorization (aka reservation) ############################################################
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer);
$_SESSION['PaymentId'] = $authorization->getPaymentId();
redirect($authorization->getRedirectUrl());
$customer = new Customer('Linda', 'Heideich');
$charge = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer);
$_SESSION['PaymentId'] = $charge->getPaymentId();
$_SESSION['ShortId'] = $charge->getShortId();
redirect($charge->getRedirectUrl());
} catch (HeidelpayApiException $e) {
redirect(FAILURE_URL);
}
Expand Down
3 changes: 3 additions & 0 deletions examples/CreditCard3DCharge/ReturnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;

Expand All @@ -47,6 +48,8 @@ function redirect($url)
$paymentId = $_SESSION['PaymentId'];
try {
$heidelpay = new Heidelpay('s-priv-2a10BF2Cq2YvAo6ALSGHc3X7F42oWAIp');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

$payment = $heidelpay->fetchPayment($paymentId);
if ($payment->isCompleted()) {
redirect(SUCCESS_URL);
Expand Down
7 changes: 5 additions & 2 deletions examples/CreditCardAuthorization/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Customer;
Expand All @@ -52,10 +53,12 @@ function redirect($url)
try {
//####### 2. Create a heidelpay object using your private key #####################################################
$heidelpay = new Heidelpay('s-priv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

//####### 3. Create an authorization (aka reservation) ############################################################
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->authorize(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customer);
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->authorize(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customer);
$_SESSION['ShortId'] = $authorization->getShortId();
if ($authorization->getPayment()->isPending()) {
redirect(SUCCESS_URL);
}
Expand Down
9 changes: 6 additions & 3 deletions examples/CreditCardCharge/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use heidelpayPHP\examples\ExampleDebugHandler;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Customer;
Expand All @@ -52,11 +53,13 @@ function redirect($url)
try {
//####### 2. Create a heidelpay object using your private key #####################################################
$heidelpay = new Heidelpay('s-priv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n');
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

//####### 3. Create an authorization (aka reservation) ############################################################
$customer = new Customer('Linda', 'Heideich');
$authorization = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customer);
if ($authorization->getPayment()->isCompleted()) {
$customer = new Customer('Linda', 'Heideich');
$charge = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customer);
$_SESSION['ShortId'] = $charge->getShortId();
if ($charge->getPayment()->isCompleted()) {
redirect(SUCCESS_URL);
}
} catch (HeidelpayApiException $e) {
Expand Down
39 changes: 39 additions & 0 deletions examples/ExampleDebugHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* This custom debug handler will echo out debug messages.
*
* Copyright (C) 2018 heidelpay GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://dev.heidelpay.com/
*
* @author Simon Gabriel <[email protected]>
*
* @package heidelpayPHP/test/integration
*/
namespace heidelpayPHP\examples;

use heidelpayPHP\Interfaces\DebugHandlerInterface;

class ExampleDebugHandler implements DebugHandlerInterface
{
/**
* {@inheritDoc}
*/
public function log(string $message)
{
// ATTENTION: Uncomment following line to write debug messages to the error log of your web server.
//error_log($message);
}
}
11 changes: 10 additions & 1 deletion examples/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
*
* @package heidelpayPHP/examples
*/

session_start();
?>

<!DOCTYPE html>
<html>
<body>
<h1>Failure</h1>
<p>There has been an error completing the payment.</p>
<p>
There has been an error completing the payment.
<?php
if (isset($_SESSION['ShortId']) && !empty($_SESSION['ShortId'])) {
echo '<br>Please look for ShortId ' . $_SESSION['ShortId'] . ' in hIP to see the transaction.';
}
?>
</p>
<p><a href=".">start again</a></p>
</body>
</html>
11 changes: 10 additions & 1 deletion examples/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
*
* @package heidelpayPHP/examples
*/

session_start();
?>

<!DOCTYPE html>
<html>
<body>
<h1>Success</h1>
<p>The payment has been successfully completed.</p>
<p>
The payment has been successfully completed.
<?php
if (isset($_SESSION['ShortId']) && !empty($_SESSION['ShortId'])) {
echo '<br>Please look for ShortId ' . $_SESSION['ShortId'] . ' in hIP to see the transaction.';
}
?>
</p>
<p><a href=".">start again</a></p>
</body>
</html>
2 changes: 2 additions & 0 deletions src/Constants/ApiResponseCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ApiResponseCodes
const API_ERROR_CUSTOMER_ID_REQUIRED = 'API.320.100.008';
const API_ERROR_RESOURCE_DOES_NOT_BELONG_TO_MERCHANT = 'API.320.200.145';
const API_ERROR_CHARGED_AMOUNT_HIGHER_THAN_EXPECTED = 'API.330.100.007';
const API_ERROR_IVG_ADDRESSES_DO_NOT_MATCH = 'API.320.100.106';
const API_ERROR_DDG_ADDRESSES_DO_NOT_MATCH = 'API.330.100.106';
const API_ERROR_CURRENCY_IS_NOT_SUPPORTED = 'API.330.100.202';
const API_ERROR_AUTHORIZE_ALREADY_CANCELLED = 'API.340.100.014';
const API_ERROR_CHARGE_ALREADY_CHARGED_BACK = 'API.340.100.015';
Expand Down
10 changes: 9 additions & 1 deletion src/Exceptions/HeidelpayApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HeidelpayApiException extends \Exception
* @param string $clientMessage
* @param string $code
*/
public function __construct($merchantMessage = '', $clientMessage = '', $code = '')
public function __construct($merchantMessage = '', $clientMessage = '', $code = 'No error code provided')
{
$merchantMessage = empty($merchantMessage) ? static::MESSAGE : $merchantMessage;
$this->clientMessage = empty($clientMessage) ? static::CLIENT_MESSAGE : $clientMessage;
Expand All @@ -54,4 +54,12 @@ public function getClientMessage(): string
{
return $this->clientMessage;
}

/**
* @return string
*/
public function getMerchantMessage(): string
{
return $this->getMessage();
}
}
2 changes: 1 addition & 1 deletion src/Heidelpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Heidelpay implements HeidelpayParentInterface
const BASE_URL = 'https://api.heidelpay.com/';
const API_VERSION = 'v1';
const SDK_TYPE = 'HeidelpayPHP';
const SDK_VERSION = '1.0.0.0';
const SDK_VERSION = '1.0.0.1';

/** @var string $key */
private $key;
Expand Down
22 changes: 22 additions & 0 deletions src/Resources/TransactionTypes/AbstractTransactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Resources\AbstractHeidelpayResource;
use heidelpayPHP\Resources\Payment;
use heidelpayPHP\Resources\PaymentTypes\BasePaymentType;
use heidelpayPHP\Traits\HasOrderId;

abstract class AbstractTransactionType extends AbstractHeidelpayResource
Expand Down Expand Up @@ -190,6 +191,27 @@ public function handleResponse(\stdClass $response, $method = HttpAdapterInterfa
}
}

/**
* {@inheritDoc}
*
* @throws \RuntimeException
*/
public function getLinkedResources(): array
{
/** @var Payment $payment */
$payment = $this->getPayment();
$paymentType = $payment ? $payment->getPaymentType() : null;
if (!$paymentType instanceof BasePaymentType) {
throw new \RuntimeException('Payment type is missing!');
}

return [
'customer'=> $payment->getCustomer(),
'type' => $paymentType,
'metadata' => $payment->getMetadata()
];
}

//</editor-fold>

/**
Expand Down
Loading

0 comments on commit dbabd9b

Please sign in to comment.