-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add blink input field and capture its data inside of action
- Loading branch information
Showing
9 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer; | ||
|
||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
class PaymentDetailsTransformer implements DataTransformerInterface | ||
{ | ||
public function transform($value): string | ||
{ | ||
if (!$value || !array_key_exists('blik', $value)) { | ||
return ''; | ||
} | ||
|
||
return $value['blik']; | ||
} | ||
public function reverseTransform($value): array | ||
{ | ||
return ['blik' => $value]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Form\Type; | ||
|
||
use Sylius\Bundle\CoreBundle\Form\Type\Checkout\CompleteType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class CompleteTypeExtension extends AbstractTypeExtension | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->add('notes', TextareaType::class, [ | ||
'label' => 'sylius.form.notes', | ||
'required' => false, | ||
]); | ||
|
||
$builder->add('others', PaymentDetailsType::class, [ | ||
'label' => 'commerce_weavers_sylius_tpay.payment.blik.token', | ||
// TODO missing validation | ||
'property_path' => 'payments[0].details', // TODO looks awfull and what about other payments? | ||
// 'mapped' => false, | ||
'required' => false, | ||
]); | ||
} | ||
|
||
public static function getExtendedTypes(): iterable | ||
{ | ||
return [CompleteType::class]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Form\Type; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer\PaymentDetailsTransformer; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class PaymentDetailsType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->addModelTransformer(new PaymentDetailsTransformer()); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return TextType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateBlik0Transaction; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Tpay\OpenApi\Api\TpayApi; | ||
|
||
/** | ||
* @property TpayApi $api | ||
*/ | ||
final class CreateBlik0TransactionAction extends BaseApiAwareAction | ||
{ | ||
/** | ||
* @param CreateTransaction $request | ||
*/ | ||
public function execute($request): void | ||
{ | ||
/** @var PaymentInterface $model */ | ||
$model = $request->getModel(); | ||
$details = $model->getDetails(); | ||
|
||
$order = $model->getOrder(); | ||
$customer = $order->getCustomer(); | ||
$billingAddress = $order->getBillingAddress(); | ||
|
||
$blikToken = $model->getDetails()['blik']; | ||
|
||
$response = $this->api->transactions()->createTransaction([ | ||
'amount' => number_format($model->getAmount() / 100, 2, thousands_separator: ''), | ||
'description' => sprintf('zamówienie #%s', $order->getNumber()), // TODO: Introduce translations | ||
'payer' => [ | ||
'email' => $customer->getEmail(), | ||
'name' => $billingAddress->getFullName(), | ||
], | ||
'pay' => [ | ||
'groupId' => 150, | ||
'blikPaymentData' => [ | ||
'blikToken' => $blikToken, | ||
], | ||
], | ||
'callbacks' => [ | ||
'payerUrls' => [ | ||
'success' => $request->getAfterUrl(), | ||
'error' => $request->getAfterUrl(), | ||
], | ||
], | ||
]); | ||
|
||
// blik token could be removed here from $details | ||
$details['tpay']['transaction_id'] = $response['transactionId']; | ||
|
||
$model->setDetails($details); | ||
} | ||
|
||
public function supports($request): bool | ||
{ | ||
return $request instanceof CreateBlik0Transaction && $request->getModel() instanceof PaymentInterface; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api; | ||
|
||
use Payum\Core\Request\Generic; | ||
|
||
class CreateBlik0Transaction extends Generic | ||
{ | ||
public function __construct ( | ||
private string $afterUrl, | ||
mixed $model, | ||
) { | ||
parent::__construct($model); | ||
} | ||
|
||
public function getAfterUrl(): string | ||
{ | ||
return $this->afterUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters