Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into MAG2-283-BNPL-categ…
Browse files Browse the repository at this point in the history
…ory-url
  • Loading branch information
andrepayone committed Aug 31, 2023
2 parents d93d0de + a399a75 commit fe0ade5
Show file tree
Hide file tree
Showing 74 changed files with 1,789 additions and 867 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_magento23.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, gd, bcmath, ctype, curl, dom, hash, iconv, intl, openssl, simplexml, soap, xsl, zip
tools: composer:v2.1
tools: composer:v1.8
- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/build_magento246php82.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build and Test with PHP 8.2 and Magento 2.6

on: [push, pull_request, workflow_dispatch]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 15
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2']
magento-versions: ['2.4.6']

services:
mysql:
image: mysql:8.0.20
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306

steps:
- uses: actions/checkout@v3
- name: Install PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, gd, bcmath, ctype, curl, dom, hash, iconv, intl, openssl, simplexml, soap, xsl, zip
tools: composer:v2.1
- name: Validate composer.json and composer.lock
run: composer validate

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: PHP Syntax Checker
run: find . -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )

- name: Setup Magento 2 and run tests
run: |
mysql -u root --password=root -h 127.0.0.1 -e 'CREATE DATABASE IF NOT EXISTS magento;'
git clone --depth=1 -b ${{ matrix.magento-versions }} https://github.com/magento/magento2 /tmp/build
cd /tmp/build
composer update
php bin/magento setup:install --base-url=http://magebuild.integrations.p1-test.de/build/ \
--db-host=127.0.0.1 --db-name=magento --db-user=root --db-password=root --admin-firstname=Dieter \
--admin-lastname=Demo [email protected] --admin-user=DieterDemo \
--admin-password=72q980hdfq2378ga9w87dg6 --language=de_DE --currency=EUR --timezone=Europe/Berlin \
--disable-modules=Magento_Elasticsearch7,Magento_Elasticsearch,Magento_OpenSearch
composer require --ignore-platform-reqs payone-gmbh/magento-2 dev-master
rm -rf /tmp/build/vendor/payone-gmbh/magento-2/*
cp -R $GITHUB_WORKSPACE/* /tmp/build/vendor/payone-gmbh/magento-2
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean
sed -i 's+>allure/allure.config.php<+>dev/tests/unit/allure/allure.config.php<+g' dev/tests/unit/phpunit.xml.dist
./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/payone-gmbh/magento-2/Test/Unit
2 changes: 1 addition & 1 deletion .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: gitleaks-action
uses: gitleaks/[email protected].0
uses: FatchipRobert/[email protected].1
10 changes: 5 additions & 5 deletions Block/BNPL/InstallmentPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public function formatPrice($dPrice)
*/
public function getSelectLinkText($aInstallment)
{
$sText = $this->formatPrice($aInstallment['monthly_amount_value']).' ';
$sText .= $aInstallment['monthly_amount_currency'].' ';
$sText .= __('per month').' - ';
$sText .= $aInstallment['number_of_payments'].' ';
$sText .= __('installments');
$sText = __('Payment in');
$sText .= ' '.$aInstallment['number_of_payments'].' ';
$sText .= __('installments of').' ';
$sText .= $this->formatPrice($aInstallment['monthly_amount_value']).' ';
$sText .= $aInstallment['monthly_amount_currency'];
return $sText;
}
}
188 changes: 188 additions & 0 deletions Block/Form/RatepayInvoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace Payone\Core\Block\Form;

use Payone\Core\Model\PayoneConfig;

class RatepayInvoice extends Base
{
/**
* @var \Magento\Sales\Model\AdminOrder\Create
*/
protected $orderCreate;

/**
* @var \Payone\Core\Helper\Ratepay
*/
protected $ratepayHelper;

/**
* @var array|null
*/
protected $ratepayConfig = null;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Sales\Model\AdminOrder\Create $orderCreate
* @param \Payone\Core\Helper\Ratepay $ratepayHelper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
\Payone\Core\Helper\Ratepay $ratepayHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->orderCreate = $orderCreate;
$this->ratepayHelper = $ratepayHelper;
}

/**
* Retrieve create order model object
*
* @return \Magento\Quote\Model\Quote
*/
public function getQuote()
{
return $this->orderCreate->getQuote();
}

/**
* Tries to determine a matching ratepay configuration
*
* @return array
*/
public function getRatepayConfig()
{
if ($this->ratepayConfig === null) {
$this->ratepayConfig = $this->ratepayHelper->getRatepaySingleConfig(PayoneConfig::METHOD_RATEPAY_INVOICE, $this->getQuote());
}
return $this->ratepayConfig;
}

/**
* Returns snippet id from config
*
* @return string
*/
public function getDevicefingerprintSnippetId()
{
return $this->ratepayHelper->getConfigParam('devicefingerprint_snippet_id', 'ratepay', 'payone_misc');
}

/**
* Returns token generated by Ratepay helper
*
* @return string
*/
public function getDevicefingerprintToken()
{
return $this->ratepayHelper->getRatepayDeviceFingerprintToken();
}

/**
* Returns if birthday has to be entered
*
* @return bool
*/
public function isBirthdayNeeded()
{
if ($this->isB2BMode() === true) {
return false;
}
return true;
}

/**
* Return if customer has entered a company name in his billing address
*
* @return bool
*/
public function isB2BMode()
{
$billingAddress = $this->getQuote()->getBillingAddress();
if ($billingAddress && !empty($billingAddress->getCompany())) {
return true;
}
return false;
}

/**
* Return if ratepay config allows B2B mode
*
* @return bool
*/
public function isB2BModeAllowed()
{
$aConfig = $this->getRatepayConfig();
if (isset($aConfig['b2bAllowed'])) {
return (bool)$aConfig['b2bAllowed'];
}
return false;
}

/**
* Return if ratepay config allows differing delivery addresses
*
* @return bool
*/
public function isDifferingDeliveryAddressAllowed()
{
$aConfig = $this->getRatepayConfig();
if (isset($aConfig['differentAddressAllowed'])) {
return (bool)$aConfig['differentAddressAllowed'];
}
return false;
}

/**
* Returns if billing address is different as shipping address
*
* @return true
*/
public function hasDifferingDeliveryAddress()
{
return !$this->getQuote()->getShippingAddress()->getSameAsBilling();
}

/**
* Returns the customers birthday if known
*
* @return string
*/
public function getBirthday()
{
return $this->getQuote()->getCustomer()->getDob();
}

/**
* Returns a part of the birthday (day, month or year)
*
* @param string $sPart
* @return string
*/
public function getBirthdayPart($sPart)
{
$sBirthday = $this->getBirthday();
if (!empty($sBirthday)) {
$timestamp = strtotime($sBirthday);
return date($sPart, $timestamp);
}
return '';
}

/**
* Returns if the telephone number has to be entered
*
* @return bool
*/
public function isTelephoneNeeded()
{
$billingAddress = $this->getQuote()->getBillingAddress();
if ($billingAddress && !empty($billingAddress->getTelephone())) {
return false;
}
return true;
}
}
5 changes: 5 additions & 0 deletions Controller/Amazon/LoadReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class LoadReview extends \Magento\Framework\App\Action\Action
*/
protected $confirmOrderReference;

/**
* @var \Payone\Core\Model\Api\Request\Genericpayment\CancelOrderReference
*/
protected $cancelOrderReference;

/**
* Amazon Pay payment object
*
Expand Down
55 changes: 37 additions & 18 deletions Controller/Onepage/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,31 @@ class PlaceOrder extends \Magento\Framework\App\Action\Action
*/
protected $cartManagement;

/**
* Payone checkout helper
*
* @var \Payone\Core\Helper\Checkout
*/
protected $checkoutHelper;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Quote\Api\CartManagementInterface $cartManagement
* @param \Payone\Core\Helper\Checkout $checkoutHelper
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementValidator,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Quote\Api\CartManagementInterface $cartManagement
\Magento\Quote\Api\CartManagementInterface $cartManagement,
\Payone\Core\Helper\Checkout $checkoutHelper
) {
$this->agreementsValidator = $agreementValidator;
$this->checkoutSession = $checkoutSession;
$this->cartManagement = $cartManagement;
$this->checkoutHelper = $checkoutHelper;
parent::__construct($context);
}

Expand All @@ -86,7 +96,30 @@ public function execute()
}

try {
$this->placeOrder();
$oQuote = $this->checkoutSession->getQuote();

if ($this->checkoutHelper->getQuoteComparisonString($oQuote) != $this->checkoutSession->getPayoneQuoteComparisonString()) {
// The basket was changed - abort current checkout
$this->messageManager->addErrorMessage('An error occured during the Checkout.');
$this->_redirect('checkout/cart');
return;
}

$this->placeOrder($oQuote);

$sPayoneRedirectUrl = $this->checkoutSession->getPayoneRedirectUrl();
if (!empty($sPayoneRedirectUrl)) {
$this->checkoutSession->setPayoneCustomerIsRedirected(true);
$this->checkoutSession->setPayonePayPalExpressRetry(true);
$this->_redirect($sPayoneRedirectUrl);
return;
}

// "last successful quote"
$sQuoteId = $oQuote->getId();
$this->checkoutSession->setLastQuoteId($sQuoteId)->setLastSuccessQuoteId($sQuoteId)->unsPayoneWorkorderId()->unsIsPayonePayPalExpress()->unsPayoneUserAgent()->unsPayoneDeviceFingerprint();

$oQuote->setIsActive(false)->save();

$this->_redirect('checkout/onepage/success');
} catch (\Exception $e) {
Expand All @@ -101,19 +134,11 @@ public function execute()
/**
* Place the order and put it in a finished state
*
* @param Magento\Quote\Model\Quote $oQuote
* @return void
*/
protected function placeOrder()
protected function placeOrder($oQuote)
{
$oQuote = $this->checkoutSession->getQuote();

if ($oQuote->getSubtotal() != $this->checkoutSession->getPayoneGenericpaymentSubtotal()) {
// The basket was changed - abort current checkout
$this->messageManager->addErrorMessage('An error occured during the Checkout.');
$this->_redirect('checkout/cart');
return;
}

$oQuote->getBillingAddress()->setShouldIgnoreValidation(true);
if (!$oQuote->getIsVirtual()) {
$oQuote->getShippingAddress()->setShouldIgnoreValidation(true);
Expand All @@ -129,12 +154,6 @@ protected function placeOrder()
}

$this->cartManagement->placeOrder($oQuote->getId());

// "last successful quote"
$sQuoteId = $oQuote->getId();
$this->checkoutSession->setLastQuoteId($sQuoteId)->setLastSuccessQuoteId($sQuoteId)->unsPayoneWorkorderId()->unsIsPayonePayPalExpress()->unsPayoneUserAgent()->unsPayoneDeviceFingerprint();

$oQuote->setIsActive(false)->save();
}

/**
Expand Down
Loading

0 comments on commit fe0ade5

Please sign in to comment.