invoiceAddress

Purpose:

The invoiceAddress function is used to retrieve the address of a purchase.

Return value:

An array containing the invoice address.

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. Get the address associated with the purchase/invoice
// Here you enter the invoice number:
$invNo = '123456';

try {
    // Attempt to get the address
    $addr = $k->invoiceAddress($invNo);

    // Display the retrieved address:
    echo "<table>\n";
    if ($addr->isCompany) {
        echo "\t<tr><td>Company</td><td>{$addr->getCompanyName()}</td></tr>\n";
    } else {
        echo "\t<tr><td>First name</td><td>{$addr->getFirstName()}</td></tr>\n";
        echo "\t<tr><td>Last name</td><td>{$addr->getLastName()}</td></tr>\n";
    }

    echo "\t<tr><td>Street</td><td>{$addr->getStreet()}</td></tr>\n";
    echo "\t<tr><td>Zip code</td><td>{$addr->getZipCode()}</td></tr>\n";
    echo "\t<tr><td>City</td><td>{$addr->getCity()}</td></tr>\n";
    echo "\t<tr><td>Country</td><td>{$addr->getCountryCode()}</td></tr>\n";
    echo "</table>\n";
} catch(Exception $e) {
    //Something went wrong
    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. Get the address associated with the purchase/invoice
            //Use the invoice number you which to fetch the address from
            string invoicenr = "";
            try {
                Address address = klarna.InvoiceAddress (invoicenr);

                //Display the recieved address accordingly
                if (address.IsCompany) {
                    Console.WriteLine ("Company name: " + address.Company);
                } else {
                    Console.WriteLine ("First name: " + address.Firstname);
                    Console.WriteLine ("Last name" + address.Lastname);
                }
                Console.WriteLine ("Street address: " + address.Street);
                Console.WriteLine ("Zip code: " + address.ZipCode);
                Console.WriteLine ("City: " + address.City);
                Console.WriteLine ("Country: " + address.Country);
            } 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. Get the address associated with the purchase/invoice
    // Here you enter the invoice number:
    String invNo = request.getParameter("invoice_number");

    try {
        // Attempt to get the address:
        KlarnaAddr addr = k.invoiceAddress(invNo);

        // Display the retrieved address
        out.println("<table>");
        if (addr.isCompany()) {
            out.println("<tr><td>Company</td><td>" + addr.getCompanyName() + "</td></tr>");
        } else {
            out.println("<tr><td>First name</td><td>" + addr.getFirstName() + "</td></tr>");
            out.println("<tr><td>Last name</td><td>" + addr.getLastName() + "</td></tr>");
        }

        out.println("<tr><td>Street</td><td>" + addr.getStreet() + "</td></tr>");
        out.println("<tr><td>Zip code</td><td>" + addr.getZip() + "</td></tr>");
        out.println("<tr><td>City</td><td>" + addr.getCity() + "</td></tr>");
        out.println("<tr><td>Country</td><td>" + addr.getCountry() + "</td></tr>");
        out.println("</table>");

    } 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. Get the address associated with the purchase/invoice
<%

    On Error Resume Next

    ' Here you enter the invoice number:
    Dim invoiceNumber
    invoiceNumber = CStr(Request.QueryString("invno"))

    ' Attempt to get the address
    Dim address
    Set address = kAPI.InvoiceAddress(invoiceNumber)

    If Err.number = 0 Then
        ' Success

        ' Display the retrieved address:
        Response.Write("Address for invoice #" & invoiceNumber & "

") Response.Write("<table>") If address.isCompany Then Response.Write("<tr><td>Company</td><td>" & address.getCompanyName() & "</td></tr>") Else Response.Write("<tr><td>First name</td><td>" & address.getFirstName() & "</td></tr>") Response.Write("<tr><td>Last name</td><td>" & address.getLastName() & "</td></tr>") End If Response.Write("<tr><td>Street</td><td>" & address.getStreet() & "</td></tr>") Response.Write("<tr><td>Zip code</td><td>" & address.getZipCode() & "</td></tr>") Response.Write("<tr><td>City</td><td>" & address.getCity() & "</td></tr>") Response.Write("<tr><td>Country</td><td>" & address.getCountryCode() & "</td></tr>") Response.Write("</table>") Else ' Something went wrong Response.Write("Error occured: " & Err.number & " - " & Err.Description & "
" & Err.Source & "
") End If %>

Input data:

Variable Type Description
Required eidintegerAn e-store ID which refers to your store in Klarna's database
Required invnostringThe invoice number
Required secretstringA shared secret used to secure all traffic exchanged by Klarna and your store