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

Commit

Permalink
Merge pull request #104 from heidelpay/develop
Browse files Browse the repository at this point in the history
initial release
  • Loading branch information
Simon Gabriel authored Apr 17, 2020
2 parents 95b9751 + d9945e0 commit d47627c
Show file tree
Hide file tree
Showing 107 changed files with 12,915 additions and 4,663 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/.php_cs.cache
/vendor
/composer.lock
/vendor
86 changes: 86 additions & 0 deletions Api/Checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Heidelpay\MGW\Api;

use Exception;
use Heidelpay\MGW\Api\Data\Customer;
use Heidelpay\MGW\Helper\Order as OrderHelper;
use Magento\Checkout\Model\Session;
use Magento\Quote\Model\Quote;

/**
* Checkout API Interface Implementation.
*
* 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 Justin Nuß
*
* @package heidelpay/magento2-merchant-gateway
*/
class Checkout implements CheckoutInterface
{
/**
* @var Session
*/
protected $_checkoutSession;

/**
* @var OrderHelper
*/
protected $_orderHelper;

/**
* Checkout constructor.
* @param Session $checkoutSession
* @param OrderHelper $orderHelper
*/
public function __construct(Session $checkoutSession, OrderHelper $orderHelper)
{
$this->_checkoutSession = $checkoutSession;
$this->_orderHelper = $orderHelper;
}

/**
* Returns the external customer for the current quote.
*
* @param string|null $guestEmail E-Mail address used for quote, in case customer is not logged in.
*
* @return Customer|null
*
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getExternalCustomer(?string $guestEmail = null): ?Customer
{
/** @var Quote $quote */
$quote = $this->_checkoutSession->getQuote();

$email = $guestEmail ?? $quote->getCustomerEmail();

if ($email === null) {
return null;
}

try {
$customerResource = $this->_orderHelper->createCustomerFromQuote($quote, $email);
} catch (Exception $e) {
$customerResource = null;
}

return $customerResource !== null ? Customer::fromResource($customerResource) : null;
}
}
40 changes: 40 additions & 0 deletions Api/CheckoutInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Heidelpay\MGW\Api;

use Heidelpay\MGW\Api\Data\Customer;

/**
* Checkout API Interface.
*
* 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 Justin Nuß
*
* @package heidelpay/magento2-merchant-gateway
*/
interface CheckoutInterface
{
/**
* Returns the external customer ID for the current quote.
*
* @param string|null $guestEmail Customer E-Mail address.
*
* @return Customer|null
*/
public function getExternalCustomer(?string $guestEmail = null): ?Customer;
}
118 changes: 118 additions & 0 deletions Api/Data/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Heidelpay\MGW\Api\Data;

/**
* Checkout API Address DTO.
*
* 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 Justin Nuß
*
* @package heidelpay/magento2-merchant-gateway
*/
class Address
{
/** @var string $name */
protected $name;

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

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

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

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

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

/**
* CompanyInfo constructor.
*/
private function __construct()
{
}

/**
* @param \heidelpayPHP\Resources\EmbeddedResources\Address $addressResource
* @return static
*/
public static function fromResource(\heidelpayPHP\Resources\EmbeddedResources\Address $addressResource): self
{
$address = new self();
$address->name = $addressResource->getName();
$address->street = $addressResource->getStreet();
$address->state = $addressResource->getState();
$address->zip = $addressResource->getZip();
$address->city = $addressResource->getCity();
$address->country = $addressResource->getCountry();
return $address;
}

/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}

/**
* @return string
*/
public function getStreet(): string
{
return $this->street;
}

/**
* @return string|null
*/
public function getState(): ?string
{
return $this->state;
}

/**
* @return string
*/
public function getZip(): string
{
return $this->zip;
}

/**
* @return string
*/
public function getCity(): string
{
return $this->city;
}

/**
* @return string
*/
public function getCountry(): string
{
return $this->country;
}
}
94 changes: 94 additions & 0 deletions Api/Data/CompanyInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Heidelpay\MGW\Api\Data;

/**
* Checkout API CompanyInfo DTO.
*
* 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 Justin Nuß
*
* @package heidelpay/magento2-merchant-gateway
*/
class CompanyInfo
{
/** @var string $registrationType */
protected $registrationType;

/** @var string|null $commercialRegisterNumber */
protected $commercialRegisterNumber;

/** @var string|null $function */
protected $function;

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

/**
* CompanyInfo constructor.
*/
private function __construct()
{
}

/**
* @param \heidelpayPHP\Resources\EmbeddedResources\CompanyInfo $companyInfoResource
* @return static
*/
public static function fromResource(\heidelpayPHP\Resources\EmbeddedResources\CompanyInfo $companyInfoResource): self
{
$companyInfo = new self();
$companyInfo->registrationType = $companyInfoResource->getRegistrationType();
$companyInfo->commercialRegisterNumber = $companyInfoResource->getCommercialRegisterNumber();
$companyInfo->function = $companyInfoResource->getFunction();
$companyInfo->commercialSector = $companyInfoResource->getCommercialSector();
return $companyInfo;
}

/**
* @return string
*/
public function getRegistrationType(): string
{
return $this->registrationType;
}

/**
* @return string|null
*/
public function getCommercialRegisterNumber(): ?string
{
return $this->commercialRegisterNumber;
}

/**
* @return string|null
*/
public function getFunction(): ?string
{
return $this->function;
}

/**
* @return string
*/
public function getCommercialSector(): string
{
return $this->commercialSector;
}
}
Loading

0 comments on commit d47627c

Please sign in to comment.