Reservation payment: Difference between revisions

From Barion Documentation
Jump to navigation Jump to search
No edit summary
Line 29: Line 29:
'''Currency'''
'''Currency'''


You can define the currency of the payment by specifying the <tt>Currency</tt> 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 <tt>Total</tt>. For example for HUF payments no decimal digits allowed while for EUR payments two decimal digits can be used. To be able to receive payments in the selected currency the shop has to have an account created in that currency in the wallet. This means that if the shop only has HUF and USD accounts in its wallet, EUR payments will not be allowed to prepare. However 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).
You can define the currency of the payment by specifying the <tt>Currency</tt> 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 <tt>Total</tt>. For example for HUF payments no decimal digits allowed while for EUR payments two decimal digits can be used. To be able to receive payments in the selected currency the shop has to have an account created in that currency in the wallet. This means that if the shop only has HUF and USD accounts in its wallet, EUR payments will not be allowed to prepare. However 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 yet).


''' Example preparation'''
''' Example preparation'''

Revision as of 10:38, 14 December 2017

If at the moment of payment the amount of the transaction is not eventual, it is possible to reserve the money, and finalize it later in one or more steps. In case of reservation there is only one condition, the final amount cannot be higher then the reserved one. If the reservation ends with 0 currency, the reserved amount will be refunded to the user. Reservations both work with e-money or bank cards. If bank card was used the amount will be immediately sent to the payee (but will be reserved on the payee's wallet), in case of e-money the amount will be reserved at the payer. The reserved money can not be used until the reservation finished

Prerequisites

The prerequisites are similar to Responsive Web Payment.

The payment process

The payment process is similar to Responsive Web Payment. However as a final step the reservation should be finished ( within the ReservationPeriod ) trough the v2/Payment/FinishReservation API endpoint.

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 in the webshop. 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 webshop 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

In this scenario the PaymenType should be set to Reservation indicating that the financial transaction should be finished at a later time. This means that the amount charged will be placed to reservation until the transaction is not completed. The property ReservationPeriod should be set as well, indicating how long will the reservation stay active.

Every attached transaction has a Payee property. That property indicates the user wallet that will receive the amount of the transaction. It is very important to make sure that this wallet is the same wallet that opened the webshop. In technical terms the POSKey provided should belong to one of the Payee's shop. This is valid for all the transactions attached to the particular payment. If one of the payees is different the scenario autmatically will be upgraded to sharing economy scenario.

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. To be able to receive payments in the selected currency the shop has to have an account created in that currency in the wallet. This means that if the shop only has HUF and USD accounts in its wallet, EUR payments will not be allowed to prepare. However 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 yet).

Example preparation

This is an example POST Start with minimum provided information.

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": "Reservation",
    "ReservationPeriod": "1.00:00:00",
    "PaymentRequestId": "TEST-01",
    "GuestCheckOut" : true,
    "FundingSources": ["All"],
    "Transactions": [
        {
            "POSTransactionId": "TEST-01-01",
            "Payee": "{{shoplogin}}",
            "Total": "1000",
            "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"
                }
            ]
        }
    ]
}


Example success response

In this response there are no errors because the Errors array is empty. There is no fee charged for the payment because there is only one transaction in the Transactions array and it's the one the webshop sent in.

{
    "PaymentId": "00e75116f5ea4cd2b09cc95dcd1eff30",
    "PaymentRequestId": "TEST-01",
    "Status": "Prepared",
    "QRUrl": "https://api.demo.barion.com/qr/generate?paymentId=00e75116-f5ea-4cd2-b09c-c95dcd1eff30&size=Large",
    "Transactions": [
        {
            "POSTransactionId": "TEST-01-01",
            "TransactionId": "8056a2755d4543f294a7d861fc9b41ca",
            "Status": "Prepared",
            "Currency": "HUF",
            "TransactionTime": "2017-12-13T09:45:57.118",
            "RelatedId": null
        }
    ],
    "RecurrenceResult": "None",
    "GatewayUrl": "https://secure.demo.barion.com:443/Pay?Id=00e75116f5ea4cd2b09cc95dcd1eff30",
    "RedirectUrl": "https://testshop.demo.barion.com/Redirect?paymentId=00e75116f5ea4cd2b09cc95dcd1eff30",
    "CallbackUrl": "https://testshop.demo.barion.com/callback?paymentId=00e75116f5ea4cd2b09cc95dcd1eff30",
    "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