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

change/PHPLIB-187/add-geolocation-to-card #174

Merged
merged 14 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ 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.2.7.2][1.2.7.2]

### Fix
* Rename Cards property holder to cardHolder.

### Change
* Fix some minor issues.

## [1.2.7.1][1.2.7.1]

### Added
Expand Down Expand Up @@ -394,3 +403,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
[1.2.6.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.5.1..1.2.6.0
[1.2.7.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.6.0..1.2.7.0
[1.2.7.1]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.7.0..1.2.7.1
[1.2.7.2]: https://github.com/heidelpay/heidelpayPHP/compare/1.2.7.1..1.2.7.2
2 changes: 1 addition & 1 deletion src/Heidelpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Heidelpay implements HeidelpayParentInterface, PaymentServiceInterface, Re
const BASE_URL = 'api.heidelpay.com';
const API_VERSION = 'v1';
const SDK_TYPE = 'HeidelpayPHP';
const SDK_VERSION = '1.2.7.1';
const SDK_VERSION = '1.2.7.2';

/** @var string $key */
private $key;
Expand Down
16 changes: 3 additions & 13 deletions src/Resources/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
use heidelpayPHP\Constants\Salutations;
use heidelpayPHP\Resources\EmbeddedResources\Address;
use heidelpayPHP\Resources\EmbeddedResources\CompanyInfo;
use heidelpayPHP\Resources\EmbeddedResources\GeoLocation;
use heidelpayPHP\Traits\HasGeoLocation;
use stdClass;
use function in_array;

class Customer extends AbstractHeidelpayResource
{
use HasGeoLocation;

/** @var string $firstname */
protected $firstname;

Expand Down Expand Up @@ -70,9 +72,6 @@ class Customer extends AbstractHeidelpayResource
/** @var CompanyInfo $companyInfo */
protected $companyInfo;

/** @var GeoLocation $geoLocation */
private $geoLocation;

/**
* Customer constructor.
*
Expand All @@ -90,7 +89,6 @@ public function __construct(string $firstname = null, string $lastname = null)
$this->lastname = $lastname;
$this->billingAddress = new Address();
$this->shippingAddress = new Address();
$this->geoLocation = new GeoLocation();
}

//<editor-fold desc="Getters/Setters">
Expand Down Expand Up @@ -324,14 +322,6 @@ public function setCompanyInfo(CompanyInfo $companyInfo): Customer
return $this;
}

/**
* @return GeoLocation|null
*/
public function getGeoLocation()
{
return $this->geoLocation;
}

//</editor-fold>

//<editor-fold desc="Resource IF">
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/EmbeddedResources/GeoLocation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Represents the customers geolocation.
* Represents the geo location of an entity.
*
* Copyright (C) 2019 heidelpay GmbH
*
Expand Down
38 changes: 31 additions & 7 deletions src/Resources/PaymentTypes/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use heidelpayPHP\Traits\CanDirectCharge;
use heidelpayPHP\Traits\CanPayout;
use heidelpayPHP\Traits\CanRecur;
use heidelpayPHP\Traits\HasGeoLocation;
use heidelpayPHP\Validators\ExpiryDateValidator;
use RuntimeException;
use stdClass;
Expand All @@ -40,6 +41,7 @@ class Card extends BasePaymentType
use CanAuthorize;
use CanPayout;
use CanRecur;
use HasGeoLocation;

/** @var string $number */
protected $number;
Expand All @@ -50,8 +52,8 @@ class Card extends BasePaymentType
/** @var string $cvc */
protected $cvc;

/** @var string $holder */
protected $holder = '';
/** @var string $cardHolder */
protected $cardHolder = '';

/** @var bool $card3ds */
protected $card3ds;
Expand Down Expand Up @@ -150,22 +152,44 @@ public function setCvc($cvc): Card
/**
* @return string|null
*/
public function getHolder()
public function getCardHolder()
{
return $this->holder;
return $this->cardHolder;
}

/**
* @param string $holder
* @param string $cardHolder
*
* @return Card
*/
public function setHolder($holder): Card
public function setCardHolder($cardHolder): Card
{
$this->holder = $holder;
$this->cardHolder = $cardHolder;
return $this;
}

/**
* @return string|null
*
* @deprecated since 1.2.7.2
*/
public function getHolder()
{
return $this->getCardHolder();
}

/**
* @param string $cardHolder
*
* @return Card
*
* @deprecated since 1.2.7.2
*/
public function setHolder($cardHolder): Card
{
return $this->setCardHolder($cardHolder);
}

/**
* @return bool|null
*/
Expand Down
59 changes: 59 additions & 0 deletions src/Traits/HasGeoLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* This trait adds geolocation to class.
*
* Copyright (C) 2020 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;

use heidelpayPHP\Resources\EmbeddedResources\GeoLocation;

trait HasGeoLocation
{
/** @var GeoLocation $geoLocation */
private $geoLocation;

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

/**
* @return GeoLocation
*/
public function getGeoLocation(): GeoLocation
{
if (empty($this->geoLocation)) {
$this->geoLocation = new GeoLocation();
}
return $this->geoLocation;
}

/**
* @param GeoLocation $geoLocation
*
* @return $this
*/
public function setGeoLocation(GeoLocation $geoLocation): self
{
$this->geoLocation = $geoLocation;
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 @@ -223,7 +223,7 @@ protected function createCardObject(string $cardNumber = '5453010000059543'): Ca
{
$expiryDate = $this->getNextYearsTimestamp()->format('m/Y');
$card = new Card($cardNumber, $expiryDate);
$card->setCvc('123');
$card->setCvc('123')->setCardHolder('max mustermann');
return $card;
}

Expand Down
5 changes: 0 additions & 5 deletions test/integration/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use heidelpayPHP\Constants\Salutations;
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Resources\Customer;
use heidelpayPHP\Resources\EmbeddedResources\GeoLocation;
use heidelpayPHP\Resources\Payment;
use heidelpayPHP\Resources\PaymentTypes\Paypal;
use heidelpayPHP\test\BasePaymentTest;
Expand All @@ -52,25 +51,21 @@ class CustomerTest extends BasePaymentTest
*/
public function minCustomerCanBeCreatedAndFetched(): Customer
{
/** @var Customer $customer */
$customer = $this->getMinimalCustomer();
$this->assertEmpty($customer->getId());
$this->heidelpay->createCustomer($customer);
$this->assertNotEmpty($customer->getId());

$geoLocation = $customer->getGeoLocation();
$this->assertInstanceOf(GeoLocation::class, $geoLocation);
$this->assertNull($geoLocation->getClientIp());
$this->assertNull($geoLocation->getCountryCode());

/** @var Customer $fetchedCustomer */
$fetchedCustomer = $this->heidelpay->fetchCustomer($customer->getId());
$exposeArray = $customer->expose();
$exposeArray['salutation'] = Salutations::UNKNOWN;
$this->assertEquals($exposeArray, $fetchedCustomer->expose());

$geoLocation = $fetchedCustomer->getGeoLocation();
$this->assertInstanceOf(GeoLocation::class, $geoLocation);
$this->assertNotEmpty($geoLocation->getClientIp());
$this->assertNotEmpty($geoLocation->getCountryCode());

Expand Down
15 changes: 13 additions & 2 deletions test/integration/PaymentTypes/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,25 @@ class CardTest extends BasePaymentTest
*/
public function cardShouldBeCreatable(string $cardNumber, CardDetails $expectedCardDetails): BasePaymentType
{
/** @var Card $card */
$card = $this->createCardObject($cardNumber);
$this->assertNull($card->getId());

$geoLocation = $card->getGeoLocation();
$this->assertNull($geoLocation->getClientIp());
$this->assertNull($geoLocation->getCountryCode());

/** @var Card $card */
$card = $this->heidelpay->createPaymentType($card);

$this->assertInstanceOf(Card::class, $card);
$this->assertNotNull($card->getId());
$this->assertSame($this->heidelpay, $card->getHeidelpayObject());
$this->assertEquals($expectedCardDetails, $card->getCardDetails());

$geoLocation = $card->getGeoLocation();
$this->assertNotEmpty($geoLocation->getClientIp());
$this->assertNotEmpty($geoLocation->getCountryCode());

return $card;
}

Expand All @@ -81,8 +90,8 @@ public function cardShouldBeCreatable(string $cardNumber, CardDetails $expectedC
*/
public function cardWith3dsFlagShouldSetItAlsoInTransactions()
{
/** @var Card $card */
$card = $this->createCardObject()->set3ds(false);
/** @var Card $card */
$card = $this->heidelpay->createPaymentType($card);
$this->assertFalse($card->get3ds());

Expand Down Expand Up @@ -180,13 +189,15 @@ public function cardCanBeFetched()
$card = $this->createCardObject();
$card = $this->heidelpay->createPaymentType($card);
$this->assertNotNull($card->getId());
$this->assertNotNull($card->getCardHolder());

/** @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->getCardHolder(), $fetchedCard->getCardHolder());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/unit/Resources/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function settersAndGettersShouldWork()
$this->assertNull($customer->getMobile());
$this->assertNull($customer->getEmail());
$this->assertNull($customer->getCompany());
$this->assertInstanceOf(GeoLocation::class, $customer->getGeoLocation());
$geoLocation = $customer->getGeoLocation();
$this->assertNull($geoLocation->getClientIp());
$this->assertNull($geoLocation->getCountryCode());

$customer->setCustomerId('MyCustomerId-123');
$this->assertEquals('MyCustomerId-123', $customer->getCustomerId());
Expand Down
Loading