Skip to content

Commit

Permalink
Release 1.1.15
Browse files Browse the repository at this point in the history
  • Loading branch information
vttn committed Jul 24, 2020
1 parent c5badc3 commit 55f4e5a
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.15
- Send customer first name and last name from billing and shipping profiles
- Respect Shop URL

# 1.1.14
- Add cookies to the cookie manager
- Resize icon to 40px * 40px
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ account dashboard.

## Documentation

[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/1.1.14/docs/en/documentation.html)
[Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/shopware-6/1.1.15/docs/en/documentation.html)

## License

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"postfinancecheckout/sdk": "2.1.0"
},
"type": "shopware-platform-plugin",
"version": "1.1.14"
"version": "1.1.15"
}
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/shopware-6/releases/tag/1.1.14/">
<a href="https://github.com/pfpayments/shopware-6/releases/tag/1.1.15/">
Source
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Api/Transaction/Service/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class TransactionService {

/**
* TransactionService constructor.
*
* @param \Psr\Container\ContainerInterface $container
* @param \PostFinanceCheckoutPayment\Core\Util\LocaleCodeProvider $localeCodeProvider
* @param \PostFinanceCheckoutPayment\Core\Settings\Service\SettingsService $settingsService
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
ContainerInterface $container,
Expand Down
15 changes: 12 additions & 3 deletions src/Core/Storefront/Checkout/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
Page\Checkout\Finish\CheckoutFinishPage,
Page\GenericPageLoader,};
use Symfony\Component\{
HttpFoundation\JsonResponse,
HttpFoundation\Request,
HttpFoundation\Response,
Routing\Annotation\Route};
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use PostFinanceCheckout\Sdk\{
Model\Transaction,
Model\TransactionPending,
Model\TransactionState};
use PostFinanceCheckoutPayment\Core\{
Api\Transaction\Service\TransactionService,
Expand Down Expand Up @@ -186,7 +185,17 @@ public function pay(SalesChannelContext $salesChannelContext, Request $request):
->setIntegration($this->settings->getIntegration())
->setJavascriptUrl($javascriptUrl)
->setDeviceJavascriptUrl($this->settings->getSpaceId(), $this->container->get('session')->getId())
->setTransactionPossiblePaymentMethods($possiblePaymentMethods);
->setTransactionPossiblePaymentMethods($possiblePaymentMethods)
->setCheckoutUrl($this->generateUrl(
'frontend.postfinancecheckout.checkout.pay',
['orderId' => $orderId,],
UrlGeneratorInterface::ABSOLUTE_URL
))
->setCartRecreateUrl($this->generateUrl(
'frontend.postfinancecheckout.checkout.recreate-cart',
['orderId' => $orderId,],
UrlGeneratorInterface::ABSOLUTE_URL
));

$page->addExtension('postFinanceCheckoutData', $checkoutPageData);

Expand Down
51 changes: 46 additions & 5 deletions src/Core/Storefront/Checkout/Struct/CheckoutPageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,77 @@
* @package PostFinanceCheckoutPayment\Storefront\Checkout\Struct
*/
class CheckoutPageData extends Struct {

/**
* @var string
*/
protected $deviceJavascriptUrl;
protected $cartRecreateUrl;

/**
* @var string
*/
protected $checkoutUrl;
/**
* @var string
*/
protected $deviceJavascriptUrl;
/**
* @var string
*/
protected $integration;

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

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

/**
* @var array
*/
protected $possiblePaymentMethodsArray = [];

/**
* @var array
*/
protected $transactionPossiblePaymentMethods = [];

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

/**
* @param string $cartRecreateUrl
* @return CheckoutPageData
*/
public function setCartRecreateUrl(string $cartRecreateUrl): CheckoutPageData
{
$this->cartRecreateUrl = $cartRecreateUrl;
return $this;
}

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

/**
* @param string $checkoutUrl
* @return CheckoutPageData
*/
public function setCheckoutUrl(string $checkoutUrl): CheckoutPageData
{
$this->checkoutUrl = $checkoutUrl;
return $this;
}

/**
* @return string
*/
Expand Down
50 changes: 46 additions & 4 deletions src/Core/Util/Payload/TransactionPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,59 @@ protected function getAdjustmentLineItem(array &$lineItems): ?LineItemCreate
*/
protected function getAddressPayload(CustomerEntity $customer, CustomerAddressEntity $customerAddressEntity): AddressCreate
{
// Family name
$family_name = null;
if (!empty($customerAddressEntity->getLastName())) {
$family_name = $customerAddressEntity->getLastName();
} else {
if (!empty($customer->getLastName())) {
$family_name = $customer->getLastName();
}
}
$family_name = !empty($family_name) ? $this->fixLength($family_name, 100) : null;

// Given name
$given_name = null;
if (!empty($customerAddressEntity->getFirstName())) {
$given_name = $customerAddressEntity->getFirstName();
} else if (!empty($customer->getFirstName())) {
$given_name = $customer->getFirstName();
}
$given_name = !empty($given_name) ? $this->fixLength($given_name, 100) : null;

// Organization name
$organization_name = null;
if (!empty($customerAddressEntity->getCompany())) {
$organization_name = $customerAddressEntity->getCompany();
} else if (!empty($customer->getCompany())) {
$organization_name = $customer->getCompany();
}
$organization_name = !empty($organization_name) ? $this->fixLength($organization_name, 100) : null;

// Salutation
$salutation = null;
if (!(
empty($customerAddressEntity->getSalutation()) ||
empty($customerAddressEntity->getSalutation()->getDisplayName())
)) {
$salutation = $customerAddressEntity->getSalutation()->getDisplayName();
} else if (!empty($customer->getSalutation())) {
$salutation = $customer->getSalutation()->getDisplayName();

}
$salutation = !empty($salutation) ? $this->fixLength($salutation, 20) : null;

$addressData = [
'city' => $customerAddressEntity->getCity() ? $this->fixLength($customerAddressEntity->getCity(), 100) : null,
'country' => $customerAddressEntity->getCountry() ? $customerAddressEntity->getCountry()->getIso() : null,
'email_address' => $customer->getEmail() ? $this->fixLength($customer->getEmail(), 254) : null,
'family_name' => $customer->getLastName() ? $this->fixLength($customer->getLastName(), 100) : null,
'given_name' => $customer->getFirstName() ? $this->fixLength($customer->getFirstName(), 100) : null,
'organization_name' => $customer->getCompany() ? $this->fixLength($customer->getCompany(), 100) : null,
'family_name' => $family_name,
'given_name' => $given_name,
'organization_name' => $organization_name,
'phone_number' => $customerAddressEntity->getPhoneNumber() ? $this->fixLength($customerAddressEntity->getPhoneNumber(), 100) : null,
'postcode' => $customerAddressEntity->getZipcode() ? $this->fixLength($customerAddressEntity->getZipcode(), 40) : null,
'postal_state' => $customerAddressEntity->getCountryState() ? $customerAddressEntity->getCountryState()->getShortCode() : null,
'salutation' => $customer->getSalutation() ? $this->fixLength($customer->getSalutation()->getDisplayName(), 20) : null,
'salutation' => $salutation,
'street' => $customerAddressEntity->getStreet() ? $this->fixLength($customerAddressEntity->getStreet(), 300) : null,
];

Expand Down
42 changes: 14 additions & 28 deletions src/Resources/public/storefront/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
payment_method_handler_status: 'input[name="postfinancecheckout_payment_handler_validation_status"]',
payment_form_id: 'confirmOrderForm',
button_cancel_id: 'postfinancecheckoutOrderCancel',
order_id: '',
loader_id: 'postfinancecheckoutLoader',
pay_url: '/postfinancecheckout/checkout/pay?orderId=',
recreate_cart_url: '/postfinancecheckout/checkout/recreate-cart?orderId=',
checkout_url: null,
checkout_url_id: 'checkoutUrl',
cart_recreate_url: null,
cart_recreate_url_id: 'cartRecreateUrl',
handler: null,

/**
* Initialize plugin
*/
init: function () {
PostFinanceCheckoutCheckout.activateLoader(true);
this.order_id = this.getParameterByName('orderId');
this.pay_url += this.order_id;
this.recreate_cart_url += this.order_id;
this.checkout_url = document.getElementById(this.checkout_url_id).value;
this.cart_recreate_url = document.getElementById(this.cart_recreate_url_id).value;

document.getElementById(this.button_cancel_id).addEventListener('click', this.recreateCart, false);
document.getElementById(this.payment_form_id).addEventListener('submit', this.submitPayment, false);
Expand All @@ -64,7 +64,7 @@
},

recreateCart: function (e) {
window.location.href = PostFinanceCheckoutCheckout.recreate_cart_url;
window.location.href = PostFinanceCheckoutCheckout.cart_recreate_url;
e.preventDefault();
},

Expand Down Expand Up @@ -159,24 +159,6 @@
if (errorElement) {
errorElement.parentNode.removeChild(errorElement);
}
},

/**
* Get query name value
*
* @param name
* @param url
* @link https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
* @return {*}
*/
getParameterByName: function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
};

Expand All @@ -189,13 +171,17 @@
*/
window.addEventListener('load', function (e) {
PostFinanceCheckoutCheckout.init();
window.history.pushState({}, document.title, PostFinanceCheckoutCheckout.recreate_cart_url);
window.history.pushState({}, document.title, PostFinanceCheckoutCheckout.pay_url);
window.history.pushState({}, document.title, PostFinanceCheckoutCheckout.cart_recreate_url);
window.history.pushState({}, document.title, PostFinanceCheckoutCheckout.checkout_url);
}, false);

/**
* This only works if the user has interacted with the page
* @link https://stackoverflow.com/questions/57339098/chrome-popstate-not-firing-on-back-button-if-no-user-interaction
*/
window.addEventListener('popstate', function (e) {
if (window.history.state == null) { // This means it's page load
return;
}
window.location.href = PostFinanceCheckoutCheckout.recreate_cart_url;
window.location.href = PostFinanceCheckoutCheckout.cart_recreate_url;
}, false);
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
{% block page_checkout_aside_actions %}
<div class="checkout-aside-action">
<form name="confirmOrderForm" id="confirmOrderForm">
<input type="hidden" id="cartRecreateUrl" value="{{ page.extensions.postFinanceCheckoutData.cartRecreateUrl }}" />
<input type="hidden" id="checkoutUrl" value="{{ page.extensions.postFinanceCheckoutData.checkoutUrl }}" />
<button id="confirmFormSubmit"
class="btn btn-primary btn-block btn-lg"
form="confirmOrderForm"
Expand Down

0 comments on commit 55f4e5a

Please sign in to comment.