PAYONE-GmbH / shopware-5

PAYONE Payment Plugin for shopware 5
MIT License
10 stars 24 forks source link

External API Functions #32

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi, it would be nice, if we can get two public available function (over your plugin Bootstrap.php) to refund or capture values.

class Shopware_Plugins_Frontend_MoptPaymentPayone_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
    // some other code ...

    /**
     * do a capture for order position with specified $orderDetailId (s_order_details.id) with $amount
     * @param int $orderDetailId
     * @param float $amount
     * @return bool success?
     */
    public function doCapture($orderDetailId, $amount)
    {
        // do caputre
    }

    /**
     * do a refund for order position with specified $orderDetailId (s_order_details.id) with $amount
     * @param int $orderDetailId
     * @param float $amount
     * @return bool success?
     */
    public function doRefund($orderDetailId, $amount)
    {
        // do refund
    }

    // some other code ...
}
fjbender commented 8 years ago

Sounds like a sensible feature to me. Some questions for clarification:

Capturing each order position individually might produce a high number of capture requests to our plattform that might produce higher costs for merchants. It should be possible to capture multiple order positions at once, e.g. in an array() of s_order_details.id. Will that also work in the setting you have in mind?

Additionally, the $amount parameter is redundant, as we can calculate the amount from the price and quantity columns in s_order_details. Or is there any specific reason why you would like to set the amount manually?

@bestit-tkellner Please give feedback on these questions, thanks!

ghost commented 8 years ago

@fjbender thanks for your information, i didn't know that.

Yes we can use an array (or an object?) for this function like this:

<?php
$data = [
    [
        'id' => 12,
        'quantity' => 10
    ],
    [
        'id' => 13,
        'quantity' => 5
    ],
];

It's also possible to use a quantity instead of a amount.

fjbender commented 8 years ago

Appreciate your feedback, I'll talk to Dev about it.

ghost commented 8 years ago

Hi @fjbender , i found the reason why we want to use amount instead of quantity.

We have to calculate article specific amounts for custom articles.

fjbender commented 8 years ago

Problem is, that some payment methods require the capture to contain exactly the positions given in the preauthorization. While "free amount" captures work for some payment methods, this is not standard. The standard would be only to capture the preauthorized positions, as this works for all payment methods.

fjbender commented 8 years ago

@Fatchip-Support a viable method to keep track of how many articles have been captured and refunded would be to store the number of captured and debited articles in the s_order_details_attributes table. ERP systems will need to keep track of this in order to be able to refund and capture articles of the same type at the same time.

FATCHIP-GmbH commented 8 years ago

I added the neccessary method as requested. The first argument $orderDetailParams is an array like this:

$data = [ [ 'id' => 12, 'amount' => 10.0 ], [ 'id' => 13, 'quantity' => 5 ], ];

Note that all orderDetail Ids have to belong to the same Order.

ghost commented 8 years ago

hey, thanks for your support.

public function captureOrder($orderDetailParams, $finalize = false, $includeShipment = false)

$orderDetailParams = this parameter is ok $finalize = can you explain this parameter? $includeShipment = i think shippings costs are captured? so i set this parameter only to true in first caputre?

FATCHIP-GmbH commented 8 years ago

Hi, Set $finalize to true if you capture the full amount of all order postitions or on your last capture in case of multiple partial captures (corresponds to "Finaler Geldeinzug" when you do the capture manually via the backend). When capturing partial amounts this parameter is set to false. (corresponds to "Teil- Geldeinzug in the backend). Set $includeShipment to true to capture including shipment costs. Set $includeShipment to false in case the shipping costs have their own order position. You do not have to use includeShipment on the first capture, just remember to set it to true in one of your capture request. Hope this clarifies things a bit.

ghost commented 8 years ago

thanks a lot!