Skip to content

Commit

Permalink
fix issues with card and paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Oct 17, 2024
1 parent 818ba86 commit 0dc93db
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
15 changes: 13 additions & 2 deletions src/Controller/AccountSavedPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OxidSolutionCatalysts\Unzer\Traits\ServiceContainer;
use OxidEsales\Eshop\Core\Registry;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\PaymentTypes\Paypal as UnzerSDKPaypal;

class AccountSavedPaymentController extends AccountController
{
Expand Down Expand Up @@ -47,6 +48,11 @@ public function render()
return $this->_sThisTemplate;
}

/**
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function setPaymentListsToView(): void
{
$transactionService = $this->getServiceFromContainer(Transaction::class);
Expand All @@ -69,12 +75,17 @@ protected function setPaymentListsToView(): void
$currency,
$customerType
);

$paymentType = $unzerSDK->fetchPaymentType($paymentTypeId);
if (strpos($paymentTypeId, 'crd') && method_exists($paymentType, 'getBrand')) {
$paymentTypes[$paymentType->getBrand()][$transactionOxId] = $paymentType->expose();
}
if (strpos($paymentTypeId, 'ppl')) {
$paymentTypes['paypal'][$transactionOxId] = $paymentType->expose();
if (
strpos($paymentTypeId, 'ppl')
&& $paymentType instanceof UnzerSDKPaypal
&& !empty($paymentType->getEmail())
) {
$paymentTypes['paypal'][$transactionOxId] = $paymentType->expose();
}
if (strpos($paymentTypeId, 'sdd')) {
$paymentTypes['sepa'][$transactionOxId] = $paymentType->expose();
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentExtensions/UnzerPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function execute(
} catch (UnzerApiException $apiException) {
$customer = $this->unzerSDK->createCustomer($customer);
}
//first_transaction
//first_transaction
$transaction = $this->doTransactions($basketModel, $customer, $userModel, $paymentType);
$this->unzerService->setSessionVars($transaction);

Expand Down
11 changes: 8 additions & 3 deletions src/Service/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use UnzerSDK\Resources\Payment;
use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment;
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
use UnzerSDK\Resources\PaymentTypes\Paypal as UnzerSDKPaypal;
use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType;
use UnzerSDK\Resources\TransactionTypes\Cancellation;
use UnzerSDK\Resources\TransactionTypes\Charge;
Expand Down Expand Up @@ -630,10 +631,10 @@ public function getSavedPaymentsForUser(?User $user, array $ids, bool $cache): a
foreach ($ids as $typeData) {
$paymentTypes = null;
$paymentTypeId = $typeData['paymenttypeid'] ?: '';
if ($paymentTypeId) {
if ($paymentTypeId !== '') {
$paymentTypes = $this->setPaymentTypes(
$user,
$typeData['paymenttypeid'] ?: '',
$paymentTypeId,
$typeData['currency'] ?: '',
$typeData['customertype'] ?: '',
$paymentTypeId
Expand Down Expand Up @@ -690,7 +691,11 @@ private function setPaymentTypes(

foreach ($this->transPaymentTypeIds as $unzerId => $oxVar) {
if (strpos($paymentTypeId, $unzerId)) {
$result[$oxVar][$paymentTypeId] = $paymentType->expose();
if ($paymentType instanceof UnzerResourceCard && method_exists($paymentType, 'getBrand')) {
$result[$oxVar][$paymentType->getBrand()] = $paymentType->expose();
} elseif ($paymentType instanceof UnzerResourcePaypal && !empty($paymentType->getEmail())) {
$result[$oxVar]['paypal'] = $paymentType->expose();
}
}
}
return $result;
Expand Down
50 changes: 25 additions & 25 deletions views/twig/frontend/tpl/order/unzer_card.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
<div class="savedpayment">
{% for type, setting in unzerPaymentType %}
{% if type != 'paypal' and type != 'sepa' %}
<form id="payment-saved-cards" class="unzerUI form" novalidate>
<table class="table">
<thead>
<tr>
<th scope="col">{{ translate({ ident: "OSCUNZER_CARD_NUMBER" }) }}</th>
<th scope="col">{{ translate({ ident: "OSCUNZER_EXPIRY_DATE" }) }}</th>
<th scope="col">{{ translate({ ident: "OSCUNZER_BRAND" }) }}</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% set counter = 0 %}
{% for paymenttypeid, paymentType in setting %}
<form id="payment-saved-cards" class="unzerUI form" novalidate>
<table class="table">
<thead>
<tr>
<th scope="row">{{ paymentType.number }}</th>
<td>{{ paymentType.expiryDate }}</td>
<td>{{ type }}</td>

<td>
<input type="radio" class="paymenttypeid" name="paymenttypeid" value="{{ paymenttypeid }}" style="-webkit-appearance: radio">
</td>
<th scope="col">{{ translate({ ident: "OSCUNZER_CARD_NUMBER" }) }}</th>
<th scope="col">{{ translate({ ident: "OSCUNZER_EXPIRY_DATE" }) }}</th>
<th scope="col">{{ translate({ ident: "OSCUNZER_BRAND" }) }}</th>
<th scope="col"></th>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</thead>
<tbody>
{% set counter = 0 %}
{% for paymenttypeid, paymentType in setting %}
<tr>
<th scope="row">{{ paymentType.number }}</th>
<td>{{ paymentType.expiryDate }}</td>
<td>{{ type }}</td>

<td>
<input type="radio" class="paymenttypeid" name="paymenttypeid" value="{{ paymenttypeid }}" style="-webkit-appearance: radio">
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
{% endif %}
{% endfor %}
</div>
Expand All @@ -37,7 +37,7 @@
{% if unzerPaymentType != false %}
<br>
<label>
<input type="checkbox" name="newccard" id="newccard" value="show" style="-webkit-appearance: checkbox"> Neue Kreditkarte
<input type="checkbox" name="newccard" id="newccard" value="show" style="-webkit-appearance: checkbox">{{ translate({ ident: "OSCUNZER_NEW_CARD" }) }}
</label>
{% endif %}
<div id="newcc" style="display:none;" class="card-body">
Expand Down

0 comments on commit 0dc93db

Please sign in to comment.