Facilitated payments: Difference between revisions

From Barion Documentation
Jump to navigation Jump to search
No edit summary
Line 8: Line 8:
== The Payment Process ==
== The Payment Process ==
The payment process is similar to [[Responsive_web_payment|Responsive web payment|]]. However in this case the facilitator is responsible to manage the payment.
The payment process is similar to [[Responsive_web_payment|Responsive web payment|]]. However in this case the facilitator is responsible to manage the payment.


This example shows the process of a marketplace payment.
This example shows the process of a marketplace payment.
[[file:sharing-economy-marketplace.png|1000px]]
[[file:sharing-economy-marketplace.png|1000px]]



Revision as of 12:10, 13 December 2017

In this scenario the shop is works as a facilitator, handling the payment transactions but the user do not pay for the shop but for another user. Both facilitator and agents ( if any included) receive a fee.

Prerequisites

The prerequisites and is similar to Responsive web payment|.

The Payment Process

The payment process is similar to Responsive web payment|. However in this case the facilitator is responsible to manage the payment.


This example shows the process of a marketplace payment.


Preparing the payment

To prepare a new payment an HTTP POST request should be made to the /v2/Payment/Start API endpoint. The body of this request should contain a well-formed JSON representation of the desired payment process. To see the full specification of this endpoint head over to the API reference.

Structure

The structure of a Barion Gateway payment is hierarchical. The payment is the meta information that describes the process. This payment contains at least one transaction. The transaction represents a financial transfer from a customer to a seller. The payment can contain multiple transactions, this is up to the webshop to decide how the structure of the whole process should be represented. The purchased products should be represented in the Items array of the transactions. The total payment amount will be calculated from the attached transactions. The amount specified for the items is not validated against the transaction Total it is up to the integrator to make sure it is calculated appropriately.

Identification

To make sure that the payment can be properly identified always generate an Id for the payment, that is is unique for the facilitator. This should be sent in the PaymentRequestId property. This is true for all the transactions attached to the payment. For this user the POSTransactionId of the PaymentTransaction entity. If the facilitator only handles one transaction per payment it is possible to use the same Id for both the PaymentRequestId and the POSTransactionId although it is not recommended. In addition to this you can also provide an OrderNumber for the payment.

Payment scenario

Every attached transaction has a Payee property. That property indicates the user wallet that will receive the amount of the transaction. In this scenario there should be at least one payee who is not the same as the one with the provided POSKey.

Currency

You can define the currency of the payment by specifying the Currency payment property. It is important to mention that multi-currency transactions are not supported. This means that the currency you define for the payment will be automatically the currency of all the attached transactions. The currency also defines the available precision of the transaction Total. For example for HUF payments no decimal digits allowed while for EUR payments two decimal digits can be used. In case of market place or sharing economy scenario, the agents and facilitator's accounts will be created for the given currency ( if not existed already).


This is an example POST Start.

IMPORTANT
Always double check your POSKey and Payee properties. The POSKey is different in the sandbox and live Barion systems.
{
    "POSKey": "630ee026-3e19-469f-8325-afc9bd1ae6a6",
    "PaymentType": "Immediate",
    "PaymentRequestId": "TEST-01",
    "GuestCheckOut" : true,
    "FundingSources": ["All"],
    "Currency":"EUR",
    "PayerHint": "[email protected]",
    "Transactions": [
        {
            "POSTransactionId": "EXMPLSHOP-PM-001/TR001",
            "Payee": "[email protected]",
            "Total": 37.2,
            "Comment": "A brief description of the transaction",
            "Items": [
                {
                    "Name": "iPhone 7 smart case",
                    "Description": "Durable elegant phone case / matte black",
                    "Quantity": 1,
                    "Unit": "piece",
                    "UnitPrice": 25.2,
                    "ItemTotal": 25.2,
                    "SKU": "EXMPLSHOP/SKU/PHC-01"
                },
            ],
            "PayeeTransactions": [
                {
                    "Payee": "[email protected]",
                    "POSTransactionId": "TEST-01-AGENTFEE-02",
                    "Total": 30,
                    "Comment": "Agent Fee"
                },
                {
                    "Payee": "[email protected]",
                    "POSTransactionId": "TEST-01-FACILITATORFEE-02",
                    "Total": 10,
                    "Comment": "Facilitator Fee"
                }
            ]
        }
    ]
}

Processing the successful response

After a successfully preparing the payment a JSON response is sent back as response. This JSON should be processed and some properties should be saved in the database of the webshop. The single most important property of this JSON is the PaymentId. This should be saved into the database of the webshop along the the ids of the transactions (TransactionId) attached.

The successful response will also contain the appropriate URL where the customer should be redirected so the integration doesn't have to hard-code any URL. This information is displayed in the GatewayUrl.

At this point the Status of the payment should be Prepared. This means that all the necessary information is prepared for the payment but no financial transfer happened yet.

In the Transactions array are all the transaction that were processed. This array also contains the various fee transactions as well. So if there are transaction here that are not familiar it's because they were not sent by the webshop.

Example success response

In this response there are no errors because the Errors array is empty. The transactions for agent and facilitator fees is prepared aswell.

{
    "PaymentId": "105d618968e5489c8d18e2439b99e5c2",
    "PaymentRequestId": "TEST-01",
    "Status": "Prepared",
    "QRUrl": "https://api.demo.barion.com/qr/generate?paymentId=105d6189-68e5-489c-8d18-e2439b99e5c2&size=Large",
    "Transactions": [
        {
            "POSTransactionId": "TEST-01-01",
            "TransactionId": "a0715a9cd1df4318a8ea9c2fd8a8c334",
            "Status": "Prepared",
            "Currency": "EUR",
            "TransactionTime": "2017-12-13T12:03:02.275",
            "RelatedId": null
        },
        {
            "POSTransactionId": "TEST-01-AGENTFEE-02",
            "TransactionId": "bff280b111104a929ce17886cd76a2a5",
            "Status": "Prepared",
            "Currency": "EUR",
            "TransactionTime": "2017-12-13T12:03:02.275",
            "RelatedId": "a0715a9cd1df4318a8ea9c2fd8a8c334"
        },
        {
            "POSTransactionId": "TEST-01-FACILITATORTFEE-02",
            "TransactionId": "385af623920a4a2c8a153ebf0965f9a2",
            "Status": "Prepared",
            "Currency": "EUR",
            "TransactionTime": "2017-12-13T12:03:02.29",
            "RelatedId": "a0715a9cd1df4318a8ea9c2fd8a8c334"
        }
    ],
    "RecurrenceResult": "None",
    "GatewayUrl": "https://secure.demo.barion.com:443/Pay?Id=105d618968e5489c8d18e2439b99e5c2",
    "RedirectUrl": "https://testshop.demo.barion.com/Redirect?paymentId=105d618968e5489c8d18e2439b99e5c2",
    "CallbackUrl": "https://testshop.demo.barion.com/callback?paymentId=105d618968e5489c8d18e2439b99e5c2",
    "Errors": []
}

Processing the error response

If there is something wrong during the preparation an error response will be provided. If this happens the Errors array will be filled out with information about the problem.

Possible error responses

Error code Description
ModelValidationError This happens when some of the input properties fail the basic validation. For example when transaction set to reservation but no ReservationPeriod was given
AuthenticationFailed The provided POSKey is invalid. Check that the key used is appropriate for the environment. The test and production environment are separate so the keys are only valid for one environment. Another problem could be that the provided key is the public key and not the private key. For API requests the secret API key should be used.
ShopIsClosed The shop is closed in the Barion system, no payments are allowed.
InvalidUser There is a problem with one of the participants taking part in the payment. All of them should be registered Barion users.
UserCantReceiveEMoney There is a problem with the recipient of the payment. Every Payee specified in the attached transactions should be a fully registered user of Barion.
NotExistingCurrency The currency specified for the payment is not supported by the Barion system.
InvalidFundingSource The specified funding source is not valid. Check the FundingSources input parameter.
InvalidCulture The specified culture is not supported by the Barion system.
DoNotHaveEnoughMoneyToPreparePayment In certain corner cases when the webshops Barion balance and the incoming money is not enough to cover the Barion fee this error message is sent.
PaymentStatusNotValid The status of the payment is InProgress already.

Example error response

For example this is the error response when the authentication data (the POSKey) is not correct.

{
  "Errors": [
    {
      "ErrorCode": "AuthenticationFailed",
      "Title": "User authentication failed.",
      "Description": "The login information provided is incorrect. There is no such user in the system or the password is incorrect.",
      "EndPoint": "https://api.barion.com/v2/payment/start",
      "AuthData": null,
      "HappenedAt": "2017-02-03T13:18:07.8878292Z"
    }
  ]
}

Redirecting the customer

After a successful payment preparation the next step is to redirect the customer to the secure Barion site. The URL is provided in the response of the Payment/Start request. Make sure that the user is redirected properly no iframe hacks are allowed. At this point the webshop gives the flow control to the Barion system. There is no need for constant GetPaymentState requests, at least for a reasonable time period. The callback mechanism will take care of the notification. However mistakes could happen so after a reasonable time the webshop can make a GetPaymentState request just to rule out any callback errors. Again, this should not be frequent, let the user fill out its credit card information. If you want to shorten the period the user is allowed to pay you can specify this time period in the PaymentWindow property.

Once the customer arrives to the secure Barion server the payment GUI is displayed. At this point the customer either pays with e-money or with its credit card. If the payment fails for any reason (invalid card for example) the customer can try the payment again without leaving the Barion payment GUI. This means that the customer won't return automatically to webshop when the payment fails. This is worth mentioning because this could lengthen the time the customer takes at the Barion server.

IMPORTANT
Do not try to pay with the account that owns the shop! It is not permitted to purchase in your own shop!

Processing the callback

Once the payment completed a callback request is sent to webshop's server to the specified URL. In fact any change happens in the state of the payment a callback is sent out to notify the webshop. This can be interpreted as a signal to start a GetPaymentState request towards the Barion system. The callback signal is only a signal does not indicate the success of the payment! Therefore a GetPaymentState request is mandatory to make sure that the appropriate payment state is registered in the webshop as well. Read more about the whole callback mechanism.

WARNING
Flooding the Barion servers with unnecessary API calls, instead of relying on the callback mechanism, may lead to suspension of the shop.

Requesting information about the payment

Once the webshop server received the callback the webshop needs to request information about the outcome of the payment process. For this a Payment/GetPaymentState request should be sent to the Barion API.

Processing the returning customer

At the end of the payment process the customer decides whether to return to the webshop or just close the browser. Therefore no financial decision should be made based on the returning customer. The only valid way to decide what to do with the order to request information about the payment through the GetPaymentState API endpoint.

Reference