Payments

The payments api allows clients to create payment links that allow you to redirect website visitors to a secure payment page to accept payment into the EC English account.

To request a payment from a client you need to follow the following steps:

  1. Setup your system to create payments
  2. Create a payment installment request in the API. This will return a link to the payment pages
  3. Redirect the customer to the payment URL returned in the previous step
  4. Show an appropiate page when the user returns to your site
  5. Handle notifications about the results of payments to update external systems based on successful or unsuccessful payments.

Setting up your API Key to request payments

The following settings need adding to be provided by clients of the payment api. They will be added to the PaymentPortalDb.PaymentClient table

Setting  
RedirectBackUrl The URL on the client site that users will be redirected back to once they are finished
SuccessfulPaymentQueue The name of the Azure Service Bus queue that will receive notifications of successful payments.
FailedPaymentQueue The name of the Azure Service Bus queue that will recieve notifications of failed payments

Additionaly the API administrator should generate a random access code and add it to the following locations. This code is only used to authenticate the API with the payment portal doesn’t need to be used by clients of the API.

  • PaymentPortalDb.PaymentClient.AccessCode
  • ApiDb.ApiKeySettings[PaymentPortalApiKey] or ApiDb.ClientSettings[PaymentPortalApiKey]

Finally the API key used by the client needs to be granted PaymentInstallment:Create and PaymentInstallment:Query permissions.

Create a payment installment request

Sample request

Error

Failed to run contract transformer command: bin\Api.ContractTransformer.exe

{
    "LanguageCode": "en",
    "PaymentInstallmentId": "payment-2948",
    "Description": "Your EC English Course and Accommodation",
    "Amount": 400.10,
    "CurrencyIsoCode": "USD",
    "PaymentNotificationData": "any-data-or-blank",
    "Student": {
        "FirstNames": "John",
        "LastName": "Smith",
        "Email": "john.smith@example.com",
        "Address": {
            "Line1": "Flat 2 The Monnings",
            "Line2": "High Street",
            "City": "Norwich",
            "StateProvince": "Norfolk",
            "PostalCode": "JH99 9WW",
            "CountryIsoCode": "GB"
        }
    },
    "SummaryLines": [
        {
            "Amount": 200,
            "CurrencyIsoCode": "USD",
            "Description": "General English Course",
            "OptionalUnitBreakdown": {
                "NumberOfItems": 2,
                "PricePerItem": 100
            }
        },
        {
            "Amount": 200.1,
            "CurrencyIsoCode": "USD",
            "Description": "Homestay Accommodation",
            "OptionalUnitBreakdown": {
                "NumberOfItems": 2,
                "PricePerItem": 100.05
            }
        }
    ]
}

Sample Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
Content-Length: 111

{
  "PaymentUrl": "https://payments.ecenglish.com/djfdklfdsjlk",
  "ExpiryUtc": "2017-01-10T13:12:37.349Z"
}

Fields

PutPaymentInstallmentRequest
Field Type Required? Description
PaymentInstallmentId text(60) Y A unique key for the payment.
LanguageCode text(2) Y The language to display the payment screens in
Description text(80) Y A description of the items being paid for
Amount decimal Y The amont of money to charge
CurrencyIsoCode text(3) Y The currency to charge in
PaymentNotificationData text Y Data that will be passed back when payment is complete
Student object Y Details of the payee
SummaryLines array N Summary details to show on the payment screen
Student
Field Type Required? Description
FirstNames text(60) Y Firstname of the payee
LastName text(60) Y Lastname of the payee
Email text(60) Y Email of the payee
Address.Line1 text(100) N  
Address.Line2 text(100) N  
Address.City text(100) N  
Address.StateProvince text(100) N  
Address.PostalCode text(30) N  
Address.CountryIsoCode text(2) Y Two letter ISO country code of the Payee.
SummaryLine (For display on the card details screen only)
Field Type Required? Description
Amount decimal Y  
CurrencyIsoCode text(2) Y  
Description text(80) Y  
OptionalUnitBreakdown.NumberOfItems integer N  
OptionalUnitBreakdown.PricePerItem decimal N  

Show an appropiate page when the user returns to your site

You should show the user a page that informs them of the result of their payment when they return to your site.

Warning

Don’t use a visit to a page on your site update external systems based on successful payments (for example don’t create bookings based on users visiting this page). Such updates will be unrelable in the event of failures, or if users close their browsers. See Handle notifications about the results of payments for a better solution to this problem

The user will be redirected back to the page on your site that you specified when you Setup your system to create payments. The code parameter on the URL will contain the value of the PaymentInstallmentId that was specified when the payment installment request was created.

http://www.mysite.com/some-page?code=payment-2948

You can use the code query string parameter to check the status of the payment which will allow you to show an appropiate message to the customer

Sample request

Error

Failed to run contract transformer command: bin\Api.ContractTransformer.exe

{ "PaymentInstallmentId": "payment-2948" }

Sample response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
Content-Length: 194

{
  "PaymentInstallmentId": "payment-2948",
  "Status": "SuccessfullyPaid",
  "PaymentNotificationData": "any-data-or-blank",
  "PaymentUrl": "https://payments.ecenglish.com/djfdklfdsjlk"
}

Fields

Field Description
PaymentInstallmentId The ID of the payment that was specified when the payment installment was created
Status One of Unpaid SuccessfullyPaid or FailedToPay
PaymentNotificationData The notification data that was specified when the payment installment was created
PaymentUrl The URL that the user can be redirected to in order to make the payment.

Handle notifications about the results of payments

Successful and unsuccessful payments will be posted to the azure service bus queues that were setup previously. You must use the EcEnglish.Messaging.ServiceBusServer nuget package to consume the messages as this provides the required fault tolerance and reporting of failures.

Example Success Message

{
    "PaymentInstallmentId": "payment-2948",
    "Amount": 400.1,
    "PaymentNotificationData": "any-data-or-blank",
    "CurrencyIsoCode": "USD",
    "WasSuccessful": true
}

Example Failure Message

{
    "PaymentInstallmentId": "payment-2948",
    "PaymentNotificationData": "any-data-or-blank",
    "WasSuccessful": false
}
Field Description
PaymentInstallmentId The ID of the payment that was specified when the payment installment was created
Amount amont of money paid charge
CurrencyIsoCode The currency money was paid in
PaymentNotificationData The notification data that was specified when the payment installment was created
WasSuccessful true for success messages and false for failure messages