*** empty log message ***
[Packages/TYPO3.CMS.git] / misc / 3.0.0 / oldscripts / payment_DIBS.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the Typo3 project. The Typo3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * payment_DIBS.php
29 *
30 * This script handles payment via the danish payment gateway, DIBS.
31 * Support: DIBS premium with Credit-cards and Unibank Solo-E
32 *
33 * This script is used as a "handleScript" with the default productsLib.inc shopping system.
34 *
35 * DIBS: http://www.dibs.dk
36 *
37 * @author Kasper Skårhøj <kasper@typo3.com>
38 */
39
40
41 if (!is_object($this) || !is_object($this->cObj)) die('$this and $this->cObj must be objects!');
42
43
44 // $lConf = $this->basketExtra["payment."]["handleScript."]; // Loads the handleScript TypoScript into $lConf.
45 $lConf = $conf;
46 $localTemplateCode = $this->cObj->fileResource($lConf[templateFile] ? $lConf[templateFile] : "media/scripts/payment_DIBS_template.tmpl"); // Fetches the DIBS template file
47 $localTemplateCode = $this->cObj->substituteMarkerArrayCached($localTemplateCode, $this->globalMarkerArray);
48
49 $orderUid = $this->getBlankOrderUid(); // Gets an order number, creates a new order if no order is associated with the current session
50
51 switch(t3lib_div::GPvar("products_cmd")) {
52 case "cardno":
53 $tSubpart = $lConf["soloe"] ? "###DIBS_SOLOE_TEMPLATE###" : "###DIBS_CARDNO_TEMPLATE###"; // If solo-e is selected, use different subpart from template
54 $content=$this->getBasket($tSubpart,$localTemplateCode); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
55
56 $markerArray=array();
57 $markerArray["###HIDDEN_FIELDS###"] = '
58 <input type=hidden name=merchant value="'.$lConf["merchant"].'">
59 <input type=hidden name=amount value="'.round($this->calculatedSums_tax["total"]*100).'">
60 <input type=hidden name=currency value="'.$lConf["currency"].'"> <!--Valuta som angivet i ISO4217, danske kroner=208-->
61 <input type=hidden name=orderid value="'.$this->getOrderNumber($orderUid).'"> <!--Butikkens ordrenummer der skal knyttes til denne transaktion-->
62 <input type=hidden name=uniqueoid value="1">
63 <input type=hidden name="accepturl" value="https://payment.architrade.com/cgi-ssl/relay.cgi/'.$lConf["relayURL"].'&products_cmd=accept&products_finalize=1&HTTP_COOKIE='.rawurlencode("fe_typo_user=".$GLOBALS["TSFE"]->fe_user->id).'">
64 <input type=hidden name="declineurl" value="https://payment.architrade.com/cgi-ssl/relay.cgi/'.$lConf["relayURL"].'&products_cmd=decline&products_finalize=1&HTTP_COOKIE='.rawurlencode("fe_typo_user=".$GLOBALS["TSFE"]->fe_user->id).'">';
65 if ($lConf["soloe"]) {
66 $markerArray["###HIDDEN_FIELDS###"].= '
67 <input type=hidden name="cancelurl" value="https://payment.architrade.com/cgi-ssl/relay.cgi/'.$lConf["relayURL"].'&products_cmd=cancel&products_finalize=1&HTTP_COOKIE='.rawurlencode("fe_typo_user=".$GLOBALS["TSFE"]->fe_user->id).'">';
68 }
69 if ($lConf["test"]) {
70 $markerArray["###HIDDEN_FIELDS###"].= '
71 <input type=hidden name=test value="foo">
72 ';
73 }
74 if ($lConf["cardType"] && !$lConf["soloe"]) {
75 /*
76 Examples:
77 DK Dankort
78 V-DK Visa-Dankort
79 MC(DK) Mastercard/Eurocard udstedt i Danmark
80 VISA Visakort udstedt i udlandet
81 MC Mastercard/Eurocard udstedt i udlandet
82 DIN(DK) Diners Club, Danmark
83 DIN Diners Club, international
84 */
85
86 $markerArray["###HIDDEN_FIELDS###"].= '
87 <input type=hidden name=cardtype value="'.$lConf["cardType"].'">
88 ';
89 }
90 if ($lConf["account"]) { // DIBS account feature
91 $markerArray["###HIDDEN_FIELDS###"].= '
92 <input type=hidden name=account value="'.$lConf["account"].'">
93 ';
94 }
95
96
97 // Adds order info to hiddenfields.
98 if ($lConf["addOrderInfo"]) {
99 $theFields="";
100 // Delivery info
101 reset($this->deliveryInfo);
102 $cc=0;
103 while(list($field,$value)=each($this->deliveryInfo)) {
104 $value = trim($value);
105 if ($value) {
106 $cc++;
107 $theFields.=chr(10).'<input type=hidden name="delivery'.$cc.'.'.$field.'" value="'.htmlspecialchars($value).'">';
108 }
109 }
110
111 // Order items
112 reset($this->calculatedBasket);
113 $theFields.='
114 <input type=hidden name="ordline1-1" value="Varenummer">
115 <input type=hidden name="ordline1-2" value="Beskrivelse">
116 <input type=hidden name="ordline1-3" value="Antal">
117 <input type=hidden name="ordline1-4" value="Pris">
118 ';
119 $cc=1;
120 while(list(,$rec)=each($this->calculatedBasket)) {
121 $cc++;
122 $theFields.='
123 <input type=hidden name="ordline'.$cc.'-1" value="'.htmlspecialchars($rec["rec"]["itemnumber"]).'">
124 <input type=hidden name="ordline'.$cc.'-2" value="'.htmlspecialchars($rec["rec"]["title"]).'">
125 <input type=hidden name="ordline'.$cc.'-3" value="'.$rec["count"].'">
126 <input type=hidden name="ordline'.$cc.'-4" value="'.$this->priceFormat($rec["totalTax"]).'">';
127 }
128
129 $theFields.='
130 <input type=hidden name="priceinfo1.Shipping" value="'.$this->priceFormat($this->calculatedSums_tax["shipping"]).'">';
131 $theFields.='
132 <input type=hidden name="priceinfo2.Payment" value="'.$this->priceFormat($this->calculatedSums_tax["payment"]).'">';
133 $theFields.='
134 <input type=hidden name="priceinfo3.Tax" value="'.$this->priceFormat($this->calculatedSums_tax["total"]-$this->calculatedSums_no_tax["total"]).'">';
135 $markerArray["###HIDDEN_FIELDS###"].=$theFields;
136 }
137 $content= $this->cObj->substituteMarkerArrayCached($content, $markerArray);
138 break;
139 case "decline":
140 $markerArray=array();
141 $markerArray["###REASON_CODE###"] = t3lib_div::GPvar("reason");
142 $content=$this->getBasket("###DIBS_DECLINE_TEMPLATE###",$localTemplateCode, $markerArray); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
143 break;
144 case "cancel":
145 $content=$this->getBasket("###DIBS_SOLOE_CANCEL_TEMPLATE###",$localTemplateCode, $markerArray); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
146 break;
147 case "accept":
148 $content=$this->getBasket("###DIBS_ACCEPT_TEMPLATE###",$localTemplateCode); // This is just done to calculate stuff
149
150 // DIBS md5 keys
151 $k1=$lConf["k1"];
152 $k2=$lConf["k2"];
153
154 // Checking transaction
155 $amount=round($this->calculatedSums_tax["total"]*100);
156 $currency="208";
157 $transact=t3lib_div::GPvar("transact");
158 $md5key= md5($k2.md5($k1."transact=".$transact."&amount=".$amount."&currency=".$currency));
159 $authkey=t3lib_div::GPvar("authkey");
160 if ($md5key != $authkey) {
161 $content=$this->getBasket("###DIBS_DECLINE_MD5_TEMPLATE###",$localTemplateCode); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
162 } elseif (t3lib_div::GPvar("orderid")!=$this->getOrderNumber($orderUid)) {
163 $content=$this->getBasket("###DIBS_DECLINE_ORDERID_TEMPLATE###",$localTemplateCode); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
164 } else {
165 $markerArray=array();
166 $markerArray["###TRANSACT_CODE###"] = t3lib_div::GPvar("transact");
167
168 $content=$this->getBasket("###BASKET_ORDERCONFIRMATION_TEMPLATE###","",$markerArray);
169 $this->finalizeOrder($orderUid,$markerArray); // Important: finalizeOrder MUST come after the call of prodObj->getBasket, because this function, getBasket, calculates the order! And that information is used in the finalize-function
170 }
171 /*
172 debug($md5key,1);
173 debug($authkey,1);
174 debug("transact");
175 debug(t3lib_div::GPvar("transact"));
176 debug($GLOBALS["TSFE"]->fe_user->id);
177 // echo phpinfo();
178 */
179 break;
180 default:
181 if ($lConf["relayURL"]) {
182 $markerArray=array();
183 $markerArray["###REDIRECT_URL###"] = 'https://payment.architrade.com/cgi-ssl/relay.cgi/'.$lConf["relayURL"].'&products_cmd=cardno&products_finalize=1&HTTP_COOKIE='.rawurlencode("fe_typo_user=".$GLOBALS["TSFE"]->fe_user->id);
184 $content=$this->getBasket("###DIBS_REDIRECT_TEMPLATE###",$localTemplateCode, $markerArray); // This not only gets the output but also calculates the basket total, so it's NECESSARY!
185 } else {
186 $content = "NO .relayURL given!!";
187 }
188 break;
189 }
190 ?>