Before creating the order
To make the integration as smooth as possible, we recommend that you start off by initializing the Klarna object.
Each Klarna library function requires a basic setup of the Klarna object. This configuration specifies how the library communicates with Klarna’s servers. Follow the code example below to see how to do this.
1 2 3 4 5
Dim kAPI Set kAPI = GetKlarna(0, "sharedsecret", "SE", "SV", "SEK") kAPI.SetPort(HTTPS_PORT) ' or HTTP_PORT kAPI.SetHost(BETA_HOST) ' or LIVE_HOST kAPI.SetPClassesStorageUri(Server.MapPath("pclasses.xml"))
1 2 3 4 5 6 7 8 9 10
Configuration configuration = new Configuration( Country.Code.SE, Language.Code.SV, Currency.Code.SEK, Encoding.Sweden) { Eid = 0, Secret = "sharedsecret", IsLiveMode = false }; Api api = new Api(configuration);
1 2 3 4 5 6 7 8
Klarna k = new Klarna( 0, "sharedSecret", KlarnaCountry.SE, KlarnaCurrency.SEK, new JsonStorage("/srv/data/pclasses.json"), Klarna.BETA );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use Klarna\XMLRPC\Klarna; use Klarna\XMLRPC\Country; use Klarna\XMLRPC\Language; use Klarna\XMLRPC\Currency; $k = new Klarna(); $k->config( 0, // Merchant ID 'sharedSecret', // Shared secret Country::SE, // Purchase country Language::SV, // Purchase language Currency::SEK, // Purchase currency Klarna::BETA, // Server );
1 2 3 4 5 6 7 8 9 10 11 12 13 14
config = klarna.Config( eid=0, secret='sharedSecret', country='DE', language='DE', currency='EUR', mode='beta', pcstorage='json', pcuri='/srv/pclasses.json', scheme='https', candice=True) k = klarna.Klarna(config) k.init()
Test credentials
If you wish to test your integration throughout the process, make sure to apply for a test account.
Get consumer address
This function allows you to retrieve a consumer’s address or addresses when using Klarna’s payment methods. This function makes the purchasing experience simpler for the consumer and reduces the risk that the consumer enters an address incorrectly.
Compliance Requirements
For compliance reasons you may only use the getAddresses function as long as the following requirements are met:
- Consumer data is only retrieved for Klarna’s payment methods in the Checkout
- The function may not be used for registering consumers
- The function is used after providing the consumer with Klarna’s terms and conditions
- The getAddresses function and received data must disappear if the consumer chooses another payment method
- The consumer needs to actively press a button to collect the data. It may not be triggered by completion of entering the social security number
- The button is not allowed to be called get address (hämta adress). Approved names: Fetch (Hämta), Continue (Fortsätt), Search (Sök), Proceed (Vidare)
If you fulfill these, follow the two steps below to start using the function:
1. Make the API call to Klarna
Start by making the getAddress API call to Klarna.
1 2
Dim result result = kAPI.GetAddresses("410321-9202", null, null)
1
List<Address> addresses = api.GetAddresses("410321-9202");
1 2 3 4
// Client IP must be set k.setClientIP("192.168.2.10"); List<KlarnaAddr> addresses = k.getAddresses("4103219202");
1
$addrs = $k->getAddresses('410321-9202');
1 2 3 4
# Client IP must be set k.clientip = '83.10.0.5' addrs = k.get_addresses('410321-9202')
Klarna will then respond with an array of arrays containing the addresses (one array per address). The array contains strings.
Example when using GA_GIVEN or GA_OLD
- 0 = First name (not returned if company)
- 1 = Last name or company name
- 2 = Address
- 3 = Postno
- 4 = City
- 5 = Country
An exception with error code and error message will be thrown if the API request was malformed.
2. Fill in the consumer’s address
Use the information returned from Klarna to fill out the relevant fields in the checkout form.
You are now ready for the next step, to make the call to Klarna to create the order.