activatePart

Purpose:

The activatePart function is used to partially activate a passive invoice.

Explanation:

When partially activating an invoice, only the articles and quantities specified by you will be activated. For items which were not activated, a new passive invoice is created with a new invoice number.

Return value:

Struct - [url, invno]
The value of ”url” is a URL pointing to a temporary PDF-version of the activated invoice.
The value of ”invno” is the number on the new passive invoice. If the invoice is fully activated the struct will only contain the url.
The URL is valid for 30 days.

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. Partially activate the invoice
// Here you specify the quantity of an article you wish to partially activate.
// artNo must be the same as the one you used in addArticle() when you made the
// addTransaction() call.
$k->addArtNo(
    1,          // Quantity
    'MG200MMS'  // Article number
);

// Here you enter the invoice number you got from addTransaction():
$invNo = '123456';

try {
    $result = $k->activatePart(
        $invNo,               // Invoice number
        KlarnaPClass::INVOICE // Or the PClass ID used to make the order.
    );
    $url = $result['url'];
    echo "url: ${url}\n";
    if (isset($result['invno'])) {
        $invno = $result['invno'];
        echo "invno: ${invno}\n";
    }
    // The url points to a PDF file for the invoice.
    // The invno field is only present if the invoice was not entirely activated,
    // and in that case it contains the new invoice number.

    // Invoice activated, proceed accordingly.
} catch(Exception $e) {
    // Something went wrong or the invoice 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. Partially activate the invoice
            // Here you enter the invoice number you got from AddTransaction();
            string invoicenr = "";

            // Here you specify the quantity of an article you wish to partially activate.
            klarna.AddArticleNumber (2, "1234e");
            try {
                var response = klarna.ActivatePart (
                    invoicenr,
                // This is an invoice purchase. For a part payment
                // purchase you will have a pclass object which you use
                // pclass.PClassID from.
                    (int)API.Flag.PclassInvoice
                );

                // The url points to a PDF file for the invoice
                string url = (string)response ["url"];
                string invoiceNumber = "";
                // If no invno field is present the entire invoice was activated
                if (response.ContainsKey ("invno")) {
                    invoiceNumber = (string)response ["invno"];
                }
                // Invoice activated, proceed accordingly

                Console.WriteLine ("url: " + url);
                Console.WriteLine ("invno: " + invoiceNumber);
            } catch (Exception e) {
                //Something went wrong print the error message:
                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. Partially activate the invoice
    // Here you specify the quantity of an article you wish to partially activate
    k.addArtNo(1, "MG200MMS"); // the article number must be the same as the one used in addArticle() when you made the addTransaction() call.

    // Here you enter the invoice number you got from addTransaction();
    String invNo = request.getParameter("invoice_number");

    try {
        // If you used delay_adjust = express shipment, then you should set that before activating also.
        String[] result = k.activatePart(invNo, KlarnaPClass.INVOICE);

        String url = result[0];
        invNo = result[1];
        //The url points to a PDF file for the invoice.
        //The invno is 0 if the entire invoice was activated, or the new invoice number.
        //Invoice activated, proceed accordingly.
    } catch (Exception e) {
        //Something went wrong or the invoice doesn't exist.
        out.println("Error: " + 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. Partially activate the invoice
<%

    On Error Resume Next

    ' Here you specify the quantity of an article you wish to partially activate.
    ' -Quantity
    ' -Article number, must be the same as the one you used in addArticle() when you made the addTransaction call.
    Call kAPI.AddArticleNumber(1, "MG200MMS")

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

    ' You can specify a new pclass ID if the customer wanted to change it before you activate.
    Dim result
    Set result = kAPI.ActivatePart(invoiceNumber, PCLASS_INVOICE, True)

    If Err.number = 0 Then
        ' Success

        ' The url points to a PDF file for the invoice.
        Dim url
        url = result("url")

        Response.Write("The returned url is: " & url)
        Response.Write("
Link to invoice
") ' If no invno key exist the entire invoice was activated, else it's the new ' invoice number If result.Exists("invno") = True Then Dim number number = result("invno") Response.Write("Invoice #" & number & "
") else Response.Write("Invoice completly activated" & "
") end if Else ' Something went wrong Response.Write("Error occured: " & Err.number & " - " & Err.Description & "
" & Err.Source & "
") End If %>

Input data:

Variable Type Description
Required eid integer An e-store ID which refers to your store in Klarna's database.
Required invno string The passive invoice number
Required artnos array A list of pairs containing quantity and article number. Each element in the list is created using a call to the addArtNo function.
Required secret string A shared secret used to secure all traffic exchanged by Klarna and your store
Required pclass integer This argument designates a campaign code to be used at the purchase and is utilized when the sale is a part payment or a special campaign purchase. If the sale is an invoice purchase this argument shall be set to -1.

-1 = invoice
xxx = campaign
xxx = all other pclasses*

Please note that part payment and special campaign purchases are not available for companies.

*There are two ways to retrieve pclasses.

1. Go to Klarna Online and press "view store" button in the menu on the left. In the store view, click "Click here to view campaigns".

2. Use the function fetch_pclasses to save all pclass values to your database.
Required shipment_info array [delay_adjust] Required
  • (int) - Determines how long after invoice activation Klarna starts countdown to the expiration date. Both values are by default 0. The terms of these parameters can be negotiated with Klarna.

    KRED_NORMAL_SHIPMENT (value: 1) KRED_EXPRESS_SHIPMENT (value: 2).