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 #48 from heidelpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
devheidelpay authored Jan 31, 2019
2 parents ae219cd + 8310719 commit a182efa
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 42 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ 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.2.0][1.0.2.0]

### Added
* Made status information available in transactions (isSuccess, isError, isPending).

### Fixed
* Http-Request: Remove payload from DELETE call.
* DebugLog: Remove payload output from GET and DELETE calls.

### Changed
* Several code style issues.

## [1.0.1.0][1.0.1.0]

### Added
Expand Down Expand Up @@ -89,3 +101,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
[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
[1.0.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.0.1..1.0.1.0
[1.0.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.1.0..1.0.2.0
2 changes: 1 addition & 1 deletion src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function init($url, $payload = null, $httpMethod = HttpAdapterInterface::
$this->setOption(CURLOPT_SSL_VERIFYHOST, 2);
$this->setOption(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2

if (HttpAdapterInterface::REQUEST_GET !== $httpMethod) {
if (in_array($httpMethod, [HttpAdapterInterface::REQUEST_POST, HttpAdapterInterface::REQUEST_PUT], true)) {
$this->setOption(CURLOPT_POSTFIELDS, $payload);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Heidelpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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.1.0';
const SDK_VERSION = '1.0.2.0';

/** @var string $key */
private $key;
Expand Down
16 changes: 8 additions & 8 deletions src/Resources/AbstractHeidelpayResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function updateValues($object, \stdClass $response)
{
foreach ($response as $key => $value) {
$newValue = $value;
if (!\is_string($value) || $value === '') {
if ($value !== false && (!\is_string($value) || $value === '')) {
$newValue = $value ?: null;
}

Expand Down Expand Up @@ -301,14 +301,14 @@ public function expose()

if ($value === null) {
unset($properties[$property]);
} else {
if ($value instanceof self) {
$newValue = $value->expose();
} else {
$newValue = $value;
}
$properties[$property] = $newValue;
continue;
}

$newValue = $value;
if ($value instanceof self) {
$newValue = $value->expose();
}
$properties[$property] = $newValue;
} catch (\ReflectionException $e) {
unset($properties[$property]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getMetadata($name)
return $this->metadata[$name] ?? null;
}

//</editor-fold>
//</editor-fold>>

//<editor-fold desc="Overridable Methods">

Expand Down
42 changes: 17 additions & 25 deletions src/Resources/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ class Payment extends AbstractHeidelpayResource
use HasPaymentState;
use HasOrderId;

/**
* @param null $parent
*/
public function __construct($parent = null)
{
$this->amount = new Amount();
$this->metadata = new Metadata();

parent::__construct($parent);
}

//<editor-fold desc="Properties">
/** @var string $redirectUrl */
private $redirectUrl;

Expand All @@ -82,7 +70,17 @@ public function __construct($parent = null)

/** @var Basket $basket */
private $basket;
//</editor-fold>

/**
* @param null $parent
*/
public function __construct($parent = null)
{
$this->amount = new Amount();
$this->metadata = new Metadata();

parent::__construct($parent);
}

//<editor-fold desc="Setters/Getters">

Expand Down Expand Up @@ -750,22 +748,16 @@ private function updateResponseResources($resources)
}
}

if (isset($resources->typeId) && !empty($resources->typeId)) {
if (!$this->paymentType instanceof BasePaymentType) {
$this->paymentType = $this->getHeidelpayObject()->fetchPaymentType($resources->typeId);
}
if (isset($resources->typeId) && !empty($resources->typeId) && !$this->paymentType instanceof BasePaymentType) {
$this->paymentType = $this->getHeidelpayObject()->fetchPaymentType($resources->typeId);
}

if (isset($resources->metadataId) && !empty($resources->metadataId)) {
if ($this->metadata->getId() === null) {
$this->metadata = $this->getHeidelpayObject()->fetchMetadata($resources->metadataId);
}
if (isset($resources->metadataId) && !empty($resources->metadataId) && $this->metadata->getId() === null) {
$this->metadata = $this->getHeidelpayObject()->fetchMetadata($resources->metadataId);
}

if (isset($resources->basketId) && !empty($resources->basketId)) {
if (!$this->basket instanceof Basket) {
$this->basket = $this->getHeidelpayObject()->fetchBasket($resources->basketId);
}
if (isset($resources->basketId) && !empty($resources->basketId) && !$this->basket instanceof Basket) {
$this->basket = $this->getHeidelpayObject()->fetchBasket($resources->basketId);
}
}

Expand Down
66 changes: 66 additions & 0 deletions src/Resources/TransactionTypes/AbstractTransactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ abstract class AbstractTransactionType extends AbstractHeidelpayResource
/** @var string $shortId */
private $shortId;

/** @var bool $isError */
private $isError = false;

/** @var bool $isSuccess */
private $isSuccess = false;

/** @var bool $isPending */
private $isPending = false;

//</editor-fold>

//<editor-fold desc="Getters/Setters">
Expand Down Expand Up @@ -162,6 +171,63 @@ protected function setShortId(string $shortId): AbstractTransactionType
return $this;
}

/**
* @return bool
*/
public function isError(): bool
{
return $this->isError;
}

/**
* @param bool $isError
*
* @return AbstractTransactionType
*/
public function setIsError(bool $isError): AbstractTransactionType
{
$this->isError = $isError;
return $this;
}

/**
* @return bool
*/
public function isSuccess(): bool
{
return $this->isSuccess;
}

/**
* @param bool $isSuccess
*
* @return AbstractTransactionType
*/
public function setIsSuccess(bool $isSuccess): AbstractTransactionType
{
$this->isSuccess = $isSuccess;
return $this;
}

/**
* @return bool
*/
public function isPending(): bool
{
return $this->isPending;
}

/**
* @param bool $isPending
*
* @return AbstractTransactionType
*/
public function setIsPending(bool $isPending): AbstractTransactionType
{
$this->isPending = $isPending;
return $this;
}

//</editor-fold>

//<editor-fold desc="Overridable methods">
Expand Down
9 changes: 7 additions & 2 deletions src/Services/HttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,14 @@ public function debugLog(AbstractHeidelpayResource $resource, $httpMethod, strin
if ($heidelpayObj->isDebugMode()) {
$debugHandler = $heidelpayObj->getDebugHandler();
if ($debugHandler instanceof DebugHandlerInterface) {
$resourceJson = $resource->jsonSerialize();
$debugHandler->log($httpMethod . ': ' . $url);
$debugHandler->log('Request: ' . $resourceJson);
if (in_array(
$httpMethod,
[HttpAdapterInterface::REQUEST_POST, HttpAdapterInterface::REQUEST_PUT],
true
)) {
$debugHandler->log('Request: ' . $resource->jsonSerialize());
}
$debugHandler->log('Response: ' . json_encode(json_decode($response)));
}
}
Expand Down
40 changes: 40 additions & 0 deletions test/integration/AuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
namespace heidelpayPHP\test\integration;

use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Resources\AbstractHeidelpayResource;
use heidelpayPHP\Resources\PaymentTypes\BasePaymentType;
use heidelpayPHP\Resources\PaymentTypes\Paypal;
use heidelpayPHP\Resources\TransactionTypes\Authorization;
use heidelpayPHP\test\BasePaymentTest;
use PHPUnit\Framework\ExpectationFailedException;
Expand Down Expand Up @@ -140,4 +143,41 @@ public function authorizationCanBeFetched(Authorization $authorization)
$fetchedAuthorization = $this->heidelpay->fetchAuthorization($authorization->getPaymentId());
$this->assertEquals($authorization->expose(), $fetchedAuthorization->expose());
}

/**
* Verify authorization has the expected states.
*
* @test
* @dataProvider authorizeHasExpectedStatesDP
*
* @param BasePaymentType|AbstractHeidelpayResource $paymentType
* @param bool $isSuccess
* @param bool $isPending
* @param bool $isError
*
* @throws HeidelpayApiException
* @throws \PHPUnit\Framework\AssertionFailedError
* @throws \RuntimeException
*/
public function authorizeHasExpectedStates(BasePaymentType $paymentType, $isSuccess, $isPending, $isError)
{
$paymentType = $this->heidelpay->createPaymentType($paymentType);
$authorize = $this->heidelpay->authorize(100.0, 'EUR', $paymentType->getId(), self::RETURN_URL);
$this->assertEquals($isSuccess, $authorize->isSuccess());
$this->assertEquals($isPending, $authorize->isPending());
$this->assertEquals($isError, $authorize->isError());
}

/**
* @return array
*
* @throws \RuntimeException
*/
public function authorizeHasExpectedStatesDP(): array
{
return [
'card' => [$this->createCardObject(), true, false, false],
'paypal' => [new Paypal(), false, true, false]
];
}
}
18 changes: 18 additions & 0 deletions test/integration/CancelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,22 @@ public function chargeCancellationsShouldBeFetchableViaPaymentObject()
$this->assertNotNull($cancellation);
$this->assertEquals($cancellation->expose(), $reversal->expose());
}

/**
* Verify transaction status.
*
* @test
*
* @throws HeidelpayApiException
* @throws \RuntimeException
*/
public function cancelStatusIsSetCorrectly()
{
$charge = $this->createCharge();
$reversal = $charge->cancel();

$this->assertTrue($reversal->isSuccess());
$this->assertFalse($reversal->isPending());
$this->assertFalse($reversal->isError());
}
}
17 changes: 17 additions & 0 deletions test/integration/ChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,21 @@ public function chargeShouldWorkWithTypeObject()
$this->assertNotEmpty($charge->getPayment()->getId());
$this->assertEquals(self::RETURN_URL, $charge->getReturnUrl());
}

/**
* Verify transaction status.
*
* @test
*
* @throws HeidelpayApiException
* @throws \RuntimeException
*/
public function chargeStatusIsSetCorrectly()
{
$charge = $this->createCharge();

$this->assertTrue($charge->isSuccess());
$this->assertFalse($charge->isPending());
$this->assertFalse($charge->isError());
}
}
26 changes: 26 additions & 0 deletions test/integration/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,30 @@ public function shipmentShouldBePossibleWithPaymentObject()
$this->assertNotNull($shipment->getId());
$this->assertNotNull($shipment);
}

/**
* Verify transaction status.
*
* @test
*
* @throws HeidelpayApiException
* @throws \RuntimeException
*/
public function shippmentStatusIsSetCorrectly()
{
$invoiceGuaranteed = new InvoiceGuaranteed();
$authorize = $this->heidelpay->authorize(
100.0,
'EUR',
$invoiceGuaranteed,
self::RETURN_URL,
$this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress())
);

$payment = $authorize->getPayment();
$shipment = $this->heidelpay->ship($payment);
$this->assertTrue($shipment->isSuccess());
$this->assertFalse($shipment->isPending());
$this->assertFalse($shipment->isError());
}
}
2 changes: 1 addition & 1 deletion test/unit/DummyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DummyResource extends AbstractHeidelpayResource
{
public function jsonSerialize()
{
return 'dummyResourceJsonSerialized';
return '{"dummyResource": "JsonSerialized"}';
}

public function getUri($appendId = true): string
Expand Down
Loading

0 comments on commit a182efa

Please sign in to comment.