Handle refunds
In this section, you will learn how to implement and use full, partial and good will refunds.
Prerequisites
- You have acknowledged and activated an order
Note: You can also use this call if you need to add items to the order after you have activated the order. This functionality is not available for Klarna Checkout purchases made with credit card and direct banking.
Partial refund
In this tutorial, you will learn how to process a partial refund. This functionality will give the consumer a refund for a returned item.
Use case
A consumer purchases a number of items from your web store. The consumer then decides to return some of the items. You will need to process a refund.
1. Initialize 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 examples below to see how to do this with our different libraries:
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()
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);
2. Add call data
The creditPart call requires you to send in the list of items for which you wish to issue a refund.
This is facilitated by a helper function within the Klarna library:
1
k.addArtNo(2, "1234e");
1
$k->addArtNo(1, 'MG200MMS');
1
k.add_art_no(1, 'MG200MMS')
1
Call kAPI.AddArticleNumber(1, "MG200MMS")
1
api.AddArticleNumber(2, "1234e");
After adding the articles you wish to refund, make the call to Klarna.
3. Make the API call
Please initiate the creditPart API call to Klarna using the invoice number to which you want to apply the refund.
1
k.creditPart("123456");
1
$k->creditPart("123456");
1
k.credit_part("123456")
1
Call kAPI.CreditPart("123456", Null)
1
api.CreditPart("123456");
Klarna will respond with a string with the invoice number of the invoice to which the refund is applied, or if an error occurred an exception containing an error code and message will be thrown.
You can now apply the refund to the invoice in your system.
Good-will refund
In this tutorial, you will learn how to process a good-will refund. This functionality will give the consumer a discount on the invoice.
Use case
A consumer purchases a number of items from your web store. Due to an issue with the logistics company the package arrives late. Since this is a loyal customer and customer satisfaction is important to you, you decide to give the consumer a good-will refund in the form of a discount on the invoice.
1. Initialize 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 examples below to see how to do this with our different libraries:
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()
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);
2. Make the API call
Please initiate the returnAmount API call to Klarna using the invoice number to which you want to apply the refund, the amount to be refunded and the VAT rate.
You can also add a description, detailing the reason for the refund.
1 2 3 4 5 6 7
k.returnAmount( "123456789", // Invoice Number 50d, // Amount to return 17d, // VAT % Goods.INC_VAT, // Amount is including VAT "Employee Discount" // Description of the return );
1 2 3 4 5 6 7 8 9
use Klarna\XMLRPC\Flags; $k->returnAmount( $invNo, // Invoice number 19.99, // Amount given as a discount. 25, // 25% VAT Flags::INC_VAT, // Amount including VAT. "Family discount" // Description );
1 2 3 4 5 6
k.return_amount( "123456789", amount=19.99, vat=19, description="Employee Discount" )
1 2 3 4 5
' -Invoice number ' -Amount, give 19.99 as a discount ' -VAT, 25% VAT ' -Flags, price including VAT Call kAPI.ReturnAmount("123456", 19.99, 25, INC_VAT)
1
api.ReturnAmount("123456789", 19.99, 25.0, GoodsFlags.IncVAT, "Employee Discount");
Klarna will respond with a string with the invoice number of the invoice to which the refund is applied, or if an error occurred an exception containing an error code and message will be thrown.
You can now apply the refund to the invoice in your system.
Full refund
Full refund will give the consumer a complete refund on a purchase.
Use case
A consumer purchases a number of items from your web store. The consumer then decides to return all of the items in the order. You will need to process a full refund.
1. Initialize 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 examples below to see how to do this with our different libraries:
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()
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);
2. Make the API call
Please initiate the creditInvoice API call to Klarna using the invoice number to which you want to apply the refund.
1
k.creditInvoice("123456");
1
$k->creditInvoice("123456");
1
k.credit_invoice("123456")
1
Call kAPI.CreditInvoice("123456", Null)
1
api.CreditInvoice("123456");
Klarna will respond with a string with the invoice number of the invoice to which the refund is applied, or if an error occurred an exception containing an error code and message will be thrown.
You can now apply the refund to the invoice in your system.