Skip to content

Commit 75d839d

Browse files
committed
Merged with master of PaysonAktiebolag/api-integration-php and namespaced it like previously.
2 parents 8161514 + b9cc6c1 commit 75d839d

27 files changed

Lines changed: 1556 additions & 1703 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/nbproject/private/
2+
/nbproject

example/cancel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h3>Cancel</h3>

example/example.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

example/exampleTest.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

example/index.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
error_reporting(E_ALL);
4+
ini_set("display_errors", 1);
5+
6+
/*
7+
* Payson API Integration example for PHP
8+
*
9+
* More information can be found att https://api.payson.se
10+
*
11+
*/
12+
13+
/*
14+
* On every page you need to use the API you
15+
* need to include the file lib/paysonapi.php
16+
* from where you installed it.
17+
*/
18+
19+
require_once '../lib/paysonapi.php';
20+
21+
/*
22+
* Account information. Below is all the variables needed to perform a purchase with
23+
* payson. Replace the placeholders with your actual information
24+
*/
25+
26+
// Your agent ID and md5 key
27+
$agentID = "1";
28+
$md5Key = "fddb19ac-7470-42b6-a91d-072cb1495f0a";
29+
30+
// URLs used by payson for redirection after a completed/canceled purchase.
31+
32+
$returnURL = "http://my.local/phpAPI/example/return.php";
33+
$cancelURL = "http://my.local/phpAPI/example/cancel.php";
34+
35+
// Please note that only IP/URLS accessible from the internet will work
36+
$ipnURL = "http://my.local/phpAPI/example/ipn-example.php";
37+
38+
// Account details of the receiver of money
39+
$receiverEmail = "testagent-1@payson.se";
40+
41+
// Amount to send to receiver
42+
$amountToReceive = "125";
43+
44+
// Information about the sender of money
45+
$senderEmail = "test-shopper@payson.se";
46+
$senderFirstname = "Test";
47+
$senderLastname = "Person";
48+
49+
50+
/* Every interaction with Payson goes through the PaysonApi object which you set up as follows.
51+
* For the use of our test or live environment use one following parameters:
52+
* TRUE: Use test environment, FALSE: use live environment */
53+
$credentials = new PaysonCredentials($agentID, $md5Key);
54+
$api = new PaysonApi($credentials, TRUE);
55+
56+
/*
57+
* To initiate a direct payment the steps are as follows
58+
* 1. Set up the details for the payment
59+
* 2. Initiate payment with Payson
60+
* 3. Verify that it suceeded
61+
* 4. Forward the user to Payson to complete the payment
62+
*/
63+
64+
/*
65+
* Step 1: Set up details
66+
*/
67+
68+
69+
// Details about the receiver
70+
$receiver = new Receiver(
71+
$receiverEmail, // The email of the account to receive the money
72+
$amountToReceive); // The amount you want to charge the user, here in SEK (the default currency)
73+
$receivers = array($receiver);
74+
75+
// Details about the user that is the sender of the money
76+
$sender = new Sender($senderEmail, $senderFirstname, $senderLastname);
77+
78+
$payData = new PayData($returnURL, $cancelURL, $ipnURL, "Min fina vara", $sender, $receivers);
79+
80+
//Set the list of products. For direct payment this is optional
81+
$orderItems = array();
82+
$orderItems[] = new OrderItem("Test produkt", 100, 1, 0.25, "kalle");
83+
84+
$payData->setOrderItems($orderItems);
85+
86+
87+
//Set the payment method
88+
$constraints = array(FundingConstraint::BANK);
89+
$payData->setFundingConstraints($constraints);
90+
91+
//Set the payer of Payson fees
92+
$payData->setFeesPayer(FeesPayer::PRIMARYRECEIVER);
93+
94+
// Set currency code
95+
$payData->setCurrencyCode(CurrencyCode::SEK);
96+
97+
// Set locale code
98+
$payData->setLocaleCode(LocaleCode::SWEDISH);
99+
100+
// Set guarantee options
101+
$payData->setGuaranteeOffered(GuaranteeOffered::OPTIONAL);
102+
103+
/*
104+
* Step 2 initiate payment
105+
*/
106+
$payResponse = $api->pay($payData);
107+
108+
/*
109+
* Step 3: verify that it suceeded
110+
*/
111+
if ($payResponse->getResponseEnvelope()->wasSuccessful()) {
112+
/*
113+
* Step 4: forward user
114+
*/
115+
header("Location: " . $api->getForwardPayUrl($payResponse));
116+
}
117+
?>

example/ipn-example-test.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)