Purpose:
The changeReservation function is used to change a reservation. This is useful when a customer might want to change their order and the order amount changes. Call this function to check if the amount can be changed.
Return value:
String - OK or Throws an exception with error code and error message.
Code examples
Please note that you can find more code examples in our API-files which you will find under Download API in the left menu.
The code examples have been divided into several steps. Click on the step you would like to see the code example.
1. Initialize and setup the Klarna instance
$k = new Klarna();
$k->config(
123456, // Merchant ID
'sharedSecret', // Shared Secret
KlarnaCountry::SE, // Country
KlarnaLanguage::SV, // Language
KlarnaCurrency::SEK, // Currency
Klarna::BETA, // Server
'json', // PClass Storage
'/srv/pclasses.json', // PClass Storage URI path
true, // SSL
true // Remote logging of response times of xmlrpc calls
);
2. Change the reservation
// Here you enter the reservation number you got from reserveAmount():
$rno = '123456';
try {
$result = $k->changeReservation(
$rno, // Reservation number
49.99, // Amount
KlarnaFlags::NEW_AMOUNT // Flag deciding if the amount is the new amount
// to reserve, or if it is to be added to the
// existing amount. (KlarnaFlags::ADD_AMOUNT)
);
// Reservation changed, proceed accordingly.
echo "Result: {$result}\n";
} catch (Exception $e) {
// Something went wrong or the reservation doesn't exist.
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
The code examples have been divided into several steps. Click on the step you would like to see the code example.
1. Initialize and setup the Klarna instance
API klarna = new API ();
/** Configure the Klarna object **/
klarna.Config (new KlarnaConfig () {
EID = 123456,
Secret = "sharedsecret",
Country = API.Country.Sweden,
Language = API.Language.Swedish,
Currency = API.Currency.SEK,
Encoding = API.Encoding.Swedish,
// API.KlarnaServer.Beta or API.KlarnaServer.Live, depending
// on which server your eid is associated with
Mode = API.KlarnaServer.Beta,
PCStorage = "xml",
PCURI = @"/tmp/pclasses.xml"
});
2. Change the reservation
//Use the reservation number you got from ReserveAmount();
string reservationnr = "";
try {
klarna.ChangeReservation (
reservationnr,
// New amount (or add to existing amount depending on the flag
// specified
199.99,
// Amount specified is the new amount, API.Flag.AddAmount adds
// to the existing amount.
API.Flag.NewAmount
);
} catch (Exception e) {
//Something went wrong print the error:
Console.WriteLine ("Error: " + e.Message);
}
The code examples have been divided into several steps. Click on the step you would like to see the code example.
1. Initialize and setup the Klarna instance
Klarna k = new Klarna();
/*
* Configure the Klarna object using the config() method. (Alternative 1)
*/
KlarnaConfig conf = new KlarnaConfig();
// Define values:
conf.setEid(0); // Merchant ID or Estore ID, an Integer above 0.
conf.setSecret("sharedSecret"); // The shared secret which accompanied your eid.
conf.setCountry(KlarnaCountry.DE); // The country of your store.
conf.setLanguage(KlarnaLanguage.DE); // The language of your store.
conf.setCurrency(KlarnaCurrency.EUR); // The currency of your store.
conf.setMode(Klarna.BETA); // or Klarna.LIVE when you are ready to go live.
// Define pclass settings:
conf.setPcStorage("json"); // Storage module. Currently only json is supported.
conf.setPcURI("/srv/pclasses.json"); // Where the json file for the pclasses are stored.
// Should we use SSL?
conf.setSsl(false);
// Should we error report/status report to klarna.
conf.setCandice(true); // set to false if your server doesn't support UDP
// Do we want to see normal debug information?
conf.setDebug(null); // true to debug, null or false not to debug
// Set the config object.
k.config(conf);
/*
* Configure the Klarna object using the config() method (Alternative 2)
*/
/*
* k.config(0, // e-store ID
* "sharedSecret", // shared secret
* KlarnaCountry.DE, // Country constant
* KlarnaLanguage.DE, // Language constant
* KlarnaCurrency.EUR, // Currency constant
* Klarna.BETA, // Mode, BETA or LIVE
* "json", // Storage module
* "/srv/pclasses.json", // Storage location
* true, // SSL
* true // Candice
* );
*
* k.debug = false;
*/
/*
* Configure the Klarna object using the config() method (Alternative 3)
*/
//k.config(KlarnaConfig.fromJson("/srv/klarna.json"));
/* the file would contain the following data to set the same information as above alternatives:
* {
* "eid":0,
* "secret":"sharedSecret",
** "country":"DE",
** "language":"DE",
* "currency":"EUR",
* "mode":1,
* "ssl":false,
* "candice":true,
* "pcStorage":"json",
* "pcURI":"/srv/pclasses.json"
* }
*
*/
2. Change the reservation
// Here you enter the reservation number you got from reserveAmount()
String rno = request.getParameter("reservation_number");
try {
k.changeReservation(
rno,
49.99, // New amount (or add to existing amount depending on the next parameter
KlarnaFlags.Reservation.NEW_AMOUNT.intVal()); // amount specified is the new amount. Use KlarnaFlags.ADD_AMOUNT to add to existing amount. .getCode() is used because it uses the int value of the flag for futureproofing.
// Reservation changed, proceed accordingly
} catch (Exception e) {
// Something went wrong, print the message:
out.println(e.getMessage());
}
The code examples have been divided into several steps. Click on the step you would like to see the code example.
1. Initialize and setup the Klarna instance
<%
Option Explicit
%>
<%
' Grab the API object
' -Merchant ID or Estore ID, an integer above 0.
' -The shared secret which accompanied your eid.
' -Country, language and currency.
Dim kAPI
Set kAPI = GetKlarna(0, "sharedsecret", "SE", "SV", "SEK")
' Do we want to see normal debug information?
kAPI.DebugInformation = True
' Set the address and port to Klarna server.
' Use LIVE or BETA depending on which server your eid is associated with.
kAPI.SetPort(HTTPS_PORT) ' or HTTP_PORT
kAPI.SetHost(BETA_HOST) ' or LIVE_HOST
' Where the XML for the PClasses are stored, e.g. "pclasses.xml"
kAPI.SetPClassesStorageUri(Server.MapPath("pclasses.xml"))
%>
2. Change the reservation
<%
On Error Resume Next
' Here you enter the reservation number you got from ReserveAmount():
Dim rno
rno = CStr(Request.QueryString("rno"))
' Change the reservation amount to be 49.99 instead.
Dim result
result = kAPI.ChangeReservation(rno, 49.99, NEW_AMOUNT) ' ADD_AMOUNT is also available.
If Err.number = 0 Then
' Success
If result = True Then
Response.Write("
Reservation "& rno & " was succesfully changed
")
Else
Response.Write("
Unable to change reservation "& rno & "
")
End If
Else
' Something went wrong
Response.Write("Error occured: " & Err.number & " - " & Err.Description & "" & Err.Source & "")
End If
%>
