Marketplace Example: Difference between revisions

From Barion Documentation
Jump to navigation Jump to search
Line 234: Line 234:
}
}
</syntaxhighlight>
</syntaxhighlight>
Even though the Marketplace just received a response and probably processed it, the Barion system also sends a [[callback|Callback_mechanism]] to the respective callback URL of the payment - should there be any extra processing required in the Marketplace system.


From the reserved amount of €49 in Terry Wellington's wallet, €40 is released and is now available for him to use. The €9 difference from the initially reserved amount is automatically refunded to Chris's bank card. Robert Craig receives the whole amount of €35.
From the reserved amount of €49 in Terry Wellington's wallet, €40 is released and is now available for him to use. The €9 difference from the initially reserved amount is automatically refunded to Chris's bank card. Robert Craig receives the whole amount of €35.

Revision as of 10:52, 21 December 2017

Detailed example of a marketplace payment

Introduction

This detailed guide is to show the full life cycle of a purchase made at a marketplace scenario. Through this you will be familiar how the Barion payment system works in a complex payment situation - how the payments are processed, how the money travels between the parties and how the systems communicate with each other.

WARNING
Do NOT copy any JSON content to your project - these are for demonstration purposes only!

Imagine Chef Chris would like to buy some groceries and products at the Marketplace. In this case, we are talking about a facilitated payment scenario, where the Marketplace is the facilitator. The facilitator manages and organizes the whole payment process, but they do not take part in it as a final payee. Instead, they distribute the money between the different sellers of the chosen products.

Starting the payment

The process starts with the shopping. Chris has put some products / services (referred to as items) in his shopping cart on the Marketplace website. These items belong to different manufacturers / providers / distributors - other users of the Barion system, henceforth referred to as sellers. They all have registered, active Barion wallets but they do not own a shop in the system.

Chris has selected four items from two sellers and went to checkout. The Marketplace informs him that there is a one-day period of confirmation from the sellers upon placing an order.

At this point, the Marketplace prepares the payment trough the Barion API, using the /v2/Payment/Start endpoint. Chris is purchasing items from two separate sellers, the payment will contain two payment transactions, with the respective items and payees set accordingly. Since there is a time window where the sellers should confirm the order, the Marketplace prepares a Reservation_payments with a reservation period of one day.

For this API call the request JSON looks like this :

 
{
    "POSKey": "60I98E979-Z592-4AA2-BC9F-DF14ABA4P8F17",
    "PaymentType": "Reservation",
    "ReservationPeriod": "1.00:00:00",
    "PaymentRequestId": "MARKETPAY-123456",
    "GuestCheckOut" : true,
    "FundingSources": ["All"],
    "Locale":"en-US",
    "OrderNumber": "1234-5678",
    "Currency":"EUR",
    "Transactions": [
        {
            "POSTransactionId": "MP-TR-01",
            "Payee": "[email protected]",
            "Total": "49",
            "Comment": "Order 1",
            "Items": [
                {
                    "Name": "Fresh potatoes",
                    "Description": "Fresh potatoes",
                    "Quantity": 3,
                    "Unit": "kg",
                    "UnitPrice": 3,
                    "ItemTotal": 9,
                    "SKU": "SM-01"
                },
                {
                    "Name": "Ginger, sliced",
                    "Description": "Ginger, sliced",
                    "Quantity": 2,
                    "Unit": "packs",
                    "UnitPrice": 10,
                    "ItemTotal": 20,
                    "SKU": "SM-02"
                },
                {
                    "Name": "Truffle box",
                    "Description": "Truffle box",
                    "Quantity": 1,
                    "Unit": "pc",
                    "UnitPrice": 20,
                    "ItemTotal": 20,
                    "SKU": "SM-03"
                }
            ]
        },
        {
            "POSTransactionId": "MP-TR-02",
            "Payee": "[email protected]",
            "Total": "35",
            "Comment": "Order  2",
            "Items": [
                {
                    "Name": "8 piece kitchen knives set",
                    "Description": "8 piece kitchen knives set",
                    "Quantity": 1,
                    "Unit": "pc",
                    "UnitPrice": 35,
                    "ItemTotal": 35,
                    "SKU": "SM-04"
                }
            ]
        }
    ]
}

The Barion API accepts the request and prepares the payment. The response JSON content is sent to the Marketplace:

 
{
    "PaymentId": "c2283b509e424b729cabca6437079d6e",
    "PaymentRequestId": "MARKETPAY-123456",
    "Status": "Prepared",
    "QRUrl": "https://api.barion.com/qr/generate?paymentId=48257700-d044-344a-85df-fc75d5fu62cd&size=Large",
    "Transactions": [
        {
            "POSTransactionId": "MP-TR-01",
            "TransactionId": "07ecff0bb7404b40aeae1bb285ed38c8",
            "Status": "Prepared",
            "Currency": "EUR",
            "TransactionTime": "2017-12-20T12:37:39.696",
            "RelatedId": null
        },
        {
            "POSTransactionId": "MP-TR-02",
            "TransactionId": "b673b95ee96746ca8e182a8596d67a9e",
            "Status": "Prepared",
            "Currency": "EUR",
            "TransactionTime": "2017-12-20T12:37:39.696",
            "RelatedId": null
        }
    ],
    "RecurrenceResult": "None",
    "GatewayUrl": "https://secure.barion.com:443/Pay?Id=c2283b509e424b729cabca6437079d6e",
    "RedirectUrl": "https://testshop.barion.com/Redirect?paymentId=c2283b509e424b729cabca6437079d6e",
    "CallbackUrl": "https://testshop.barion.com/callback?paymentId=c2283b509e424b729cabca6437079d6e",
    "Errors": []
}

The Marketplace system logs the result and stores the appropriate parameters of the order (eg. the identifiers for the payment and its transactions) for later use.

Paying on the Barion Smart Gateway

At this point, the Marketplace has all necessary data. It successfully processed the response from the Barion API, so they redirect Chris's browser to the Barion Smart Gateway:

File:Marketplace payment example.png

Chris logs in to the Barion system and chooses one of his saved bank cards to pay for the order.

The payment is successfully finished in a few seconds. The Barion Smart Gateway confirms the successful payment in a summary window.

File:Marketplace payment finish.png

Chris's browser is redirected back to the Marketplace's website, where he may get another confirmation of the order being processed. At this point, the reservation timer is started. The Marketplace has one day to finish the reservation.

The Barion system also sends a callback to the Marketplace so they can process data accordingly even if Chris never returns to the Marketplace website.

Finishing the reservation

The next day the facilitator is informed that one of the items (€9 worth of fresh potatoes) ran out of stock at Terry Wellington. The Marketplace removes this item from Chris's order and modifies the transaction accordingly. All other items are available.

Because the total amount due to the payment is changed, the Marketplace has to finish the reservation with an amount lower than the initial value. The Marketplace sends a request to the Barion API to finish the reservation, via the /v2/Payment/FinishReservation API endpoint, using the payment and transaction identifiers received earlier when preparing the payment. The JSON content of the request looks like this:

 
{
    "POSKey": "60F99E979-S5U2-4AA2-BC9F-DF14ABA4P8F17",
    "PaymentId": "c2283b509e424b729cabca6437079d6e",
     "Transactions": [
        {
            "TransactionId": "07ecff0bb7404b40aeae1bb285ed38c8",
            "Payee": "[email protected]",
            "Total": "40",
            "Comment": "Order 1",
            "Items": [
                {
                    "Name": "Ginger, sliced",
                    "Description": "Ginger, sliced",
                    "Quantity": 2,
                    "Unit": "packs",
                    "UnitPrice": 10,
                    "ItemTotal": 20,
                    "SKU": "SM-02"
                },
                {
                    "Name": "Truffle box",
                    "Description": "Truffle box",
                    "Quantity": 1,
                    "Unit": "pc",
                    "UnitPrice": 20,
                    "ItemTotal": 20,
                    "SKU": "SM-03"
                }
            ]
        },
        {
            "TransactionId": "b673b95ee96746ca8e182a8596d67a9e",
            "Payee": "[email protected]",
            "Total": "35",
            "Comment": "Order  2",
            "Items": [
                {
                    "Name": "8 piece kitchen knives set",
                    "Description": "8 piece kitchen knives set",
                    "Quantity": 1,
                    "Unit": "pc",
                    "UnitPrice": 35,
                    "ItemTotal": 35,
                    "SKU": "SM-04"
                }
            ]
        }
    ]
}
NOTE
See the items and the total amount for the first payment transaction has changed!

The Barion API accepts and processes the request. Both transactions are finished successfully. The payment is set to Succeeded state.

{
    "IsSuccessful": true,
    "PaymentId": "c2283b509e424b729cabca6437079d6e",
    "PaymentRequestId": "MARKETPAY-123456",
    "Status": "Succeeded",
    "Transactions": [
        {
            "POSTransactionId": "MP-TR-01",
            "TransactionId": "07ecff0bb7404b40aeae1bb285ed38c8",
            "Status": "Succeeded",
            "Currency": "EUR",
            "TransactionTime": "2017-12-20T13:47:11.251Z",
            "RelatedId": null
        },
        {
            "POSTransactionId": "MP-TR-02",
            "TransactionId": "b673b95ee96746ca8e182a8596d67a9e",
            "Status": "Succeeded",
            "Currency": "EUR",
            "TransactionTime": "2017-12-20T13:47:11.251Z",
            "RelatedId": null
        }
    ],
    "Errors": []
}

Even though the Marketplace just received a response and probably processed it, the Barion system also sends a Callback_mechanism to the respective callback URL of the payment - should there be any extra processing required in the Marketplace system.

From the reserved amount of €49 in Terry Wellington's wallet, €40 is released and is now available for him to use. The €9 difference from the initially reserved amount is automatically refunded to Chris's bank card. Robert Craig receives the whole amount of €35.

The Marketplace informs Chris about the confirmed order and that the items are being shipped.

Refunding the payment

Chris receives the items he ordered and discovers that the knife set he ordered from Robert Craig has broken during shipment. He informs the Marketplace about this.

The Marketplace forwards his feedback to Robert, who arranges a full refund with Chris in compensation. Robert can do the refund via the Barion web user interface under the details of the corresponding payment after logging into his Barion wallet.

If Robert is not available for some reason, the Marketplace may also refund the payment via the Barion API, using the /vs/Payment/Refund endpoint. In this case, the following JSON content is sent in the request:

{
    "POSKey": "60I98E979-Z592-4AA2-BC9F-DF14ABA4P8F17",
    "PaymentId": "c2283b509e424b729cabca6437079d6e",
    "TransactionsToRefund": [{
        "TransactionId": "b673b95ee96746ca8e182a8596d67a9e",
        "AmountToRefund": 35,
        "POSTransactionId": "MP-TR-02",
        "Comment": "Refund due to broken product sold at Marketplace"
    }],
}

The Barion API receives the refund request and processes it. The refund successfully takes place, although Chris might have to wait up to 30 days to receive the refund on his bank card, depending on the bank system.

{
    "POSKey": "60I98E979-Z592-4AA2-BC9F-DF14ABA4P8F17",
    "PaymentId": "c2283b509e424b729cabca6437079d6e",
    "RefundedTransactions": [{
        "TransactionId": "b673b95ee96746ca8e182a8596d67a9e",
        "Total": 35,
        "POSTransactionId": "MP-TR-02",
        "Comment": "Refund due to broken product sold at Marketplace",
        "Status": "Succeeded"
    }],
    "Errors": []
}

Reference