-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Multiple payments support. #1203
Conversation
👍 |
|
This is how I always imagined multiple payment support.
Some random thoughts about recurring payments and remembering payment methods.
I can assure you that all this is possible, because I implemented it in Sylius app already. (just not the way I'd like it to be in core - quality, coupling) Thoughts? |
Why not bidirectional? It is very useful to be able to access order payments without injecting a repository.
Did you mean
What do you think about this PR? #1131
I agree it is redundant, I was just copying shipments' implementation here. Will make the changes @pjedrzejewski suggested.. |
Thanks for starting on this @kayue, you're awesome! |
@pjedrzejewski I am not sure is this can work. At the moment, a new payment is created every time customer visit Payment Step. This means there are multiple payment associated with order already (just missing the linkage). All of these payment state are Are we going to change this behaviour? |
@pjedrzejewski Just a reminder, we cannot rely on payment state |
|
@pjedrzejewski Yes. Can I do front-end in another PR because it is a lot more complex, and it is not a must have. Multi-payment can still be useful in backend when it comes to order refund: #1202 What do you think? |
if (!$this->hasPayment($payment)) { | ||
$payment->setOrder($this); | ||
$this->payments->add($payment); | ||
} |
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.
Can you make this fluid please? Same with the next method.
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.
@Richtermeister Fluid? what does it means?
@kayue what is the status on this? :) |
@winzou Not much, there was too many changes happening in Sylius in the past few weeks, and I wasn't able to adopt them to my project yet. Feel free to work on this if you wish. |
I'm currently upgrading my sylius, and it's actually quite smooth! Alexandre Bacco +65 8671 7859 On Mon, Apr 14, 2014 at 4:20 PM, Ka Yue Yeung notifications@github.comwrote:
|
Let me give this a 2nd try this weekend |
@pjedrzejewski Will you accept if I only deprecated the public function getPayment()
{
return $this->getPayments()->last();
} Removing Can I only focus on creating 1:n order payment relationship here? |
@pjedrzejewski @winzou What do you guys think? In order to support real multiple payment like you said ("loop through payments until all payments are not "new"), we will need to tweak both |
@@ -108,7 +109,9 @@ public function voidOrderPayment(GenericEvent $event) | |||
); | |||
} | |||
|
|||
$order->getPayment()->setState(PaymentInterface::STATE_VOID); | |||
if (false === $order->getPayments()->isEmpty()) { |
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.
Just !$order->getPayments()->isEmpty()
This is a bit weird, as the aim of this PR is just to add the ability to use multiple payments, but it does not add multiple payments. To be honest this leads to some wtf in the code. I think it's a bit risky to have this merged like this, as we won't be able to identify what is proper code and what is temporary workaround. @kayue is it possible for you to adapt all the logic of the different actors (paymentProcessor, listeners, etc. no need to go up to the purchase step) to be able to really handle multiple payments? |
To be clear: what is done is good, a nice step towards multiple payments support. Thanks for that! But there are some temporary workarounds in listeners and processors that deserve to be dealt with before merging I think :) |
@winzou Sounds fair, I agree we should remove all the temporary workaround. I believe this list has everything we want to fix already: https://scrutinizer-ci.com/g/Sylius/Sylius/inspections/023d68fa-c0e7-4d63-958d-79f2d98dea26/issues/ They can all be fixed by changing Payum's Did I missed anything here? |
I was thinking of giving the payment in addition to just the order on all the listeners and processor modified in your PR. The payments->last() shouldn't be used. We should always know which payment is to be changed. |
@pjedrzejewski I agree what you says, but at the current stage it is safer to just get the last "new" payment. I think there is a "bug" in Sylius where an order could have multiple "new payment" when user trying to pay with different payment method. (maybe I am using an older version). As discussed earlier we will not implement multiple payments UI logic in this PR. We can do it in another PR. |
@kayue Deal, let's go with the |
@pjedrzejewski This PR is ready! |
Good to me as well! You can go with this one first, mine is blocked by
|
* | ||
* @return PaymentInterface | ||
*/ | ||
public function getLastNewPayment(); |
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.
What about: getLastPayment(PaymentInterface::STATE_NEW)
?
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.
@stloyd I don't think it will works because it is not supported by PropertyAccess
in form.
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.
Why? If you call without value, it will use default one, so it will be PaymentInterface::STATE_NEW
.
I'd be able to review it on Monday. Dont hesitate to ping me. |
* Check if the payment subject has certain payment. | ||
* | ||
* @param PaymentInterface $payment | ||
* @return Boolean |
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.
Please add new line to stop CS fixed complain about this =)
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.
Also IIRC we use @return bool
same as Symfony.
* | ||
* @author Ka Yue Yeung <kayuey@gmail.com> | ||
*/ | ||
class Payment extends BasePayment implements PaymentInterface |
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.
Just to mention. This could be named OrderAwarePayment
and moved to order or payment component. I dont a big fun of dependencies on core component.
See for the referance #964
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 agree, but let's do this in a separate PR! This one is big enough. :)
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.
@pjedrzejewski sure, just mentioned it
Great job @kayue. |
Thanks for review @makasim. I have fixed the comments. @pjedrzejewski Good to merge? |
Multiple payments support.
Awesome awesome awesome... thank you Ka Yue! 👍 |
Great! |
Good work!! |
Multiple payments support.
Multiple payments support.
Multiple payments support.
Multiple payments support.
#834