Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #15 from heidelpay/develop
Browse files Browse the repository at this point in the history
Beta Release V 0.0.1
  • Loading branch information
Sascha authored Jun 30, 2020
2 parents a477c2a + 7b92d3f commit aff81ea
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ package:
only:
- tags
- master
- integration*
services:
- mysql:5.7
script:
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# HeidelPayment

Heidelpay payment integration for Shopware 6 including the following payment methods:
Heidelpay payment integration for Shopware 6.2 including the following payment methods:
* Credit Card
* SEPA direct debit
* Flexipay direct debit (secured)
* Prepayment
* Invoice
* FlexiPay® Invoice B2C / B2B (secured, factoring)
* FlexiPay® Direct
* SOFORT
* giropay
* EPS
* iDEAL
* PayPal
* Flexipay
* Alipay
* WeChat Pay


## Installation
### For production
Expand All @@ -27,8 +36,13 @@ This will automatically generate all files required for the plugin to work corre
After the actual plugin installation it is necessary to add the new payment methods to the desired sales channel.
Currently the only sales channel that is supported is the Storefront.

Further information and configuration you can find in the manual at https://dev.heidelpay.de/handbuch-shopware-ab-6-2-version-0-0-1/

## Troubleshooting

#### Known Issues
> This plugin is a beta-release. For all known issues please have a look at https://dev.heidelpay.de/handbuch-shopware-ab-6-2-version-0-0-1/#Known_issues
#### JavaScript does not load correctly in the storefront

> In this case it's required to run the command `./psh.phar storefront:build` manually in the shopware directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function mapPaymentStatus(Payment $paymentObject): string
} elseif ($paymentObject->isPartlyPaid()) {
$status = StateMachineTransitionActions::ACTION_PAID_PARTIALLY;
} elseif ($paymentObject->isPaymentReview() || $paymentObject->isCompleted()) {
$status = StateMachineTransitionActions::ACTION_PAID;
$status = StateMachineTransitionActions::ACTION_DO_PAY;
}

if ($this->isShipmentAllowed) {
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function checkForShipment(Payment $paymentObject, string $currentStatu
}

if ($shippedAmount === ($totalAmount - $cancelledAmount)) {
return StateMachineTransitionActions::ACTION_PAID;
return StateMachineTransitionActions::ACTION_DO_PAY;
}

if ($shippedAmount < ($totalAmount - $cancelledAmount)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function mapForAuthorizeMode(Payment $paymentObject): string
}

if (count($paymentObject->getCharges()) > 0) {
return StateMachineTransitionActions::ACTION_PAID;
return StateMachineTransitionActions::ACTION_DO_PAY;
}

return $this->checkForRefund($paymentObject, $this->mapPaymentStatus($paymentObject));
Expand Down
13 changes: 13 additions & 0 deletions src/Components/TransactionStateHandler/TransactionStateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ protected function executeTransition(string $transactionId, string $transition,
),
$context
);

// If the previous state is "paid_partially", "paid" is currently not allowed as direct transition
if ($transition === StateMachineTransitionActions::ACTION_DO_PAY) {
$this->stateMachineRegistry->transition(
new Transition(
OrderTransactionDefinition::ENTITY_NAME,
$transactionId,
StateMachineTransitionActions::ACTION_PAID,
'stateId'
),
$context
);
}
} catch (IllegalTransitionException $exception) {
// false positive handling (state to state) like open -> open, paid -> paid, etc.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ public function __construct(EntityRepositoryInterface $entityRepository, Address
/**
* {@inheritdoc}
*/
public function getCollectionByCustomer(CustomerEntity $customer, string $deviceType, Context $context): EntitySearchResult
public function getCollectionByCustomer(CustomerEntity $customer, Context $context, string $deviceType = null): EntitySearchResult
{
$addressHash = $this->addressHashService->generateHash($customer->getActiveBillingAddress(), $customer->getActiveShippingAddress());

$criteria = new Criteria();
$criteria->addFilter(
new EqualsFilter('heidelpay_payment_device.customerId', $customer->getId()),
new EqualsFilter('heidelpay_payment_device.addressHash', $addressHash),
new EqualsFilter('heidelpay_payment_device.deviceType', $deviceType)
new EqualsFilter('heidelpay_payment_device.addressHash', $addressHash)
);

if ($deviceType) {
$criteria->addFilter(new EqualsFilter('heidelpay_payment_device.deviceType', $deviceType));
}

return $this->entityRepository->search($criteria, $context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

interface HeidelpayPaymentDeviceRepositoryInterface
{
public function getCollectionByCustomer(CustomerEntity $customer, string $deviceType, Context $context): EntitySearchResult;
public function getCollectionByCustomer(CustomerEntity $customer, Context $context, string $deviceType = null): EntitySearchResult;

public function create(CustomerEntity $customer, string $deviceType, string $typeId, array $data, Context $context): EntityWrittenContainerEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,22 @@ public function onLoadAccountPaymentMethod(AccountPaymentMethodPageLoadedEvent $
$registerPayPal = $this->configReader->read($salesChannelId)->get(ConfigReader::CONFIG_KEY_REGISTER_PAYPAL, false);
$registerDirectDebit = $this->configReader->read($salesChannelId)->get(ConfigReader::CONFIG_KEY_REGISTER_DIRECT_DEBIT, false);
$extension = new PaymentMethodPageExtension();
$devices = $this->deviceRepository->getCollectionByCustomer($salesChannelContext->getCustomer(), $salesChannelContext->getContext());
$extension->setDeviceRemoved((bool) $event->getRequest()->get('deviceRemoved'));

if ($registerCreditCards && $salesChannelContext->getCustomer() !== null) {
$devices = $this->deviceRepository->getCollectionByCustomer($salesChannelContext->getCustomer(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_CREDIT_CARD, $salesChannelContext->getContext());
$creditCards = $devices->filterByProperty('deviceType', HeidelpayPaymentDeviceEntity::DEVICE_TYPE_CREDIT_CARD)->getElements();

$extension->addPaymentDevices($creditCards);
}

if ($registerPayPal && $salesChannelContext->getCustomer() !== null) {
$devices = $this->deviceRepository->getCollectionByCustomer($salesChannelContext->getCustomer(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_PAYPAL, $salesChannelContext->getContext());
$payPalAccounts = $devices->filterByProperty('deviceType', HeidelpayPaymentDeviceEntity::DEVICE_TYPE_PAYPAL)->getElements();

$extension->addPaymentDevices($payPalAccounts);
}

if ($registerDirectDebit && $salesChannelContext->getCustomer() !== null) {
$devices = $this->deviceRepository->getCollectionByCustomer($salesChannelContext->getCustomer(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT, $salesChannelContext->getContext());
$directDebitDevices = $devices->filterByProperty('deviceType', HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT)->getElements();
$directDebitGuaranteedDevices = $devices->filterByProperty('deviceType', HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT_GUARANTEED)->getElements();

Expand Down
8 changes: 4 additions & 4 deletions src/EventListeners/Checkout/ConfirmPageEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function addCreditCardExtension(PageLoadedEvent $event): void
return;
}

$creditCards = $this->deviceRepository->getCollectionByCustomer($customer, HeidelpayPaymentDeviceEntity::DEVICE_TYPE_CREDIT_CARD, $event->getContext());
$creditCards = $this->deviceRepository->getCollectionByCustomer($customer, $event->getContext(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_CREDIT_CARD);
$extension = (new CreditCardPageExtension())->setDisplayCreditCardSelection(true);

/** @var HeidelpayPaymentDeviceEntity $creditCard */
Expand All @@ -138,7 +138,7 @@ private function addPayPalExtension(PageLoadedEvent $event): void
return;
}

$payPalAccounts = $this->deviceRepository->getCollectionByCustomer($customer, HeidelpayPaymentDeviceEntity::DEVICE_TYPE_PAYPAL, $event->getContext());
$payPalAccounts = $this->deviceRepository->getCollectionByCustomer($customer, $event->getContext(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_PAYPAL);
$extension = (new PayPalPageExtension())->setDisplaypayPalAccountselection(true);

/** @var HeidelpayPaymentDeviceEntity $payPalAccount */
Expand All @@ -157,7 +157,7 @@ private function addDirectDebitExtension(PageLoadedEvent $event): void
return;
}

$directDebitDevices = $this->deviceRepository->getCollectionByCustomer($customer, HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT, $event->getContext());
$directDebitDevices = $this->deviceRepository->getCollectionByCustomer($customer, $event->getContext(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT);
$extension = (new DirectDebitPageExtension())->setDisplayDirectDebitDeviceSelection(true);

/** @var HeidelpayPaymentDeviceEntity $directDebitDevice */
Expand All @@ -176,7 +176,7 @@ private function addDirectDebitGuaranteedExtension(PageLoadedEvent $event): void
return;
}

$directDebitDevices = $this->deviceRepository->getCollectionByCustomer($customer, HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT_GUARANTEED, $event->getContext());
$directDebitDevices = $this->deviceRepository->getCollectionByCustomer($customer, $event->getContext(), HeidelpayPaymentDeviceEntity::DEVICE_TYPE_DIRECT_DEBIT_GUARANTEED);
$extension = (new DirectDebitGuaranteedPageExtension())->setDisplayDirectDebitDeviceSelection(true);

/** @var HeidelpayPaymentDeviceEntity $directDebitDevice */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% block heidelpay_frame_paypal_account %}
{% block heidelpay_checkout_confirm_frame_card_body_title %}
<div class="card-title">
{{ context.paymentMethod.translated.name }}
</div>
{% endblock %}
{% if page.extensions.heidelpayPayPal.displayPayPalAccountSelection and page.extensions.heidelpayPayPal.payPalAccounts|length > 0 %}
{% block heidelpay_checkout_confirm_frame_card_body_title %}
<div class="card-title">
{{ context.paymentMethod.translated.name }}
</div>
{% endblock %}

{% if page.extensions.heidelpayPayPal.displayPayPalAccountSelection %}
<div class="heidelpay-paypal-account-wrapper"
data-heidelpay-paypal="true"
data-heidelpay-paypal-options='{
Expand All @@ -15,22 +15,20 @@
<div class="heidelpay-saved-accounts--message">
{{ "HeidelPayment.frame.paypal.choose"|trans }}
</div>
{% if page.extensions.heidelpayPayPal.payPalAccounts|length > 0 %}
{% block heidelpay_frame_paypal_account_saved_device %}
{# @var payPalAccount \HeidelPayment6\DataAbstractionLayer\Entity\PaymentDevice\HeidelpayPaymentDeviceEntity #}
{% for payPalAccount in page.extensions.heidelpayPayPal.payPalAccounts %}
<div class="custom-control custom-radio payment-control">
<input type="radio" value="{{ payPalAccount.typeId }}" name="savedPayPalAccount"
id="account-{{ payPalAccount.id }}"
class="custom-control-input payment-method-input"{% if loop.first %} checked="checked"{% endif %}>
<label for="account-{{ payPalAccount.id }}"
class="custom-control-label payment-method-label">
<strong>{{ payPalAccount.data['email'] }}</strong>
</label>
</div>
{% endfor %}
{% endblock %}
{% endif %}
{% block heidelpay_frame_paypal_account_saved_device %}
{# @var payPalAccount \HeidelPayment6\DataAbstractionLayer\Entity\PaymentDevice\HeidelpayPaymentDeviceEntity #}
{% for payPalAccount in page.extensions.heidelpayPayPal.payPalAccounts %}
<div class="custom-control custom-radio payment-control">
<input type="radio" value="{{ payPalAccount.typeId }}" name="savedPayPalAccount"
id="account-{{ payPalAccount.id }}"
class="custom-control-input payment-method-input"{% if loop.first %} checked="checked"{% endif %}>
<label for="account-{{ payPalAccount.id }}"
class="custom-control-label payment-method-label">
<strong>{{ payPalAccount.data['email'] }}</strong>
</label>
</div>
{% endfor %}
{% endblock %}

{% block heidelpay_frame_paypal_account_saved_device_new %}
<div class="custom-control custom-radio payment-control">
Expand Down

0 comments on commit aff81ea

Please sign in to comment.