Giter Club home page Giter Club logo

Comments (6)

Patabugen avatar Patabugen commented on September 14, 2024

I guess a better question would be:

I'd like to add Refund support, how would you envisage it working? (I've just seen the release() and suchlike methods in shared()).

from sagepay.

judgej avatar judgej commented on September 14, 2024

Hi Sami,

The message type is a slightly different level to the transaction type. Some transactions can have multiple messages involved, each with different fields. A message is a block of data sent to (or received from, IIRC) SagePay, and there is a table in the documentation that describes each of those messages.

from sagepay.

judgej avatar judgej commented on September 14, 2024

In Academe/SagePay/Metadata/Transaction.php the message types are all listed as "source" (as the "source" of each field is a message type - kind of a terminology that came from the SagePay docs).

The three types of messages are "direct", "server", "shared" (both direct and server) and there is also "paypal". So the message type is prefixed by this type to give us message types like "server-registration" (the registration of a transaction for payment, used in the server protocol) and "shared-abort" (the aborting of a transaction in either the server or direct protocols). There is also the "response" suffix that identifies the fields in the response we get from SagePay.

So to create a repayment transaction, first the fields in transaction.php should be identified, and given a "source" to group them together. I expect "shared-refund" makes sense (a refund for both direct and server protocols is possible). That way when the message to request a refund is made to SagePay, it will include only those fields with the "shared-refund" label in the query string of the message that is sent.

Transaction.php is like a list of all possible fields used in all messages, and in the database, with metadata to say how they are formatted and when and where they should be used.

For refunds, the transaction ID of the refund will be a new and unique code like any other transaction. The transaction that it refers to, that it will be refunded against, will be in the RelatedVendorTxCode field. You just need to remember VendorTxCode is the primary key of the transactions entity.

Hope that makes sense :-)

from sagepay.

judgej avatar judgej commented on September 14, 2024

Why refund has got left off, is a mystery to me. It was just of those services that got left to later, I suppose.

from sagepay.

judgej avatar judgej commented on September 14, 2024

Note also in Academe/SagePay/Shared.php that there is a translation between VendorTxCode and RelatedVendorTxCode in some of the messages. This is because in a small handful of cases, SagePay uses the same field name to mean different things. So SagePay will expect a VendorTxCode for a refund (for example, I thing) but we cannot use that field name locally, because it is our primary key, but we translate it to RelatedVendorTxCode (i.e. move it to that field) before storing it in the database, and also translate RelatedVendorTxCode to VendorTxCode in the queryData() method for sending the field to SagePay.

Also just noticed REFUND and DIRECTREFUND services Academe/SagePay/ServiceAbstract.php I cannot remember the difference between the two, but it is something to watch out for. Ah, here we go:

http://www.sagepay.de/help/faq/what_is_direct_refund

It looks like REFUND is for refunding against a transaction, and DIRECTREFUND goes not even care if there was an original transaction or not. Sounds more like just a way to make an arbitrary payment onto a card.

from sagepay.

Patabugen avatar Patabugen commented on September 14, 2024

Thanks for all the info! In fact I started down a similar route, adding a "refund" method in Shared.php and tagging (under Source) all the fields required for source, as "shared-refund". I also added a few fields which were missing from Transaction but called for in the SagePay Shared Docs.

As I was wrapping up for the day I realised I'd done it a bit wrong, so wait until tomorrow to look ;) I've also based this on an already-merged copy of my repo with all the pull requests in (so I don't know how easy it'll be for you to see).

Basically It's going to work like this:

$server = new Academe\SagePay\Server();
// Set the TxModel and suchlike
$server-> refundTransaction($VendorTxCode, $amount, $description);
$server->refund();

Where the refundTransaction() works a bit like findTransaction(), it creates a new transaction with all the fields set (RelatedTxCode and suchlike), then refund() equiates to sendRegistration.

There may be better names for those functions, feel free to suggest.

The current all-in-one version (which mistakenly starts with you already having a transaction which you don't need to get:
https://github.com/Patabugen/SagePay/blob/features-refund/src/Academe/SagePay/Shared.php#L70

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.