-
Notifications
You must be signed in to change notification settings - Fork 19
/
createCheckoutOrder.php
98 lines (79 loc) · 3.14 KB
/
createCheckoutOrder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php //
/**
* example file, how to create an checkout order request
*
* @author Savo Garovic, Janko Stevanovic and Fredrik Sundell for Svea Ekonomi AB
*/
require_once '../../vendor/autoload.php';
use Svea\WebPay\WebPay;
use Svea\WebPay\WebPayItem;
use Svea\WebPay\Config\ConfigurationService;
use Svea\WebPay\Checkout\Model\PresetValue;
error_reporting(E_ALL);
ini_set('display_errors', 'On');
// get config object
$myConfig = ConfigurationService::getTestConfig();
$locale = 'sv-Se';
$orderBuilder = WebPay::checkout($myConfig);
$orderBuilder->setCountryCode('SE')// customer country, we recommend basing this on the customer billing address
->setCurrency('SEK')
->setClientOrderNumber(rand(270000, 670000))
->setCheckoutUri('http://localhost:51925/')
->setConfirmationUri('http://localhost:51925/checkout/confirm')
->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
->setTermsUri('http://localhost:51898/terms')
//->setValidationCallbackUri('http://localhost:51898/validation-callback')
//->setPartnerKey("77FB33EC-505D-4CCF-AA21-D9DF50DC8344")
//->setMerchantData("merchantData")
//->setRequireElectronicIdAuthentication(true)
->setLocale($locale);
$presetPhoneNumber = WebPayItem::presetValue()
->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER)
->setValue('+381212121')
->setIsReadonly(true);
$presetPostalCode = WebPayItem::presetValue()
->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::POSTAL_CODE)
->setValue('11000')
->setIsReadonly(false);
$orderBuilder->addPresetValue($presetPhoneNumber);
$orderBuilder->addPresetValue($presetPostalCode);
//Svea\WebPay\WebPayItem::fixedDiscount()->setAmountIncVat(10); // this is 10 $ fir example, not percent
// create and add items to order
$firstBoughtItem = WebPayItem::orderRow()
->setAmountIncVat(100.00)// - required
->setVatPercent(25)// - required
->setQuantity(1)
->setArticleNumber('123')
// ->setAmountExVat(12.32) // - this action is not allowed for checkout
->setTemporaryReference('230')
->setName('Fork');
$secondBoughtItem = WebPayItem::orderRow()
->setAmountIncVat(10.00)
->setVatPercent(25)
->setQuantity(2)
->setDescription('Korv med bröd')
->setArticleNumber('321')
->setTemporaryReference('231')
->setName('Fork');
$discountItem = WebPayItem::fixedDiscount()
->setName('Promo coupon')
->setVatPercent(25)
->setTemporaryReference('123')
// ->setAmountExVat(12.32) // - this action is not allowed for checkout
->setAmountIncVat(20.00);
$shippingItem = WebPayItem::shippingFee()
->setAmountIncVat(17.60)
->setVatPercent(25)
->setTemporaryReference('123')
// ->setAmountExVat(25.32) // - this action is not allowed for checkout
->setName('incvatShippingFee');
$orderBuilder->addOrderRow($firstBoughtItem);
$orderBuilder->addOrderRow($secondBoughtItem);
$orderBuilder->addDiscount($discountItem);
$orderBuilder->addFee($shippingItem);
try {
$response = $orderBuilder->createOrder();
echo "<pre>" . print_r($response, true) . "</pre>";
} catch (\Exception $e) {
echo "<pre>" . print_r($e->getMessage(), true) . "</pre>";
}