Initial import: Carteasy Shop (Dev-Stand)

This commit is contained in:
Thomas Bartelt
2026-04-20 01:03:43 +02:00
commit d504f8a05d
3845 changed files with 761050 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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. Activate the reservation
*/
$rno = '123456';
// Optional fields should be set using
// $k->setActivateInfo()
try {
$result = $k->activate($rno);
$risk = $result[0]; // ok or no_risk
$invno = $result[1];
echo "risk: {$risk}\ninvno: {$invno}\n";
// Reservation is activated, proceed accordingly.
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+53
View File
@@ -0,0 +1,53 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Activate the invoice
*/
// Here you enter the invoice number you got from addTransaction():
$invNo = '123456';
try {
// You can specify a new pclass ID if the customer wanted to change it
// before you activate.
$url = $k->activateInvoice($invNo, $pclass = KlarnaPClass::INVOICE);
echo "{$url}\n";
// The url points to a PDF file for the invoice.
// Invoice activated, proceed accordingly.
} catch(Exception $e) {
// Something went wrong or the invoice doesn't exist.
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+67
View File
@@ -0,0 +1,67 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 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";
}
@@ -0,0 +1,158 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Add the article(s), shipping and/or handling fee.
*/
// Here we add a normal product to our goods list.
$k->addArticle(
4, // Quantity
"MG200MMS", // Article number
"Matrox G200 MMS", // Article name/title
299.99, // Price
25, // 25% VAT
0, // Discount
KlarnaFlags::INC_VAT // Price is including VAT.
);
// Next we might want to add a shipment fee for the product
$k->addArticle(
1,
"",
"Shipping fee",
14.5,
25,
0,
// Price is including VAT and is shipment fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT
);
// Lastly, we want to use an invoice/handling fee as well
$k->addArticle(
1,
"",
"Handling fee",
11.5,
25,
0,
// Price is including VAT and is handling/invoice fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING
);
/**
* 3. Create and set the address(es).
*/
// Create the address object and specify the values.
$addr = new KlarnaAddr(
'always_approved@klarna.com', // email
'', // Telno, only one phone number is needed.
'0762560000', // Cellno
'Testperson-se', // Firstname
'Approved', // Lastname
'', // No care of, C/O.
'Stårgatan 1', // Street
'12345', // Zip Code
'Ankeborg', // City
KlarnaCountry::SE, // Country
null, // HouseNo for German and Dutch customers.
null // House Extension. Dutch customers only.
);
// Next we tell the Klarna instance to use the address in the next order.
$k->setAddress(KlarnaFlags::IS_BILLING, $addr); // Billing / invoice address
$k->setAddress(KlarnaFlags::IS_SHIPPING, $addr); // Shipping / delivery address
/**
* 4. Specify relevant information from your store. (OPTIONAL)
*/
// Set store specific information so you can e.g. search and associate invoices
// with order numbers.
$k->setEstoreInfo(
'175012', // Order ID 1
'1999110234', // Order ID 2
'' // Optional username, email or identifier
);
// If you don't have the order id available at this stage, you can later use the
// method updateOrderNo().
/**
* 5. Set additional information. (OPTIONAL)
*/
/** Comment **/
$k->setComment('A text string stored in the invoice commentary area.');
/** Shipment type **/
// Normal shipment is defaulted, delays the start of invoice
// expiration/due-date.
$k->setShipmentInfo('delay_adjust', KlarnaFlags::EXPRESS_SHIPMENT);
/**
* 6. Invoke activateReservation and transmit the data.
*/
/* Make sure the order status is ACCEPTED, before activation.
You can do this by using checkOrderStatus(). */
// Here you enter the reservation number you got from reserveAmount():
$rno = '123456';
try {
// Transmit all the specified data, from the steps above, to Klarna.
$result = $k->activateReservation(
'4103219202', // PNO (Date of birth for DE and NL).
$rno, // Reservation to activate
null, // Gender.
'', // OCR number to use if you have reserved one.
KlarnaFlags::NO_FLAG, // Flags to affect behavior.
// -1, notes that this is an invoice purchase, for part payment purchase
// you will have a pclass object which you use getId() from.
KlarnaPClass::INVOICE
);
$risk = $result[0]; // ok or no_risk
$invno = $result[1];
echo "risk: {$risk}\ninvno: {$invno}\n";
// Reservation is activated, proceed accordingly.
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+159
View File
@@ -0,0 +1,159 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Add the article(s), shipping and/or handling fee.
*/
// Here we add a normal product to our goods list.
$k->addArticle(
4, // Quantity
"MG200MMS", // Article number
"Matrox G200 MMS", // Article name/title
299.99, // Price
25, // 25% VAT
0, // Discount
KlarnaFlags::INC_VAT // Price is including VAT.
);
// Next we might want to add a shipment fee for the product
$k->addArticle(
1,
"",
"Shipping fee",
14.5,
25,
0,
// Price is including VAT and is shipment fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT
);
// Lastly, we want to use an invoice/handling fee as well
$k->addArticle(
1,
"",
"Handling fee",
11.5,
25,
0,
// Price is including VAT and is handling/invoice fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING
);
/**
* 3. Create and set the address(es).
*/
// Create the address object and specify the values.
$addr = new KlarnaAddr(
'always_approved@klarna.com', // email
'', // Telno, only one phone number is needed.
'0762560000', // Cellno
'Testperson-se', // Firstname
'Approved', // Lastname
'', // No care of, C/O.
'Stårgatan 1', // Street
'12345', // Zip Code
'Ankeborg', // City
KlarnaCountry::SE, // Country
null, // HouseNo for German and Dutch customers.
null // House Extension. Dutch customers only.
);
// Next we tell the Klarna instance to use the address in the next order.
$k->setAddress(KlarnaFlags::IS_BILLING, $addr); // Billing / invoice address
$k->setAddress(KlarnaFlags::IS_SHIPPING, $addr); // Shipping / delivery address
/**
* 4. Specify relevant information from your store. (OPTIONAL)
*/
// Set store specific information so you can e.g. search and associate invoices
// with order numbers.
$k->setEstoreInfo(
'175012', // Order ID 1
'1999110234', // Order ID 2
'' // Optional username, email or identifier
);
// If you don't have the order id available at this stage, you can later use the
// method updateOrderNo().
/**
* 5. Set additional information. (OPTIONAL)
*/
/** Comment **/
$k->setComment('A text string stored in the invoice commentary area.');
/** Shipment type **/
// Normal shipment is defaulted, delays the start of invoice expiration/due-date.
$k->setShipmentInfo('delay_adjust', KlarnaFlags::EXPRESS_SHIPMENT);
/**
* 6. Invoke addTransaction and transmit the data.
*/
try {
// Transmit all the specified data, from the steps above, to Klarna.
$result = $k->addTransaction(
'4103219202', // PNO (Date of birth for DE and NL).
null, // Gender.
KlarnaFlags::NO_FLAG, // Flags to affect behavior.
// -1, notes that this is an invoice purchase, for part payment purchase
// you will have a pclass object on which you use getId().
KlarnaPClass::INVOICE
);
// Check the order status
if ($result[1] == KlarnaFlags::PENDING) {
/* The order is under manual review and will be accepted or denied at a
later stage. Use cronjob with checkOrderStatus() or visit Klarna
Online to check to see if the status has changed. You should still
show it to the customer as it was accepted, to avoid further attempts
to fraud.
*/
}
// Here we get the invoice number
$invno = $result[0];
// Order is complete, store it in a database.
echo "Status: {$result[1]}\nInvno: {$result[0]}\n";
} catch(Exception $e) {
// The purchase was denied or something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
echo $e->getTraceAsString();
}
@@ -0,0 +1,56 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Calculate the monthly cost for the product page.
*/
$sum = 149.99; // Let's assume this is the product cost.
$flag = KlarnaFlags::PRODUCT_PAGE; // or KlarnaFlags::CHECKOUT_PAGE, if you want
// to do it for the whole order.
$pclass = $k->getCheapestPClass($sum, $flag);
// Did we get a PClass? (it is false if we didn't)
if ($pclass) {
// Here we reuse the same values as above:
$value = KlarnaCalc::calc_monthly_cost(
$sum,
$pclass,
$flag
);
echo "Value: {$value}\n";
/*
$value is now a rounded monthly cost amount to be displayed to the
customer.
*/
}
@@ -0,0 +1,48 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Cancelling a reservation
*/
// Here you enter the reservation number you got from reserveAmount():
$rno = '123456';
try {
$result = $k->cancelReservation($rno);
echo "Result: {$result}\n";
// Reservation cancelled, proceed accordingly.
} catch(Exception $e) {
// Something went wrong or the reservation doesn't exist.
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
@@ -0,0 +1,54 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 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";
}
+58
View File
@@ -0,0 +1,58 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Check the status on your order (invoice or reservation)
*/
$id = '123456'; // Your reservation or invoice number.
try {
$result = $k->checkOrderStatus(
$id, // Reservation, invoice number or order id.
0 // Flag specifying number type. 0 = rno or invno. 1 = order id.
);
if ($result == KlarnaFlags::ACCEPTED) {
// Status changed, you can now activate your invoice/reservation.
echo "Accepted\n";
} else if ($result == KlarnaFlags::DENIED) {
echo "Denied\n";
// Status changed, it is now denied, proceed accordingly.
} else {
echo "Pending\n";
//Order is still pending, try again later.
}
} catch (Exception $e) {
//Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+53
View File
@@ -0,0 +1,53 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Completely refund a invoice.
*/
// Here you enter the invoice number:
$invNo = '123456';
try {
$result = $k->creditInvoice(
$invNo, // Invoice Number
'' // Credit number. (Optional).
);
echo "Result: {$result}\n";
/* Invoice fully refunded, proceed accordingly.
$result contains the invoice number of the refunded invoice. */
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+60
View File
@@ -0,0 +1,60 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Partially refund a invoice.
*/
// Here you enter the invoice number:
$invNo = '123456';
// Specify for which article(s) you want to refund.
$k->addArtNo(
1, // Quantity
'MG200MMS' // Article Number. Must be the same as the one you used
); // in addArticle() when you made the addTransaction() call.
try {
$result = $k->creditPart(
$invNo, // Invoice Number
'' // Credit Number. (Optional).
);
echo "Result: {$result}\n";
/* Invoice partially refunded, proceed accordingly.
$result contains the invoice number of the refunded invoice.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+49
View File
@@ -0,0 +1,49 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Remove the invoice
*/
//Here you enter the invoice number you got from addTransaction():
$invNo = '123456';
try {
$result = $k->deleteInvoice($invNo);
echo "Result: {$result}\n";
//Invoice removed, proceed accordingly.
} catch(Exception $e) {
//Something went wrong or the invoice doesn't exist.
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+50
View File
@@ -0,0 +1,50 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Send an (activated) invoice to the customer via email.
*/
// Here you enter the invoice number:
$invNo = '123456';
try {
$result = $k->emailInvoice($invNo);
echo "Result: {$result}\n";
/* Invoice sent to customer via email, proceed accordingly.
$result contains the invoice number of the emailed invoice.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+50
View File
@@ -0,0 +1,50 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Retrieve the PClasses from Klarna.
*/
try {
$k->fetchPClasses(); // You can specify country (and language, currency if
// you wish) if you don't want to use the configured
// country.
/* PClasses successfully fetched, now you can use getPClasses() to load them
locally or getPClass to load a specific PClass locally.
*/
echo "Fetched " . count($k->getAllPClasses()) . " pclasses.\n";
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+66
View File
@@ -0,0 +1,66 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Get the address(es) from Klarna. (Sweden only!)
*/
$k->setCountry('se');
try {
//Attempt to get the address(es) associated with the SSN/PNO.
$addrs = $k->getAddresses('410321-9202');
/* If there exists several addresses you would want to output a list in
which the customer could choose the address which suits him/her.
*/
// Print them if available:
foreach ($addrs as $key => $addr) {
echo "<table>\n";
// This only works if the right getAddresses type is used.
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";
}
+119
View File
@@ -0,0 +1,119 @@
<?php
require_once('../Klarna.php');
//Dependencies from http://phpxmlrpc.sourceforge.net/
require_once(dirname(dirname(__FILE__)).'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc');
require_once(dirname(dirname(__FILE__)).'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc');
/**
* 1. Initialize and setup the Klarna instance.
*/
$k = new Klarna();
/** Configure the Klarna object using the setConfig() method. (Alternative 1) **/
//Later we define the settings in code, thus we don't save the config to a file in JSON format.
/*
KlarnaConfig::$store = false;
//Create the config object, since we aren't storing the file, we don't need to specify a URI.
$config = new KlarnaConfig($file = null);
//Define the values:
$config['eid'] = 0; //Merchant ID or Estore ID, an integer above 0.
$config['secret'] = "sharedSecret"; //The shared secret which accompanied your eid.
$config['country'] = KlarnaCountry::DE;
$config['language'] = KlarnaLanguage::DE;
$config['currency'] = KlarnaCurrency::EUR;
$config['mode'] = Klarna::BETA; //or Klarna::BETA, depending on which server your eid is associated with.
//Define pclass settings:
$config['pcStorage'] = 'json'; //Which storage module? can be json, xml or mysql.
$config['pcURI'] = '/srv/pclasses.json'; //Where the json file for the pclasses are stored.
//Should we use HTTPS?
$config['ssl'] = false;
//Should we error report/status report to Klarna?
$config['candice'] = true; //(set to false if your server doesn't support UDP)
//Do we want to see xmlrpc debugging information?
$config['xmlrpcDebug'] = null; //If this is defined to anything, it will debug.
//Do we want to see normal debug information?
$config['debug'] = null; //If this is defined to anything, it will debug.
//Set the config object.
$k->setConfig($config);
*/
/** Configure the Klarna object using the config() method. (Alternative 2) **/
//Specify the values:
/*
$k->config(
$eid = 0,
$secret = 'sharedSecret',
$country = KlarnaCountry::DE,
$language = KlarnaLanguage::DE,
$currency = KlarnaCurrency::EUR,
$mode = Klarna::BETA,
$pcStorage = 'json',
$pcURI = '/srv/pclasses.json',
$ssl = true,
$candice = true
);
Klarna::$xmlrpcDebug = false;
Klarna::$debug = false;
*/
/** Configure the Klarna object using the setConfig() method. (Alternative 3) **/
//KlarnaConfig::$store = true; //This is default to true, so this is just to be more detailed.
//Set the config which loads from file /srv/klarna.json:
$k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/* The file would contain the following data to set the same information as the above alternatives:
{
"eid": 0,
"secret":"sharedSecret",
"country": 81,
"language": 28,
"currency": 2,
"mode":0,
"pcStorage":"json",
"pcURI":"\/srv\/pclasses.json",
"ssl": 1,
"candice": 1,
"xmlrpcDebug":0,
"debug":0
}
*/
/**
* 2. Load the PClasses from the local file or MySQL table.
*/
/* PClasses are loaded from the local storage, as defined by "pcStorage" and "pcURI". */
//Load all PClasses available.
$pclasses = $k->getPClasses(
$type = null //Here we can define a specific type of PClass we want to load (KlarnaPClass::CAMPAIGN, for instance).
);
//Next we might want to display the description in a drop down menu:
echo "<select name='pclass'>";
foreach($pclasses as $pclass) {
echo "<option value='".$pclass->getId()."'>".$pclass->getDescription()."</option>";
}
echo "</select>";
//When the customer has confirmed the purchase and chosen a pclass, you can easily grab just that one by doing:
$pclassId = $pclasses[0]->getId(); //Let's say the customer picked the first one
$pclass = $k->getPClass($pclassId);
// Next we can use $pclassId in the addTransaction call or in the reserveAmount call.
+61
View File
@@ -0,0 +1,61 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 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";
}
+50
View File
@@ -0,0 +1,50 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Retrieve the total amount of a invoice.
*/
// Here you enter the invoice number:
$invNo = '123456';
try {
$result = $k->invoiceAmount($invNo);
echo "Result: {$result}\n";
/* Invoice amount successfully retrieved, proceed accordingly.
$result contains the total sum of the invoice.
*/
} catch(Exception $e) {
//Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
@@ -0,0 +1,58 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Retrieve the amount for specific article(s) from an invoice.
*/
// Here you enter the invoice number:
$invNo = '123456';
// Specify for which article(s) you want the amount.
// 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
);
try {
$result = $k->invoicePartAmount($invNo);
echo "Result: {$result}\n";
/* Partial invoice amount successfully retrieved, proceed accordingly.
$result contains the sum of specified article(s).
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+160
View File
@@ -0,0 +1,160 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Add the article(s), shipping and/or handling fee.
*/
// Here we add a normal product to our goods list.
$k->addArticle(
4, // Quantity
"MG200MMS", // Article number
"Matrox G200 MMS", // Article name/title
299.99, // Price
25, // 25% VAT
0, // Discount
KlarnaFlags::INC_VAT // Price is including VAT.
);
// Next we might want to add a shipment fee for the product
$k->addArticle(
1,
"",
"Shipping fee",
14.5,
25,
0,
// Price is including VAT and is shipment fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT
);
// Lastly, we want to use an invoice/handling fee as well
$k->addArticle(
1,
"",
"Handling fee",
11.5,
25,
0,
// Price is including VAT and is handling/invoice fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING
);
/**
* 3. Create and set the address(es).
*/
// Create the address object and specify the values.
$addr = new KlarnaAddr(
'always_approved@klarna.com', // email
'', // Telno, only one phone number is needed.
'0762560000', // Cellno
'Testperson-se', // Firstname
'Approved', // Lastname
'', // No care of, C/O.
'Stårgatan 1', // Street
'12345', // Zip Code
'Ankeborg', // City
KlarnaCountry::SE, // Country
null, // HouseNo for German and Dutch customers.
null // House Extension. Dutch customers only.
);
// Next we tell the Klarna instance to use the address in the next order.
$k->setAddress(KlarnaFlags::IS_BILLING, $addr); // Billing / invoice address
$k->setAddress(KlarnaFlags::IS_SHIPPING, $addr); // Shipping / delivery address
/**
* 4. Specify relevant information from your store. (OPTIONAL)
*/
// Set store specific information so you can e.g. search and associate invoices
// with order numbers.
$k->setEstoreInfo(
'175012', // Order ID 1
'1999110234', // Order ID 2
'' // Optional username, email or identifier
);
// If you don't have the order id available at this stage, you can later use the
// method updateOrderNo().
/**
* 5. Set additional information. (OPTIONAL)
*/
/** Comment **/
$k->setComment('A text string stored in the invoice commentary area.');
/** Shipment type **/
// Normal shipment is defaulted, delays the start of invoice expiration/due-date.
$k->setShipmentInfo('delay_adjust', KlarnaFlags::EXPRESS_SHIPMENT);
/**
* 6. Invoke reserveAmount and transmit the data.
*/
try {
// Transmit all the specified data, from the steps above, to Klarna.
$result = $k->reserveAmount(
'4103219202', // PNO (Date of birth for DE and NL).
null, // Gender.
// Amount. -1 specifies that calculation should calculate the amount
// using the goods list
-1,
KlarnaFlags::NO_FLAG, // Flags to affect behavior.
// -1 notes that this is an invoice purchase, for part payment purchase
// you will have a pclass object on which you use getId().
KlarnaPClass::INVOICE
);
//Check the order status
if ($result[1] == KlarnaFlags::PENDING) {
/* The order is under manual review and will be accepted or denied at a
later stage. Use cronjob with checkOrderStatus() or visit Klarna
Online to check to see if the status has changed. You should still
show it to the customer as it was accepted, to avoid further attempts
to fraud.
*/
}
// Here we get the reservation number
$rno = $result[0];
echo "status: {$result[1]}\nrno: {$result[0]}\n";
// Order is complete, store it in a database.
} catch(Exception $e) {
// The purchase was denied or something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+51
View File
@@ -0,0 +1,51 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Reserve the OCR numbers.
*/
try {
// Reserve the OCR number(s):
$result = $k->reserveOCR(
1 // Number of OCR numbers you wish to reserve.
);
echo "Result: \n";
foreach ($result as $r) {
echo "{$r}\n";
}
/* $result now contains an array of OCR numbers, proceed accordingly. */
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+57
View File
@@ -0,0 +1,57 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Give a discount on the invoice.
*/
// Here you enter the invoice number:
$invNo = '123456';
try {
$result = $k->returnAmount(
$invNo, // Invoice number
19.99, // Amount given as a discount.
25, // 25% VAT
KlarnaFlags::INC_VAT, // Amount including VAT.
"Family discount" // Description
);
echo "Result: {$result}\n";
/* Discount given, proceed accordingly.
$result contains the invoice number of the discounted invoice.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+52
View File
@@ -0,0 +1,52 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Send an (activated) invoice to the customer.
* (Postal service / normal mail)
*/
// Here you enter the invoice number:
$invNo = '123456';
try {
$result = $k->sendInvoice($invNo);
echo "Result: {$result}\n";
/* Invoice sent to customer, proceed accordingly.
$result contains the invoice number of the sent invoice.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+56
View File
@@ -0,0 +1,56 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Split the reservation.
*/
// Here you enter the reservation number you got from reserveAmount():
$rno = '123456';
try {
// Transmit all the specified data, from the steps above, to Klarna.
$result = $k->splitReservation(
$rno, // Reservation number
99.5, // Amount to be subtracted from the reservation.
KlarnaFlags::NO_FLAG // No specific behaviour.
);
// Split successful, proceed accordingly.
$newRno = $result[0]; // New reservation number
$status = $result[1]; // Status of the new reservation (1 or 2)
echo "New RNO: {$result[0]}\nStatus: {$result[1]}\n";
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+123
View File
@@ -0,0 +1,123 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Add the article(s), shipping and/or handling fee. (OPTIONAL)
*/
// Here we add a normal product to our goods list.
$k->addArticle(
4, // Quantity
"MG200MMS", // Article number
"Matrox G200 MMS", // Article name/title
299.99, // Price
25, // 25% VAT
0, // Discount
KlarnaFlags::INC_VAT // Price is including VAT.
);
// Next we might want to add a shipment fee for the product
$k->addArticle(
1,
"",
"Shipping fee",
14.5,
25,
0,
// Price is including VAT and is shipment fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT
);
// Lastly, we want to use an invoice/handling fee as well
$k->addArticle(
1,
"",
"Handling fee",
11.5,
25,
0,
// Price is including VAT and is handling/invoice fee
KlarnaFlags::INC_VAT | KlarnaFlags::IS_HANDLING
);
/**
* 3. Create and set the address(es). (OPTIONAL)
*/
// Create the address object and specify the values.
$addr = new KlarnaAddr(
'always_approved@klarna.com', // email
'', // Telno, only one phone number is needed.
'0762560000', // Cellno
'Testperson-se', // Firstname
'Approved', // Lastname
'', // No care of, C/O.
'Stårgatan 1', // Street
'12345', // Zip Code
'Ankeborg', // City
KlarnaCountry::SE, // Country
null, // HouseNo for German and Dutch customers.
null // House Extension. Dutch customers only.
);
// Next we tell the Klarna instance to use the address in the next order.
$k->setAddress(KlarnaFlags::IS_BILLING, $addr); // Billing / invoice address
$k->setAddress(KlarnaFlags::IS_SHIPPING, $addr); // Shipping / delivery address
/**
* 4. Specify relevant information from your store. (OPTIONAL)
*/
// Set store specific information so you can e.g. search and associate invoices
// with order numbers.
$k->setEstoreInfo(
'175012', // Order ID 1
'1999110234', // Order ID 2
'' // Optional username, email or identifier
);
/**
* 5. Make the call to Klarna
*/
// Reservation number
$rno = '123456';
try {
$result = $k->update('1402740');
if ($result) {
echo "Update successful\n";
}
} catch(KlarnaException $e) {
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
@@ -0,0 +1,54 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Update charge amount (shipping fee or handling fee).
*/
// Here you enter the invoice number you got from addTransaction():
$invNo = '123456';
try {
$result = $k->updateChargeAmount(
$invNo, // Invoice number
KlarnaFlags::IS_SHIPMENT, // IS_SHIPMENT or IS_HANDLING
16.7 // Set the shipping fee to 16.7
);
echo "Result: {$result}\n";
/* Charge type updated successfully, proceed accordingly.
$result contains the same invoice number.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+55
View File
@@ -0,0 +1,55 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Update goods quantity.
*/
// Here you enter the invoice number you got from addTransaction():
$invNo = '123456';
try {
$result = $k->updateGoodsQty(
$invNo, // Invoice number
'MG200MMS', // ArtNo must be the same as the one you used in
// addArticle() when you made the addTransaction() call.
2 // New Quantity
);
echo "Result: {$result}\n";
/* Article quantity updated successfully, proceed accordingly.
$result contains the same invoice number.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}
+53
View File
@@ -0,0 +1,53 @@
<?php
require_once '../Klarna.php';
// Dependencies from http://phpxmlrpc.sourceforge.net/
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc';
require_once dirname(dirname(__FILE__)) .
'/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc';
/**
* 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
);
// OR you can set the config to loads from a file, for example /srv/klarna.json:
// $k->setConfig(new KlarnaConfig('/srv/klarna.json'));
/**
* 2. Update order number / id.
*/
// Here you enter the invoice number you got from addTransaction():
$invNo = '123456';
try {
$result = $k->updateOrderNo(
$invNo, // Invoice Number
'1234' // The order id/number you wish to associated.
);
echo "Result: {$result}\n";
/* Order id is now assicated with the invoice, proceed accordingly.
$result contains the same invoice number.
*/
} catch(Exception $e) {
// Something went wrong, print the message:
echo "{$e->getMessage()} (#{$e->getCode()})\n";
}