Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAG2-298 - Added Amazon Pay V2 #550

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions Api/AmazonPayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ interface AmazonPayInterface
* @return \Payone\Core\Service\V1\Data\AmazonPayResponse
*/
public function getWorkorderId($amazonReferenceId, $amazonAddressToken);

/**
* Returns Amazon Pay V2 checkout session payload
*
* @param string $cartId
* @return \Payone\Core\Service\V1\Data\AmazonPayResponse
*/
public function getCheckoutSessionPayload($cartId);

/**
* Returns Amazon Pay V2 checkout session payload for APB
*
* @param string $orderId
* @return \Payone\Core\Service\V1\Data\AmazonPayResponse
*/
public function getAmazonPayApbSession($orderId);
}
14 changes: 14 additions & 0 deletions Api/Data/AmazonPayResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public function getRedirectUrl();
* @return string
*/
public function getAmazonReviewHtml();

/**
* Returns error message
*
* @return string
*/
public function getPayload();

/**
* Returns error message
*
* @return string
*/
public function getSignature();
}
22 changes: 22 additions & 0 deletions Block/Amazon/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Button extends Template implements \Magento\Catalog\Block\ShortcutInterfac
*/
protected $baseHelper;

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

/**
* Constructor
*
Expand Down Expand Up @@ -73,6 +78,23 @@ public function getAlias()
return $this->alias;
}

/**
* @param string $name
* @return void
*/
public function setName($name)
{
$this->name = $name;
}

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

/**
* Get Amazon client id from config
*
Expand Down
250 changes: 250 additions & 0 deletions Block/Amazon/ButtonV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php

/**
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
*
* PHP version 5
*
* @category Payone
* @package Payone_Magento2_Plugin
* @author FATCHIP GmbH <[email protected]>
* @copyright 2003 - 2024 Payone GmbH
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License
* @link http://www.payone.de
*/

namespace Payone\Core\Block\Amazon;

use Magento\Framework\View\Element\Template;
use Payone\Core\Model\Methods\AmazonPayV2;
use Payone\Core\Model\PayoneConfig;

/**
* Block class for the Amazon Pay V2 button
*/
class ButtonV2 extends Template implements \Magento\Catalog\Block\ShortcutInterface
{
/**
* Shortcut alias
*
* @var string
*/
protected $alias = 'payone.block.amazon.buttonv2';

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

/**
* @var \Payone\Core\Helper\Api
*/
protected $apiHelper;

/**
* @var \Magento\Checkout\Model\Session
*/
protected $checkoutSession;

/**
* @var \Payone\Core\Model\Methods\AmazonPayV2
*/
protected $amazonPayment;

/**
* Constructor
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Payone\Core\Helper\Api $apiHelper
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Payone\Core\Model\Methods\AmazonPayV2 $amazonPayment
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Payone\Core\Helper\Api $apiHelper,
\Magento\Checkout\Model\Session $checkoutSession,
\Payone\Core\Model\Methods\AmazonPayV2 $amazonPayment,
array $data = []
) {
parent::__construct($context, $data);
$this->apiHelper = $apiHelper;
$this->checkoutSession = $checkoutSession;
$this->amazonPayment = $amazonPayment;
$this->setTemplate('amazon/buttonv2.phtml');
}

/**
* Get shortcut alias
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}

/**
* @param string $name
* @return void
*/
public function setName($name)
{
$this->name = $name;
}

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

/**
* @return int
*/
public function getQuoteId()
{
return $this->getQuote()->getId();
}

/**
* @return string
*/
public function getStoreCode()
{
return $this->getQuote()->getStore()->getCode();
}

/**
* @return string
*/
public function getButtonId()
{
$buttonId = "AmazonPayButton";
if (strpos($this->getName() ?? '', "checkout.cart.shortcut.buttons") !== false) {
$buttonId = "AmazonPayButtonBasket";
} elseif (strpos($this->getName() ?? '', "shortcutbuttons") !== false) {
$buttonId = "AmazonPayButtonMiniBasket";
}
return $buttonId;
}

/**
* @return mixed
*/
public function getQuote()
{
return $this->checkoutSession->getQuote();
}

/**
* @return string
*/
public function getPublicKeyId()
{
return AmazonPayV2::BUTTON_PUBLIC_KEY;
}

/**
* Get Amazon merchant id from config
*
* @return string
*/
public function getMerchantId()
{
return $this->amazonPayment->getMerchantId();
}

/**
* @return bool
*/
public function isTestMode()
{
return $this->amazonPayment->useSandbox();
}

/**
* @return string
*/
public function getCurrency()
{
return $this->apiHelper->getCurrencyFromQuote($this->getQuote());
}

/**
* @return float
*/
public function getAmount()
{
return $this->apiHelper->getQuoteAmount($this->getQuote());
}

/**
* @return string
*/
public function getProductType()
{
$oQuote = $this->getQuote();
if ($oQuote->isVirtual() === true) {
return "PayOnly";
}
return "PayAndShip";
/**
* 'PayAndShip' - Offer checkout using buyer's Amazon wallet and address book. Select this product type if you need the buyer's shipping details
* 'PayOnly' - Offer checkout using only the buyer's Amazon wallet. Select this product type if you do not need the buyer's shipping details
* 'SignIn' - Offer Amazon Sign-in. Select this product type if you need buyer details before the buyer starts Amazon Pay checkout. See Amazon Sign-in for more information.
* Default value: 'PayAndShip'
*/
}

/**
* @return string
*/
public function getPlacement()
{
if ($this->getButtonId() == "AmazonPayButtonBasket") {
return "Cart";
}
return "Home";
/**
* 'Home' - Initial or main page
* 'Product' - Product details page
* 'Cart' - Cart review page before buyer starts checkout
* 'Checkout' - Any page after buyer starts checkout
* 'Other' - Any page that doesn't fit the previous descriptions
*/
}

/**
* Get Amazon button color from config
*
* @return string
*/
public function getButtonColor()
{
return $this->amazonPayment->getButtonColor();
}

/**
* Get Amazon button language from config
*
* @return string
*/
public function getButtonLanguage()
{
return $this->amazonPayment->getButtonLanguage();
}
}
Loading
Loading