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

Commit

Permalink
Merge remote-tracking branch 'remotes/github/develop' into change/PHP…
Browse files Browse the repository at this point in the history
…LIB-187/add-geolocation-to-card

# Conflicts:
#	CHANGELOG.md
#	src/Heidelpay.php
#	test/integration/PaymentTypes/CardTest.php
#	test/unit/Resources/PaymentTypes/CardTest.php
  • Loading branch information
sixer1182 committed May 8, 2020
2 parents 7f39871 + 977062d commit 636b8bb
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Change
* Fix some minor issues.
* Refactor tests due to API changes.

### Added
* TraceId property to payment and transactions.

## [1.2.7.1][1.2.7.1]

Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
namespace heidelpayPHP\Adapter;

use heidelpayPHP\Heidelpay;
use heidelpayPHP\Services\EnvironmentService;
use function extension_loaded;
use heidelpayPHP\Exceptions\HeidelpayApiException;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function setHeaders(array $headers)
*/
public function setUserAgent($userAgent)
{
$this->setOption(CURLOPT_USERAGENT, 'HeidelpayPHP');
$this->setOption(CURLOPT_USERAGENT, Heidelpay::SDK_TYPE);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Heidelpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Heidelpay implements HeidelpayParentInterface, PaymentServiceInterface, Re
{
const BASE_URL = 'api.heidelpay.com';
const API_VERSION = 'v1';
const SDK_TYPE = 'HeidelpayPHP';
const SDK_TYPE = 'heidelpayPHP';
const SDK_VERSION = '1.2.7.2';

/** @var string $key */
Expand Down Expand Up @@ -172,11 +172,11 @@ public function setLocale($locale): Heidelpay
}

/**
* @param ResourceServiceInterface $resourceService
* @param ResourceService $resourceService
*
* @return Heidelpay
*/
public function setResourceService(ResourceServiceInterface $resourceService): Heidelpay
public function setResourceService(ResourceService $resourceService): Heidelpay
{
$this->resourceService = $resourceService->setHeidelpay($this);
return $this;
Expand All @@ -193,11 +193,11 @@ public function getResourceService(): ResourceService
}

/**
* @param PaymentServiceInterface $paymentService
* @param PaymentService $paymentService
*
* @return Heidelpay
*/
public function setPaymentService(PaymentServiceInterface $paymentService): Heidelpay
public function setPaymentService(PaymentService $paymentService): Heidelpay
{
$this->paymentService = $paymentService->setHeidelpay($this);
return $this;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ public function debugLog($message)
if ($this->isDebugMode()) {
$debugHandler = $this->getDebugHandler();
if ($debugHandler instanceof DebugHandlerInterface) {
$debugHandler->log('(' . (string)(getmypid()) . ') ' . $message);
$debugHandler->log('(' . getmypid() . ') ' . $message);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/AbstractHeidelpayResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,17 @@ protected function getResourcePath(): string
public function handleResponse(stdClass $response, $method = HttpAdapterInterface::REQUEST_GET)
{
self::updateValues($this, $response);

// Todo: Workaround to be removed when API sends TraceID in processing-group
if (
isset($response->resources->traceId) &&
is_callable([$this, 'setTraceId']) &&
is_callable([$this, 'getTraceId']) &&
$this->getTraceId() === null
) {
$this->setTraceId($response->resources->traceId);
}
// Todo: Workaround end
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use heidelpayPHP\Traits\HasInvoiceId;
use heidelpayPHP\Traits\HasOrderId;
use heidelpayPHP\Traits\HasPaymentState;
use heidelpayPHP\Traits\HasTraceId;
use RuntimeException;
use stdClass;

Expand All @@ -55,6 +56,7 @@ class Payment extends AbstractHeidelpayResource
use HasPaymentState;
use HasOrderId;
use HasInvoiceId;
use HasTraceId;

/** @var string $redirectUrl */
private $redirectUrl;
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/TransactionTypes/AbstractTransactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use heidelpayPHP\Traits\HasDate;
use heidelpayPHP\Traits\HasOrderId;
use heidelpayPHP\Traits\HasStates;
use heidelpayPHP\Traits\HasTraceId;
use heidelpayPHP\Traits\HasUniqueAndShortId;
use RuntimeException;
use stdClass;
Expand All @@ -42,6 +43,7 @@ abstract class AbstractTransactionType extends AbstractHeidelpayResource
use HasOrderId;
use HasStates;
use HasUniqueAndShortId;
use HasTraceId;
use HasCustomerMessage;
use HasDate;

Expand Down
55 changes: 55 additions & 0 deletions src/Traits/HasTraceId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* This trait adds the trace id to a class.
* It can be sent to the support when a problem occurs.
*
* Copyright (C) 2019 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 https://docs.heidelpay.com/
*
* @author Simon Gabriel <[email protected]>
*
* @package heidelpayPHP\Traits
*/
namespace heidelpayPHP\Traits;

trait HasTraceId
{
/** @var string $traceId */
private $traceId;

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

/**
* @return string|null
*/
public function getTraceId()
{
return $this->traceId;
}

/**
* @param string $traceId
*
* @return $this
*/
protected function setTraceId(string $traceId): self
{
$this->traceId = $traceId;
return $this;
}

//</editor-fold>
}
2 changes: 1 addition & 1 deletion test/BasePaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function assertPending($transaction)
*/
public function createBasket(): Basket
{
$orderId = self::generateRandomId();
$orderId = 'b' . self::generateRandomId();
$basket = new Basket($orderId, 119.0, 'EUR');
$basket->setAmountTotalVat(19.0);
$basket->setNote('This basket is creatable!');
Expand Down
12 changes: 6 additions & 6 deletions test/integration/BasketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function minBasketShouldBeCreatableAndFetchable()
*/
public function maxBasketShouldBeCreatableAndFetchableWorkAround()
{
$basket = new Basket(self::generateRandomId(), 123.4, 'EUR', []);
$basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))
->setBasketItemReferenceId('refId')
Expand Down Expand Up @@ -116,7 +116,7 @@ public function maxBasketShouldBeCreatableAndFetchableWorkAround()
*/
public function basketItemWithInvalidUrlWillThrowAnError($expectException, $imageUrl, $exceptionCode = null)
{
$basket = new Basket(self::generateRandomId(), 123.4, 'EUR', []);
$basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []);
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setImageUrl($imageUrl);
$basket->addBasketItem($basketItem);

Expand All @@ -143,7 +143,7 @@ public function basketItemWithInvalidUrlWillThrowAnError($expectException, $imag
*/
public function basketShouldBeUpdateable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId');
Expand Down Expand Up @@ -175,7 +175,7 @@ public function basketShouldBeUpdateable()
*/
public function authorizeTransactionsShouldPassAlongTheBasketIdIfSet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 123.4, 234.5, 12))->setBasketItemReferenceId('refId');
Expand Down Expand Up @@ -224,7 +224,7 @@ public function chargeTransactionsShouldPassAlongTheBasketIdIfSet()
*/
public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId');
Expand All @@ -250,7 +250,7 @@ public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet()
*/
public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basket->setAmountTotalVat(10.9);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function customerCanBeFetchedById(Customer $customer)
*/
public function customerCanBeFetchedByCustomerId()
{
$customerId = str_replace([' ', '.'], '', microtime());
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomer()->setCustomerId($customerId);
$this->heidelpay->createCustomer($customer);

Expand Down Expand Up @@ -168,7 +168,7 @@ public function customerCanBeFetchedByObjectWithData(Customer $customer)
*/
public function transactionShouldCreateAndReferenceCustomerIfItDoesNotExistYet()
{
$customerId = 'customer' . self::generateRandomId();
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomerInclShippingAddress()->setCustomerId($customerId);

/** @var Paypal $paypal */
Expand Down Expand Up @@ -374,7 +374,7 @@ public function customerShouldBeFetchedByCustomerIdAndUpdatedIfItAlreadyExists()
*/
public function addressNameCanHoldFirstAndLastNameConcatenated()
{
$customerId = 'customer' . self::generateRandomId();
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomerInclShippingAddress()->setCustomerId($customerId);
$longName = 'firstfirstfirstfirstfirstfirstfirstfirst lastlastlastlastlastlastlastlastlastlast';
$customer->getShippingAddress()->setName($longName);
Expand Down
10 changes: 7 additions & 3 deletions test/integration/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function paymentShouldBeFetchableById(): void
$this->assertInstanceOf(Authorization::class, $payment->getAuthorization());
$this->assertNotEmpty($payment->getAuthorization()->getId());
$this->assertNotNull($payment->getState());

$traceId = $authorize->getTraceId();
$this->assertNotEmpty($traceId);
$this->assertSame($traceId, $payment->getTraceId());
}

/**
Expand Down Expand Up @@ -174,7 +178,7 @@ public function paymentChargeOnAuthorizeShouldTakeResourceIds()
{
$card = $this->heidelpay->createPaymentType($this->createCardObject());
$authorization = $this->heidelpay->authorize(100.00, 'EUR', $card, 'http://heidelpay.com', null, null, null, null, false);
$charge = $this->heidelpay->chargePayment($authorization->getPaymentId(), null, 'order-' . self::generateRandomId(), 'invoice-' . self::generateRandomId());
$charge = $this->heidelpay->chargePayment($authorization->getPaymentId(), null, 'EUR', 'o' . self::generateRandomId(), 'i' . self::generateRandomId());

$this->assertNotEmpty($charge->getId());
}
Expand Down Expand Up @@ -224,7 +228,7 @@ public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet()
*/
public function shouldAllowNonUniqueOrderId()
{
$orderId = self::generateRandomId();
$orderId = 'o' . self::generateRandomId();

/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
Expand All @@ -250,7 +254,7 @@ public function shouldAllowNonUniqueOrderId()
*/
public function shouldAllowNonUniqueInvoiceId()
{
$invoiceId = self::generateRandomId();
$invoiceId = 'i' . self::generateRandomId();

/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
Expand Down
26 changes: 26 additions & 0 deletions test/integration/PaymentTypes/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ public function cardCanBeFetched()
$this->assertEquals($card->getCardHolder(), $fetchedCard->getCardHolder());
}

/**
* Verify that a card object can be fetched from the api using its id.
*
* @test
*
* @throws HeidelpayApiException A HeidelpayApiException is thrown if there is an error returned on API-request.
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
*
* @deprecated since 1.2.7.2
*/
public function cardCanBeFetchedOld()
{
$card = $this->createCardObject();
$this->heidelpay->createPaymentType($card);
$this->assertNotNull($card->getId());
$this->assertNotEmpty($card->getHolder());

/** @var Card $fetchedCard */
$fetchedCard = $this->heidelpay->fetchPaymentType($card->getId());
$this->assertNotNull($fetchedCard->getId());
$this->assertEquals($this->maskNumber($card->getNumber()), $fetchedCard->getNumber());
$this->assertEquals($card->getExpiryDate(), $fetchedCard->getExpiryDate());
$this->assertEquals('***', $fetchedCard->getCvc());
$this->assertEquals($card->getHolder(), $fetchedCard->getHolder());
}

/**
* Verify the card can charge the full amount of the authorization and the payment state is updated accordingly.
*
Expand Down
4 changes: 2 additions & 2 deletions test/integration/PaymentTypes/InvoiceGuaranteedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function verifyInvoiceGuaranteedShipment()
$this->assertNotEmpty($charge->getHolder());
$this->assertNotEmpty($charge->getDescriptor());

$shipment = $this->heidelpay->ship($charge->getPayment(), self::generateRandomId(), self::generateRandomId());
$shipment = $this->heidelpay->ship($charge->getPayment(), 'i' . self::generateRandomId(), 'o' . self::generateRandomId());
$this->assertTransactionResourceHasBeenCreated($shipment);
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function verifyInvoiceIdInShipmentWillOverrideTheOneFromCharge()
$invoiceGuaranteed = $this->heidelpay->createPaymentType(new InvoiceGuaranteed());
$customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress());

$invoiceId = self::generateRandomId();
$invoiceId = 'i' . self::generateRandomId();
$charge = $invoiceGuaranteed->charge(100.0, 'EUR', self::RETURN_URL, $customer, null, null, null, null, $invoiceId);
$chargeInvoiceId = $charge->getPayment()->getInvoiceId();

Expand Down
8 changes: 4 additions & 4 deletions test/integration/PaymentTypes/PaypageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function minimalPaypageChargeShouldBeCreatableAndFetchable()
*/
public function maximumPaypageChargeShouldBeCreatable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = $this->createBasket();
$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paypage = (new Paypage(119.0, 'EUR', self::RETURN_URL))
->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
->setFullPageImage('https://www.heidelpay.com/fileadmin/content/header-Imges-neu/Header_Phone_12.jpg')
Expand Down Expand Up @@ -120,10 +120,10 @@ public function minimalPaypageAuthorizeShouldBeCreatableAndFetchable()
*/
public function maximumPaypageAuthorizeShouldBeCreatable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = $this->createBasket();
$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paypage = (new Paypage(119.0, 'EUR', self::RETURN_URL))
->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
->setFullPageImage('https://www.heidelpay.com/fileadmin/content/header-Imges-neu/Header_Phone_12.jpg')
Expand Down
Loading

0 comments on commit 636b8bb

Please sign in to comment.