dolibarr 21.0.0-beta
server_payment.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20/*
21 * The payment webservice was initially created by Nicolas Nunge <me@nikkow.eu>
22 */
23
29if (!defined('NOCSRFCHECK')) {
30 define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
31}
32if (!defined('NOTOKENRENEWAL')) {
33 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
34}
35if (!defined('NOREQUIREMENU')) {
36 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
37}
38if (!defined('NOREQUIREHTML')) {
39 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
40}
41if (!defined('NOREQUIREAJAX')) {
42 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
43}
44if (!defined("NOLOGIN")) {
45 define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
46}
47if (!defined("NOSESSION")) {
48 define("NOSESSION", '1');
49}
50
51require '../main.inc.php';
52require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
53require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
56
57require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
58require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
59
65dol_syslog("Call Dolibarr webservices interfaces");
66
67$langs->load("main");
68
69// Enable and test if module web services is enabled
70if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
71 $langs->load("admin");
72
73 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
74 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
75 print $langs->trans("ToActivateModule");
76 exit;
77}
78
79// Create the soap Object
80$server = new nusoap_server();
81$server->soap_defencoding = 'UTF-8';
82$server->decode_utf8 = false;
83$ns = 'http://www.dolibarr.org/ns/';
84$server->configureWSDL('WebServicesDolibarrPayment', $ns);
85$server->wsdl->schemaTargetNamespace = $ns;
86
87
88// Define WSDL Authentication object
89$server->wsdl->addComplexType(
90 'authentication',
91 'complexType',
92 'struct',
93 'all',
94 '',
95 array(
96 'dolibarrkey' => array('name' => 'dolibarrkey', 'type' => 'xsd:string'),
97 'sourceapplication' => array('name' => 'sourceapplication', 'type' => 'xsd:string'),
98 'login' => array('name' => 'login', 'type' => 'xsd:string'),
99 'password' => array('name' => 'password', 'type' => 'xsd:string'),
100 'entity' => array('name' => 'entity', 'type' => 'xsd:string')
101 )
102);
103// Define WSDL Return object
104$server->wsdl->addComplexType(
105 'result',
106 'complexType',
107 'struct',
108 'all',
109 '',
110 array(
111 'result_code' => array('name' => 'result_code', 'type' => 'xsd:string'),
112 'result_label' => array('name' => 'result_label', 'type' => 'xsd:string'),
113 )
114);
115
116// Define WSDL for Payment object
117$server->wsdl->addComplexType(
118 'payment',
119 'complexType',
120 'struct',
121 'all',
122 '',
123 array(
124 'amount' => array('name' => 'amount', 'type' => 'xsd:double'),
125 'num_payment' => array('name' => 'num_payment', 'type' => 'xsd:string'),
126 'thirdparty_id' => array('name' => 'thirdparty_id', 'type' => 'xsd:int'),
127 'bank_account' => array('name' => 'bank_account', 'type' => 'xsd:int'),
128 'payment_mode_id' => array('name' => 'payment_mode_id', 'type' => 'xsd:int'),
129 'invoice_id' => array('name' => 'invoice_id', 'type' => 'xsd:int'),
130 'int_label' => array('name' => 'int_label', 'type' => 'xsd:string'),
131 'emitter' => array('name' => 'emitter', 'type' => 'xsd:string'),
132 'bank_source' => array('name' => 'bank_source', 'type' => 'xsd:string'),
133 )
134);
135
136// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
137// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
138// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
139$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
140$styleuse = 'encoded'; // encoded/literal/literal wrapped
141// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
142
143// Register WSDL
144$server->register(
145 'createPayment',
146 // Entry values
147 array('authentication' => 'tns:authentication', 'payment' => 'tns:payment'),
148 // Exit values
149 array('result' => 'tns:result', 'id' => 'xsd:string', 'ref' => 'xsd:string', 'ref_ext' => 'xsd:string'),
150 $ns,
151 $ns.'#createPayment',
152 $styledoc,
153 $styleuse,
154 'WS to create a new payment'
155);
156
157
165function createPayment($authentication, $payment)
166{
167 global $db, $conf;
168
169 $now = dol_now();
170
171 dol_syslog("Function: createPayment login=".$authentication['login']." id=".$payment->id.
172 ", ref=".$payment->ref.", ref_ext=".$payment->ref_ext);
173
174 if ($authentication['entity']) {
175 $conf->entity = $authentication['entity'];
176 }
177
178 // Init and check authentication
179 $objectresp = array();
180 $errorcode = '';
181 $errorlabel = '';
182 $error = 0;
183 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
184
185 // Check parameters
186 if (empty($payment['amount']) && empty($payment['thirdparty_id'])) {
187 $error++;
188 $errorcode = 'KO';
189 $errorlabel = "You must specify the amount and the third party's ID.";
190 }
191
192 if (!$error) {
193 $soc = new Societe($db);
194 $soc->fetch($payment['thirdparty_id']);
195
196 $new_payment = new Paiement($db);
197 $new_payment->num_payment = $payment['num_payment'];
198 $new_payment->fk_account = intval($payment['bank_account']);
199 $new_payment->paiementid = !empty($payment['payment_mode_id']) ? intval($payment['payment_mode_id']) : $soc->mode_reglement_id;
200 $new_payment->datepaye = $now;
201 $new_payment->author = $payment['thirdparty_id'];
202 $new_payment->amounts = array($payment['invoice_id'] => (float) $payment['amount']);
203
204 $db->begin();
205 $result = $new_payment->create($fuser, true);
206
207 if ($payment['bank_account']) {
208 $new_payment->addPaymentToBank($fuser, 'payment', $payment['int_label'], $payment['bank_account'], $payment['emitter'], $payment['bank_source']);
209 }
210
211 if ($result < 0) {
212 $error++;
213 }
214
215 if (!$error) {
216 $db->commit();
217 $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $new_payment->id);
218 } else {
219 $db->rollback();
220 $error++;
221 $errorcode = 'KO';
222 $errorlabel = $new_payment->error;
223 dol_syslog("Function: createInvoice error while creating".$errorlabel);
224 }
225 }
226
227 if ($error) {
228 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
229 }
230
231 return $objectresp;
232}
233
234// Return the results.
235$server->service(file_get_contents("php://input"));
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
createPayment($authentication, $payment)
Create a payment.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:37