Table of content
Create a new instance of AuthenticationClient by passing in the client id and client secret provided from WasaKredit.
It is a good idea to create the AuthenticationClient as a singleton during your application initialization, this will allow the AuthorizationClient to store your access token in memory for reusability between client requests.
var authenticationClient = AuthenticationClient.Instance;
authenticationClient.SetClientCredentials("[your client id here]", "[your client secret here]");
authenticationClient.GetAccessToken();
Get the singleton instance of WasaKreditClient by getting the Instance
property of the WasaKreditClient. Call the Initialize
method passing your AuthenticationClient
and a boolean indicating whether you wish
to use the client in test mode or not.
bool testMode = true;
var wasaKreditClient = WasaKreditClient.Instance;
wasaKreditClient.Initialize(authenticationClient, testMode);
To validate whether the Wasa Kredit payment method should be displayed for a given cart amount or not, call the ValidateFinancedAmount
method on your WasaKreditClient
. In the call you provide the current cart amount, e.g.
var response = wasaKreditClient.ValidateFinancedAmount("10000.00");
The response will tell you whether the provided cart amount value is a valid financed amount or not.
To get possible payment methods for a partner, call the GetPaymentMethods
method on your WasaKreditClient
. In the call you provide the current cart amount, e.g.
string amount = "20000";
var response = wasaKreditClient.GetPaymentMethods(amount);
The response can be used to compose a description of which payment methods that are available in the checkout before it’s loaded.
Create a new checkout request and pass it to the CreateLeasingCheckout
method on your WasaKreditClient
.
var request = new CreateCheckoutRequest
{
PaymentTypes = "leasing",
OrderReferences = new [] // Optional but strongly recommended.
{
new OrderReference
{
Key = "temp_order_number",
Value = "12345"
}
}
CartItems = new List<CartItem>
{
new CartItem
{
ProductId = "ez-32131",
ProductName = "Kylskåp EZ3",
PriceExVat = new Price
{
Amount = "10000.0",
Currency = "SEK"
},
Quantity = 1,
VatAmount = new Price
{
Amount = "2500.00", // Vat per item
Currency = "SEK"
},
VatPercentage = "25",
ImageUrl = "http://image.com"
}
},
ShippingCostExVat = new Price
{
Amount = "250.00",
Currency = "SEK"
},
CustomerOrganizationNumber = "2222222-2222", // Optional
PurchaserName = "Anders Svensson", // Optional
PurchaserEmail = "email@example.com", // Optional
PurchaserPhone = "07001234567", // Optional
BillingAddress = new Address // Optional
{
City = "Göteborg",
CompanyName = "Star Republic AB",
Country = "Sweden",
PostalCode = "41116",
StreetAddress = "Eklundsgatan 9"
},
DeliveryAddress = new Address // Optional
{
City = "Göteborg",
CompanyName = "Star Republic AB",
Country = "Sweden",
PostalCode = "41116",
StreetAddress = "Eklundsgatan 9"
},
RecipientName = "Anders Svensson", // Optional
RecipientPhone = "07001234567", // Optional
RequestDomain = "https://YOUR-BASE-DOMAIN",
PingUrl = "https://YOUR-BASE-DOMAIN/payment-callback/" // Optional, but needed for status updates.
};
var response = wasaKreditClient.CreateLeasingCheckout(request);
Note that the OrderReferences
property is a collection. Even if you don’t want to create an order in your system before creating a Wasa Kredit checkout, you have the possibility to supply a temporary identifier to be able to match the Wasa Kredit order with some reference in your system. You also have the option to add additional reference identifiers at a later time, for example when your final order is created (see Add order references).
The URL that you supply with the PingUrl
property should be an endpoint that is set up to receive a POST message and return an http status code 200 response on success.
The return object of the CreateLeasingCheckout
method is a html snippet which you should embed in your web page, inside of which the Wasa Kredit Checkout widget will handle the payment flow.
Create a new checkout request and pass it to the CreateInvoiceCheckout
method on your WasaKreditClient
.
var request = new CreateInvoiceCheckoutRequest
{
OrderReferences = new [] // Optional but strongly recommended.
{
new OrderReference
{
Key = "temp_order_number",
Value = "12345"
}
}
CartItems = new List<InvoiceCartItem>
{
new CartItem
{
ProductId = "ez-32131",
ProductName = "Kylskåp EZ3",
PriceExVat = new Price
{
Amount = "10000.0",
Currency = "SEK"
},
PriceInclVat = new Price
{
Amount = "12500.0",
Currency = "SEK"
},
Quantity = 1,
VatPercentage = "25",
VatAmount = new Price
{
Amount = "2500.00", // Vat per item
Currency = "SEK"
},
TotalPriceInclVat = new Price
{
Amount = "12500.00",
Currency = "SEK"
},
TotalPriceExVat = new Price
{
Amount = "10000.00",
Currency = "SEK"
},
TotalVat = new Price
{
Amount = "25000.00",
Currency = "SEK"
}
}
},
TotalPriceInclVat = new Price
{
Amount = "12500.00",
Currency = "SEK"
},
TotalPriceExVat = new Price
{
Amount = "10000.00",
Currency = "SEK"
},
TotalVat = new Price
{
Amount = "25000.00",
Currency = "SEK"
},
CustomerOrganizationNumber = "2222222-2222", // Optional
PurchaserName = "Anders Svensson", // Optional
PurchaserEmail = "email@example.com", // Optional
PurchaserPhone = "07001234567", // Optional
PartnerReference = "My partner reference",
BillingAddress = new Address // Optional
{
City = "Göteborg",
CompanyName = "Star Republic AB",
Country = "Sweden",
PostalCode = "41116",
StreetAddress = "Eklundsgatan 9"
},
RecipientName = "Anders Svensson", // Optional
RecipientPhone = "07001234567", // Optional
RequestDomain = "https://YOUR-BASE-DOMAIN",
PingUrl = "https://YOUR-BASE-DOMAIN/payment-callback/" // Optional, but needed for status updates.
};
var response = wasaKreditClient.CreateInvoiceCheckout(request);
Note that the OrderReferences
property is a collection. Even if you don’t want to create an order in your system before creating a Wasa Kredit checkout, you have the possibility to supply a temporary identifier to be able to match the Wasa Kredit order with some reference in your system. You also have the option to add additional reference identifiers at a later time, for example when your final order is created (see Add order references).
The URL that you supply with the PingUrl
property should be an endpoint that is set up to receive a POST message and return an http status code 200 response on success.
The return object of the CreateInvoiceCheckout
method is a html snippet which you should embed in your web page, inside of which the Wasa Kredit Checkout widget will handle the payment flow.
After creating a Wasa Kredit Checkout by calling the CreateCheckout
method and embedding the resulting html snippet in your web page, as described above, the checkout html snippet needs to be explicitly initialized through a javascript call to the global window.wasaCheckout.init()
function. The init
method call will populate the <div>
contained in the html snippet and link it to an internal iframe.
<script>
window.wasaCheckout.init();
</script>
You’re able to pass an options object to the init
javascript function. Use this if you want your own custom handling of the onComplete, onRedirect and onCancel checkout events.
<script>
var options = {
onComplete: function(orderReferences){
//[...]
},
onRedirect: function(orderReferences){
//[...]
},
onCancel: function(orderReferences){
//[...]
}
};
window.wasaCheckout.init(options);
</script>
The onComplete
event will be raised when a user has completed the checkout process. We recommend that you convert your cart/checkout to an order here if you haven’t done it already.
The onRedirect
event will be raised the user clicks the “back to store/proceed”-button.
The onCancel
event will be raised if the checkout process is canceled by the user or Wasa Kredit.
All callback functions will get the orderReferences
parameter passed from the checkout. This parameter consists of an Array of KeyValue
objects.
These are the same values as the ones that was passed to the CreateCheckout
method as the OrderReferences
property and also Wasa Kredit order id.
When calling the CreateCheckout
method, Wasa Kredit will create an order. When the order is created or when the order status is updated, you will receive a POST to the supplied PingUrl
, which contains the following body:
{
"order_id" : "9c722707-123a-44e7-9eba-93e3a372d57e",
"order_status": "initialized"
}
For further information about the order status flow, see the order flow chart.
Using the Wasa Kredit order id (order_id
), provided in the pingback body, you are able to get the entire order object by calling the GetOrder method.
var orderId = "9c722707-123a-44e7-9eba-93e3a372d57e";
var order = wasaKreditClient.GetOrder(orderId);
The response object from the GetOrder
method is quite extensive. For further information about this response object see GetOrderResponse
Each time the order status is updated you will receive a pingback, enabling you to take action on the status change.
The possible order statuses are:
The preferred point in time to create the order in your system is when receiveing a pingback with order status “pending”.
To match the Wasa Kredit order against your internal cart/checkout/order, call the GetOrder
method and use the OrderReferences
property in the return object.
To be able to match your internal cart/checkout/order against the Wasa Kredit order you are able to provide an unlimited set of order references. Order references might be provided in two ways.
CreateCheckout
method call.AddOrderReference
method. This might be done at anytime as long as you have the Wasa Kredit order id. Notice that this operation will add the additional order references to any previous order references.The order reference object is a collection of key-value pairs where the key is the reference identifier (i.e. describes the type of reference) and the value is the actual reference id.
Order referenses are added one at a time by calling the AddOrderReference
method.
string orderId = "9c722707-123a-44e7-9eba-93e3a372d57e";
string quoteId = "fce34f82-de23-4f29-b19b-5e01bc4a3cf6";
var request = new AddOrderReferenceRequest { Key = "Quote", Value = quoteId };
var response = client.AddOrderReference(orderId, request);
ready_to_ship
. You should now ship the order items to the customer.ShipOrder
method.shipped
.
var orderId = "9c722707-123a-44e7-9eba-93e3a372d57e";
var request = new ShipOrderRequest
{
OrderId = orderId,
};
var response = client.ShipOrder(request);
To cancel an order, call the CancelOrder
method (see example below). Orders that have already been shipped cannot be canceled.
var orderId = "9c722707-123a-44e7-9eba-93e3a372d57e";
var request = new CancelOrderRequest
{
OrderId = orderId,
};
var response = client.CancelOrder(request);
Name | Type | Description |
---|---|---|
CustomerOrganizationNumber | string | The organization number of the customer who made the purchase. |
BillingAddress | Address | … |
DeliveryAddress | Address | … |
OrderReferences | List[OrderReference] (required) | A list containing order reference objects. |
PurchaserEmail | string | The email of the person performing the purchase. |
RecipientName | string | The name of the person who should receive the order. |
RecipientPhone | string | The phone number of the person who should receive the order. |
Status | OrderStatus | The status that the order is in at Wasa Kredit. |
CartItem | List[Cart Item] | A list of the items purchased as Cart Item objects. |
Name | Type | Description |
---|---|---|
CompanyName | string | Company name |
StreetAddress | string | Street address |
PostalCode | string | Postal code |
City | string | City |
Country | string | Country |
Name | Type | Description |
---|---|---|
Key | string | A key to succinctly describe the reference. Ex: “temp_order_reference”. |
Value | string | The actual order reference value. |
Name | Type | Description |
---|---|---|
Status | string | The status that the order is in at Wasa Kredit. |