PeiApi NuGet package
- 1 Summary
- 2 Dependencies
- 3 Usage
- 3.1 PeiApiConfiguration
- 3.2 PeiService
- 3.2.1 Orders
- 3.2.2 PurchaseAccess
- 3.2.3 PinOrders
- 3.3 Example usage
Summary
PeiApi is a NuGet package that implements calls to some methods in the https://api.pei.is/docs/ui/index that also includes authentication methods to interact with the API.
Dependencies
Newtonsoft.Json.dll (version 13.0.1)
System.Net.Http.Formatting.dll (from Microsoft.AspNet.WebApi.Client version 5.2.7)
Usage
Create a PeiService
object configured for staging (testing environment) or production using the PeiApiConfiguration
class.
Then use this PeiService
object to interact with the API as you see fit.
PeiApiConfiguration
Includes the settings used to connect to the environment and creates a PeiService
object that has those environment options set up.
Before calling .CreateService()
, either use .WithStagingAuth()
to configure it for staging or just .WithAuth()
for production environments.
For the staging environment, use client "democlient" and secret "demosecret"
Contact customer support for access to the production environment
Method | Description |
---|---|
| Configures the authentication settings for staging |
| Configures the authentication settings for production |
| Creates the |
PeiService
Includes implemented method calls to the Pei API. All these calls are asynchronous Task
methods that can be awaited.
Similar to how the sections are in the Pei API, these methods are split into three sections, PurchaseAccess
, Orders
and PinOrders
.
Currently implemented method calls are listed here, along with further documentation for what each does and what their inputs are.
In cases where there are no objects to return, the methods return HttpResponseMessage
with relevant information about the method's execution. See the https://api.pei.is/docs/ui/index Swagger docs for more detailed information about possible HTTP Status Codes and their meaning for the output.
Orders
Method | Description | Input | Output | Pei API method |
---|---|---|---|---|
| Add an order to Pei |
|
| POST: |
| Purchase an order for a buyer. The merchant ( |
|
| POST: |
OrderModel
Name | Type | Required | Description |
---|---|---|---|
|
| Yes | Unique Pei ID for a merchant |
|
| Yes | A buyer model, cannot be null. See |
|
| Yes | Total amount |
|
| No | The merchant’s own reference for the order |
|
| No | An expiration date for the order. Default (when not provided or null) is one day into the future |
|
| No | Postback when order is confirmed (the postback object includes the |
|
| No | A URL to redirect the buyer to when the order is confirmed by the buyer |
|
| No | A URL to redirect the buyer to when the order is cancelled by the buyer |
|
| Yes | List of items, not empty. See |
|
| No | Sequence type of order. See |
|
| No | Payment card authentication id, only applies if |
BuyerModel
Name | Type | Required | Description |
---|---|---|---|
|
| No | Buyer barcode, when this is used the other buyer properties are ignored |
|
| No | Name of the buyer |
|
| No | Social security number / Identity number of the buyer (ísl. kennitala) |
|
| No | The buyer's email address |
|
| No | The buyer's mobile number |
ItemModel
Name | Type | Required | Description |
---|---|---|---|
|
| No | Unique item code |
|
| Yes | Name of the item |
|
| No | Quantity of the given unit |
|
| No | The measurement |
|
| No | Price for a single unit |
|
| No | Total amount |
|
| No | Optional group name |
|
| No | Set if the item should be optional. When this is not set, the item defaults to non-optional |
|
| No | Optionally make an item selected by default |
OrderSequenceType
Name | Description |
---|---|
| Implies that the order is, in reality, not a part of a sequence of recurring orders but rather a stand-alone order |
| Implies that the order is the first in a sequence of recurring orders and will need to be manually paid for by going to the payment gateway which is the |
| Implies that the order is a non-first order in a sequence of recurring orders and will be automatically charged |
SubmitOrderResult
Name | Type | Description |
---|---|---|
|
| ID of the order |
|
| URL to the payment gateway |
PurchaseAccessOrderModel
Name | Type | Required | Description |
---|---|---|---|
|
| Yes | Unique Pei ID for a merchant |
|
| Yes | A buyer model, cannot be null. See |
|
| Yes | Total amount |
|
| No | The merchant’s own reference for the order |
|
| No | Postback when order is confirmed (the postback object includes the |
|
| Yes | List of items, not empty. See |
PurchaseAccessOrderResult
Name | Type | Description |
---|---|---|
|
| Id of the order |
PurchaseAccess
Method | Description | Input | Output | Pei API method |
---|---|---|---|---|
| Check if merchant has access to purchase orders for a buyer. |
|
| GET: |
| Request access to purchase orders for a buyer by sending a pin to the buyer. |
|
| POST: |
| Confirm merchant access to purchase orders for the buyer with a pin from the buyer. |
|
| POST: |
RequestAccessModel
Name | Type | Required | Description |
---|---|---|---|
MerchantId | int | Yes | Pei ID of the merchant requesting access |
BuyerSsn | string | Yes | Ssn of the buyer |
MobileNumber | string | Yes | The mobilenumber to send the confirmation PIN to |
ConfirmAccessModel
Name | Type | Required | Description |
---|---|---|---|
MerchantId | int | Yes | Pei ID of the merchant requesting access |
BuyerSsn | string | Yes | Ssn of the buyer |
Pin | string | Yes | The PIN to confirm the access |
PinOrders
Method | Description | Input | Output | Pei API method |
---|---|---|---|---|
| Send the user a PIN via SMS for a specific order. |
|
| POST: |
| Pay a specific order by using a PIN received through SMS. |
|
| POST: |
Example usage
Create a new PeiService
configured for staging:
var peiService = new PeiApiConfiguration()
.WithStagingAuth("democlient", "demosecret") //.WithAuth("clientId", "secret") for production
.CreateService();
PurchaseAccess payment flow, where the buyer has not confirmed access yet:
var merchantId = 4; // test merchant
var hasAccess = await peiService.PurchaseAccess.HasAccessAsync(merchantId, "buyerSsn");
//hasAccess == false
var requestAccess = await peiService.PurchaseAccess.RequestAccessAsync(/*RequestAccessModel object*/); //pin sent to buyer
var confirmAccess = await peiService.PurchaseAccess.ConfirmAccessAsync(/*ConfirmAccessModel object*/); //buyer confirmed, further calls to hasAccess should return true
//hasAccess == true
var payOrderResult = await peiService.Orders.PayOrderAsync(/*PurchaseAccessOrderModel object*/); //order created and confirmed
PurchaseAccess payment flow, where the buyer has confirmed access before:
//hasAccess == true
var hasAccess = await peiService.PurchaseAccess.HasAccessAsync(merchantId, "buyerSsn");
var payOrderResult = await peiService.Orders.PayOrderAsync(/*PurchaseAccessOrderModel object*/); //order created and confirmed
PinOrders payment flow: