Skip to content

Commit

Permalink
Merge pull request #15 from Affirm/dev_v2.0.9
Browse files Browse the repository at this point in the history
Dev v2.0.9
  • Loading branch information
Dipti Bele authored Jul 18, 2018
2 parents 85f1fd9 + 654a493 commit 7774c34
Show file tree
Hide file tree
Showing 26 changed files with 966 additions and 89 deletions.
62 changes: 49 additions & 13 deletions Block/Promotion/Banners.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
<?php
/**
* Astound
* NOTICE OF LICENSE
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Affirm
* @package Astound_Affirm
* @copyright Copyright (c) 2016 Astound, Inc. (http://www.astoundcommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* * BSD 3-Clause License
* *
* * Copyright (c) 2018, Affirm
* * All rights reserved.
* *
* * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice, this
* * list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright notice,
* * this list of conditions and the following disclaimer in the documentation
* * and/or other materials provided with the distribution.
* *
* * Neither the name of the copyright holder nor the names of its
* * contributors may be used to endorse or promote products derived from
* * this software without specific prior written permission.
* *
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/


namespace Astound\Affirm\Block\Promotion;

use Magento\Store\Model\ScopeInterface;
Expand Down Expand Up @@ -279,4 +297,22 @@ public function getMFPValue()
return $this->fpHelper->getFinancingProgramValue();
}
}

/**
* Get Page type
*
* @return string
*/
public function getPageType()
{
if ($this->isCartPage()) {
return 'cart';
} else if ($this->isCategoryPage()) {
return 'category';
} else if ($this->isProductPage()) {
return 'product';
} else {
return 'homepage';
}
}
}
4 changes: 4 additions & 0 deletions Block/Promotion/CartPage/Aslowas.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ public function getMFPValue()
{
return $this->asLowAsHelper->getFinancingProgramValue();
}

public function getLearnMoreValue(){
return $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false';
}
}
172 changes: 172 additions & 0 deletions Block/Promotion/Pixel/Confirm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php
/**
*
* * BSD 3-Clause License
* *
* * Copyright (c) 2018, Affirm
* * All rights reserved.
* *
* * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice, this
* * list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright notice,
* * this list of conditions and the following disclaimer in the documentation
* * and/or other materials provided with the distribution.
* *
* * Neither the name of the copyright holder nor the names of its
* * contributors may be used to endorse or promote products derived from
* * this software without specific prior written permission.
* *
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/


namespace Astound\Affirm\Block\Promotion\Pixel;

use Magento\Store\Model\ScopeInterface;
use Magento\Framework\View\Element\Template;
use Astound\Affirm\Model\Ui\ConfigProvider;
use Astound\Affirm\Gateway\Helper\Util;
use Astound\Affirm\Helper\Pixel;

/**
* Class Confirm
*
* @package Astound\Affirm\Block\Promotion
*/
class Confirm extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
*/
protected $_salesOrderCollection;

protected $affirmPixelHelper;

/**
* @param Template\Context $context
* @param ConfigProvider $configProvider
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection
* @param Pixel $helperPixelAffirm
* @param array $data
*/
public function __construct(
Template\Context $context,
ConfigProvider $configProvider,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection,
Pixel $helperPixelAffirm,
array $data = []
) {
$this->affirmPixelHelper = $helperPixelAffirm;
$this->_salesOrderCollection = $salesOrderCollection;
$this->configProvider = $configProvider;
parent::__construct($context, $data);
}

/**
* Render information about specified orders and their items
*
*
* @return string|void
*/
public function getOrdersTrackingCode()
{
$orderIds = $this->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}

$collection = $this->_salesOrderCollection->create();
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
$result = [];

foreach ($collection as $order) {
if ($order->getIsVirtual()) {
$address = $order->getBillingAddress();
} else {
$address = $order->getShippingAddress();
}

$result[] = sprintf("affirm.analytics.trackOrderConfirmed({
'affiliation': '%s',
'orderId': '%s',
'currency': '%s',
'total': '%s',
'tax': '%s',
'shipping': '%s',
'paymentMethod': '%s'
});",
$this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
$order->getIncrementId(),
$order->getOrderCurrencyCode(),
Util::formatToCents($order->getBaseGrandTotal()),
Util::formatToCents($order->getBaseTaxAmount()),
Util::formatToCents($order->getBaseShippingAmount()),
$order->getPayment()->getMethod()
);
}
return implode("\n", $result);
}

/**
* Render GA tracking scripts
*
* @return string
*/
protected function _toHtml()
{
if (!$this->affirmPixelHelper->isAffirmAnalyticsAvailable()) {
return '';
}

return parent::_toHtml();
}

/**
* Get options for
*
* @return string
*/
public function getOptions()
{
$options = [];
$configProvider = $this->configProvider->getConfig();
if ($configProvider['payment'][ConfigProvider::CODE]) {
$config = $configProvider['payment'][ConfigProvider::CODE];
if ($config && isset($config['script']) && isset($config['apiKeyPublic'])) {
$options['script'] = $config['script'];
$options['public_api_key'] = $config['apiKeyPublic'];
$options['sessionId'] = ($this->getCustomerSessionId())? $this->getCustomerSessionId() : '';
}
}
return json_encode($options);
}

public function getCustomerSessionId()
{
$orderIds = $this->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
$collection = $this->_salesOrderCollection->create();
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]);

foreach ($collection as $order) {
$customerId = ($order->getCustomerId()) ? $order->getCustomerId() : $guestId = "CUSTOMER-" . $this->affirmPixelHelper->getDateMicrotime();
}
return $customerId;
}
}
4 changes: 4 additions & 0 deletions Block/Promotion/ProductPage/Aslowas.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ public function getProductId()
{
return $this->affirmPaymentHelper->getProduct()->getId();
}

public function getLearnMoreValue(){
return $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false';
}
}
10 changes: 10 additions & 0 deletions Helper/AsLowAs.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ public function getFinancingProgramValueALS(Product\Collection $productCollectio
return $this->getFinancingProgramDefault();
}
}

/**
* Is visible Learn more for ALA
*
* @return boolean
*/
public function isVisibleLearnmore()
{
return $this->affirmPaymentConfig->getAsLowAsValue('learn_more');
}
}
33 changes: 33 additions & 0 deletions Helper/Payment/Data.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
<?php
/**
*
* * BSD 3-Clause License
* *
* * Copyright (c) 2018, Affirm
* * All rights reserved.
* *
* * Redistribution and use in source and binary forms, with or without
* * modification, are permitted provided that the following conditions are met:
* *
* * Redistributions of source code must retain the above copyright notice, this
* * list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright notice,
* * this list of conditions and the following disclaimer in the documentation
* * and/or other materials provided with the distribution.
* *
* * Neither the name of the copyright holder nor the names of its
* * contributors may be used to endorse or promote products derived from
* * this software without specific prior written permission.
* *
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

namespace Astound\Affirm\Helper\Payment;
class Data extends \Magento\Payment\Helper\Data
Expand Down
Loading

0 comments on commit 7774c34

Please sign in to comment.