Giter Club home page Giter Club logo

Comments (17)

dignat avatar dignat commented on September 14, 2024

hello,
What you mean with code your own discounts

from sagepay.

judgej avatar judgej commented on September 14, 2024

The details of how discounts are supported by Sage Pay can be found here:

#26 (comment)

Instead of using the Basket as it is currently defined, you would write your own extending the BasketAbstract. That custom basket would add in methods like addDiscount($fixed, $description). That would store the discount details in the basket. Then override toXml() to output those discounts in the XML that Sage Pay receives.

That way the discounts are sent to Sage Pay, and when the customer goes to the Sage Pay site to make a payment, they see the "Discounts" line on their order, separate to the order lines. Also you will see it in your control panel (I think).

I've not implemented this yet, and have never needed it. If anyone else needs it and can do a pull request with an implementation, then I would be happy to include it. Otherwise just define your own Basket:

<?php namespace My\Project\Namespace;
class Basket extends Academe\SagePay\Model\BasketAbstract
{
    // Add support for discounts here...
}

from sagepay.

judgej avatar judgej commented on September 14, 2024

There are half a dozen other pieces of data that can go into a basket too, that has not been implemented - carRentail, cruise, tourOperator, airline, dinerCustomer. They are all pretty niche.

from sagepay.

judgej avatar judgej commented on September 14, 2024

Did that answer your question? Are you looking to support discounts on a project, or were you just curious about what it meant?

from sagepay.

dignat avatar dignat commented on September 14, 2024

Hello,
Thank you , your answer did answer my question, and yes I am looking to support discounts in our team project. I did try to include discounts in basket with the SagePay BasketXML itself, as according to the documentation (protocol 3.0 )the discounts are part of the basket root in Basket XML and can be added to the basket, but unfortunately I was not able to see the discounts in basket (only items in SagePay account in section additional information). I had a long email exchange witth SagePay support, but they only could confirm that the XML I am sending is correct, and the can not find any reason discounts to not appear in basket.

from sagepay.

judgej avatar judgej commented on September 14, 2024

I'm trying to add this feature, and this is being added to the end of the basket, just before the closing </basket> tag:

<discounts>
<discount><fixed>1.20</fixed><description>Discount One!</description></discount>
<discount><fixed>10.00</fixed><description>Another Discount!</description></discount>
</discounts>

Sage Pay is giving me:

3021: The Basket format is invalid.

So you have got further than me. I'm guessing it is a typo, but I just can't see it.

from sagepay.

judgej avatar judgej commented on September 14, 2024

The example on the Sage Pay site does not have the fixed amounts formatted in the currency format, which is a bit strange:

http://www.sagepay.co.uk/support/basket-xml

<discounts> 
    <discount>
        <fixed>5</fixed>
        <description>Save 5 pounds</description>
    </discount> 
    <discount>
        <fixed>1</fixed>
        <description>Spend 5 pounds and save 1 pound</description>
    </discount> 
</discounts>

from sagepay.

judgej avatar judgej commented on September 14, 2024

I'll push the changes to master so you can have a play with it if you wish. Use it like this:

$basket->addDiscount(1.00, 'A discount because you are a lovely customer');

That breaks it for me, but you may have better luck.

from sagepay.

judgej avatar judgej commented on September 14, 2024

It does say in the specs that:

The value sent will be subtracted from the overall total.

What that means is unclear to me. Does that mean when I am asking for £10 to be paid, and add a discount of £2, then Sage Pay only really asks the customer for £8? If so, I don't like that. I'm also assuming the contents of the basket must add up correctly to the amount being asked for (before or after discount has been added, I don't know).

from sagepay.

judgej avatar judgej commented on September 14, 2024

Ah, covered:

No validation is performed on the totals of the basket, it is your responsibility to ensure that the amounts are correct and that the total of the basket matches the transaction
amount sent in the Registration.

The "your responsibility" bit is a given regardless of whether it is validated. But not being validated means Sage Pay just treat it as metadata for display purposes only. With the old-style basket, all the amounts were validated and had to sum up to the totals exactly.

from sagepay.

judgej avatar judgej commented on September 14, 2024

Doh:

The XML tags should follow the order stated in the table.

Why is this even a thing? I'd love to hear the reasoning.

Order changed and basket now validates. It does not appear on the front end, as you state. This is the new responsive front end, so it may just be teething troubles. Do you see the discounts in the control panel (MySagePay)?

from sagepay.

judgej avatar judgej commented on September 14, 2024

clipboard01
Actually, they do appear. You need to enter CC details (on SP Server) then expand the "Your Shopping Basket" block on the next page (why it's not expanded already for desktop, is probably another teething thing) and the discount will appear in the list of lines, between the items and the delivery charge.

What concerns me here, is that despite what the documentation states, the totals from the basket are all added up (and subtracted in the case of the discounts) and this gives the amount the customer will be asked for. So make sure your basket is 100% correct, and contains absolutely everything that needs to go into it (in 2000 characters or less) otherwise you may not be asking for the full amount. I might put a function in the basket to add up the total amount locally, so you can double-check at your application end. A Currency package will be useful here, so we can deal with the basket lines as integers and avoid rounding errors when adding stuff up. The new Sage Pay Integration API - replacing V3.00 at some distant time - already does this, with all amounts handled as integers (pennies, cents etc.)

I'll push the fix now.

from sagepay.

dignat avatar dignat commented on September 14, 2024

Hi Jason,
I am afraid I see different layout on My SagePay
on transaction tab you can see the transaction by clicking on a specific transaction it pops up window with left hand side menu. on the tab additional information at the bottom I can see the items in the basket but not the discounts.

image

from sagepay.

judgej avatar judgej commented on September 14, 2024

Ah, right. I've not looked in the control panel. My screen shot is from what the end customer sees.

from sagepay.

judgej avatar judgej commented on September 14, 2024

Same result here - the discounts are showing for the user, are used by Sage Pay to calculate what to charge the user, but are not showing anywhere in the control panel. The "print" link is handy on this popup - it formats all the side tabs into a single document (then tells your browser to print it - begone evil JS - I can press the print button myself!). Just cancel the print dialogue when it comes up and then you have the formatted page. Again, no discount in there.

It is going to have to be raised with Sage Pay as a bug, because it looks like it can be nothing other than a bug to me. Be prepared for your bug report to disappear into a black hole, and to not get any feedback on progress. It will silently get fixed at some point, but you probably won't hear about it. But that's just the way they work - we live with it, knowing that things do get fixed in the end.

In the meantime, you will have to save the discounts (probably the whole basket) in your application and match them up with the payments offline.

from sagepay.

dignat avatar dignat commented on September 14, 2024

Thank you so much Jason,
I contacted the SagePay support and asked them to raise a ticket for the discounts bug, hopefully they will fix it soon.

from sagepay.

judgej avatar judgej commented on September 14, 2024

👍

from sagepay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.