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

Commit

Permalink
change/PHPLIB-187/add-geolocation-to-card (#174)
Browse files Browse the repository at this point in the history
* [bugfix] (PHPLIB-309) Rename Cards holder to cardHolder.

* [change] (PHPLIB-209) Fix tests add update version and CHANGELOG.md

* [change] (PHPLIB-309) Update test.

* [change] (PHPLIB-309) Update unit test.

* [refactor] (PHPLIB-187) Geolocation: Move geolocation to trait.

* [refactor] (PHPLIB-187) Geolocation: Add geolocation to card class.

* [change] (PHPLIB-187) Fix styles.

* [change] (PHPLIB-187) Update CHANGELOG.md

* [change] (PHPLIB-187) Remove dead "code"

* [change] (PHPLIB-187) Fix examples: Fix ids due to api changes.

* [change] (PHPLIB-187) Fix examples: Fix ids due to api changes.

Co-authored-by: sixer1182 <[email protected]>
  • Loading branch information
Simon Gabriel and sixer1182 authored May 12, 2020
1 parent 2367c5a commit a5ef5e9
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
* TraceId property to payment and transactions.
* Email form field to PayPal example.
* Description to zgReferenceId setter/getter.
* Added geolocation to Card resource.

## [1.2.7.1][1.2.7.1]

Expand Down
6 changes: 3 additions & 3 deletions examples/EmbeddedPayPage/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
$paypage->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
->setShopName('My Test Shop')
->setTagline('Try and stop us from being awesome!')
->setOrderId('OrderNr' . microtime(true))
->setInvoiceId('InvoiceNr' . microtime(true));
->setOrderId('o' . microtime(true))
->setInvoiceId('i' . microtime(true));

// ... in order to enable FlexiPay Rate (Hire Purchase) you will need to set the effectiveInterestRate as well.
$paypage->setEffectiveInterestRate(4.99);

// ... a Basket is mandatory for HirePurchase
$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));
$basketItem = new BasketItem('Hat', 100.0, 119.0, 1);
$basket = new Basket($orderId, 119.0, 'EUR', [$basketItem]);

Expand Down
2 changes: 1 addition & 1 deletion examples/HirePurchaseDirectDebit/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

// Use the quote or order id from your shop
$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

/** @var HirePurchaseDirectDebit $paymentType */
$paymentType = $heidelpay->fetchPaymentType($paymentTypeId);
Expand Down
4 changes: 2 additions & 2 deletions examples/HostedPayPage/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
// These are the mandatory parameters for the payment page ...
$paypage = new Paypage(119.0, 'EUR', RETURN_CONTROLLER_URL);

$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

// ... however you can customize the Payment Page using additional parameters.
$paypage->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
Expand All @@ -82,7 +82,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
->setImprintUrl('https://www.heidelpay.com/it/')
->setHelpUrl('https://www.heidelpay.com/at/')
->setContactUrl('https://www.heidelpay.com/en/about-us/about-heidelpay/')
->setInvoiceId('InvoiceNr' . microtime(true));
->setInvoiceId('i' . microtime(true));

// ... in order to enable FlexiPay Rate (Hire Purchase) you will need to set the effectiveInterestRate as well.
$paypage->setEffectiveInterestRate(4.99);
Expand Down
2 changes: 1 addition & 1 deletion examples/Invoice/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
$invoice = $heidelpay->createPaymentType(new Invoice());

$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

$transaction = $invoice->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId);

Expand Down
2 changes: 1 addition & 1 deletion examples/InvoiceFactoring/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
->setCountry('DE');
$customer->setBirthDate('2000-02-12')->setBillingAddress($address)->setShippingAddress($address);

$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

// A Basket is mandatory for Invoice Factoring payment type
$basketItem = new BasketItem('Hat', 100.0, 119.0, 1);
Expand Down
2 changes: 1 addition & 1 deletion examples/InvoiceGuaranteed/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
$heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY);
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

// A Basket is mandatory for Invoice Factoring payment type
$basketItem = new BasketItem('Hat', 100.0, 119.0, 1);
Expand Down
2 changes: 1 addition & 1 deletion examples/Prepayment/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
$prepayment = $heidelpay->createPaymentType(new Prepayment());

$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

$transaction = $prepayment->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId);

Expand Down
2 changes: 1 addition & 1 deletion examples/SepaDirectDebitGuaranteed/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
$heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY);
$heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

$orderId = str_replace(['0.', ' '], '', microtime(false));
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));

// A Basket is mandatory for SEPA direct debit guaranteed payment type
$basketItem = new BasketItem('Hat', 100.0, 119.0, 1);
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
2 changes: 2 additions & 0 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 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>
}
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
13 changes: 11 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
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SepaDirectDebitGuaranteedTest extends BasePaymentTest
*/
public function sepaDirectDebitGuaranteedShouldBeCreatableWithMandatoryFieldsOnly()
{
/** @var SepaDirectDebitGuaranteed $directDebitGuaranteed */
$directDebitGuaranteed = new SepaDirectDebitGuaranteed('DE89370400440532013000');
/** @var SepaDirectDebitGuaranteed $directDebitGuaranteed */
$directDebitGuaranteed = $this->heidelpay->createPaymentType($directDebitGuaranteed);
$this->assertInstanceOf(SepaDirectDebitGuaranteed::class, $directDebitGuaranteed);
$this->assertNotNull($directDebitGuaranteed->getId());
Expand All @@ -66,8 +66,8 @@ public function sepaDirectDebitGuaranteedShouldBeCreatableWithMandatoryFieldsOnl
*/
public function sepaDirectDebitGuaranteedShouldBeCreatable(): SepaDirectDebitGuaranteed
{
/** @var SepaDirectDebitGuaranteed $directDebitGuaranteed */
$directDebitGuaranteed = (new SepaDirectDebitGuaranteed('DE89370400440532013000'))->setHolder('John Doe')->setBic('COBADEFFXXX');
/** @var SepaDirectDebitGuaranteed $directDebitGuaranteed */
$directDebitGuaranteed = $this->heidelpay->createPaymentType($directDebitGuaranteed);
$this->assertInstanceOf(SepaDirectDebitGuaranteed::class, $directDebitGuaranteed);
$this->assertNotNull($directDebitGuaranteed->getId());
Expand Down
4 changes: 2 additions & 2 deletions test/integration/PaymentTypes/SepaDirectDebitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SepaDirectDebitTest extends BasePaymentTest
*/
public function sepaDirectDebitShouldBeCreatableWithMandatoryFieldsOnly()
{
/** @var SepaDirectDebit $directDebit */
$directDebit = new SepaDirectDebit('DE89370400440532013000');
/** @var SepaDirectDebit $directDebit */
$directDebit = $this->heidelpay->createPaymentType($directDebit);
$this->assertInstanceOf(SepaDirectDebit::class, $directDebit);
$this->assertNotNull($directDebit->getId());
Expand All @@ -64,8 +64,8 @@ public function sepaDirectDebitShouldBeCreatableWithMandatoryFieldsOnly()
*/
public function sepaDirectDebitShouldBeCreatable()
{
/** @var SepaDirectDebit $sdd */
$sdd = (new SepaDirectDebit('DE89370400440532013000'))->setHolder('Max Mustermann')->setBic('COBADEFFXXX');
/** @var SepaDirectDebit $sdd */
$sdd = $this->heidelpay->createPaymentType($sdd);
$this->assertInstanceOf(SepaDirectDebit::class, $sdd);
$this->assertNotNull($sdd->getId());
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

0 comments on commit a5ef5e9

Please sign in to comment.