-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single page payment #150
Open
SirDomin
wants to merge
10
commits into
Sylius:1.7
Choose a base branch
from
SirDomin:single-page-payment
base: 1.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+432
−547
Open
Single page payment #150
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fc1d499
render payment buttons
SirDomin 3e8c9ad
payment with cards and paypal supported on single page
SirDomin e11b26f
removed unused controller
SirDomin 6ca0aee
cancel payment
SirDomin 76e8962
removed unused service
SirDomin c9e2ffc
handle error delay
SirDomin 57d62d3
Justify on center full-width PayPal button
Zales0123 02a8c04
Handle order completion after checkout properly
Zales0123 6f72e02
Identify completed order by PayPal order id rather than autoincrement…
Zales0123 4c0c12f
CS fixes
Zales0123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,11 +4,16 @@ | |
|
||
namespace Sylius\PayPalPlugin\Controller; | ||
|
||
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; | ||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface; | ||
use Sylius\PayPalPlugin\Api\IdentityApiInterface; | ||
use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface; | ||
use Sylius\PayPalPlugin\Provider\AvailableCountriesProviderInterface; | ||
use Sylius\PayPalPlugin\Provider\PayPalConfigurationProviderInterface; | ||
|
@@ -43,6 +48,12 @@ final class PayPalButtonsController | |
/** @var LocaleProcessorInterface */ | ||
private $localeProcessor; | ||
|
||
/** @var CacheAuthorizeClientApiInterface */ | ||
private $authorizeClientApi; | ||
|
||
/** @var IdentityApiInterface */ | ||
private $identityApi; | ||
|
||
public function __construct( | ||
Environment $twig, | ||
UrlGeneratorInterface $router, | ||
|
@@ -51,7 +62,9 @@ public function __construct( | |
PayPalConfigurationProviderInterface $payPalConfigurationProvider, | ||
OrderRepositoryInterface $orderRepository, | ||
AvailableCountriesProviderInterface $availableCountriesProvider, | ||
LocaleProcessorInterface $localeProcessor | ||
LocaleProcessorInterface $localeProcessor, | ||
CacheAuthorizeClientApiInterface $authorizeClientApi, | ||
IdentityApiInterface $identityApi | ||
) { | ||
$this->twig = $twig; | ||
$this->router = $router; | ||
|
@@ -61,6 +74,8 @@ public function __construct( | |
$this->orderRepository = $orderRepository; | ||
$this->availableCountriesProvider = $availableCountriesProvider; | ||
$this->localeProcessor = $localeProcessor; | ||
$this->authorizeClientApi = $authorizeClientApi; | ||
$this->identityApi = $identityApi; | ||
} | ||
|
||
public function renderProductPageButtonsAction(Request $request): Response | ||
|
@@ -135,4 +150,39 @@ public function renderPaymentPageButtonsAction(Request $request): Response | |
return new Response(''); | ||
} | ||
} | ||
|
||
public function renderPayPalPaymentAction(Request $request): Response | ||
{ | ||
$orderId = $request->attributes->getInt('orderId'); | ||
/** @var OrderInterface $order */ | ||
$order = $this->orderRepository->find($orderId); | ||
/** @var PaymentInterface $payment */ | ||
$payment = $order->getLastPayment(); | ||
/** @var PaymentMethodInterface $paymentMethod */ | ||
$paymentMethod = $payment->getMethod(); | ||
/** @var GatewayConfigInterface $gatewayConfig */ | ||
$gatewayConfig = $paymentMethod->getGatewayConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are so many places where we get data from the gateway config :/ We should definitely extract some service for that (but, of course, not in this PR 🖖) |
||
/** @var string $clientId */ | ||
$clientId = $gatewayConfig->getConfig()['client_id']; | ||
/** @var string $partnerAttributionId */ | ||
$partnerAttributionId = $gatewayConfig->getConfig()['partner_attribution_id']; | ||
|
||
/** @var OrderInterface $order */ | ||
$order = $payment->getOrder(); | ||
|
||
$token = $this->authorizeClientApi->authorize($paymentMethod); | ||
$clientToken = $this->identityApi->generateToken($token); | ||
|
||
return new Response($this->twig->render('@SyliusPayPalPlugin/payWithPaypal.html.twig', [ | ||
'available_countries' => $this->availableCountriesProvider->provide(), | ||
'billing_address' => $order->getBillingAddress(), | ||
'client_id' => $clientId, | ||
'client_token' => $clientToken, | ||
'currency' => $order->getCurrencyCode(), | ||
'locale' => $this->localeProcessor->process((string) $order->getLocaleCode()), | ||
'merchant_id' => $gatewayConfig->getConfig()['merchant_id'], | ||
'order_id' => $order->getId(), | ||
'partner_attribution_id' => $partnerAttributionId, | ||
])); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
src/Resources/views/bundles/SyliusShopBundle/Checkout/Complete/_navigation.html.twig
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,7 @@ | ||
{% if order.lastPayment.method.gatewayConfig.factoryName == 'sylius.pay_pal' and order.lastPayment.state == 'cart' %} | ||
{{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController:renderPayPalPaymentAction', {'orderId': order.id})) }} | ||
{% else %} | ||
<button type="submit" class="ui huge primary fluid icon labeled button" {{ sylius_test_html_attribute('confirmation-button') }}> | ||
<i class="check icon"></i> {{ 'sylius.ui.place_order'|trans }} | ||
</button> | ||
{% endif %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of the "no verification at all" to who is the owner of the order. Changing the
orderId
in the request could lead to some issues here. Is it right?