forked from md-systems/saferpay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment_saferpay.module
90 lines (78 loc) · 2.66 KB
/
payment_saferpay.module
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
<?php
/**
* @file
* Bootstrap file of the payment_saferpay module.
*/
define('PAYMENT_SAFERPAY_ECI_NO_LIABILITYSHIFT', 0);
define('PAYMENT_SAFERPAY_ECI_3D_AUTHENTICATION', 1);
define('PAYMENT_SAFERPAY_ECI_3D_NO_AUTHENTICATION', 2);
/**
* Returns the URL to post the credit card information to.
*
* @param array $settings
* Array of payment method settings
* @param $payment
*
* @return string
* The URL to point the credit card form action to, FALSE in case of an error.
*/
function _payment_saferpay_business_initpay($settings, $payment) {
$data = array();
// @todo: Check this:
// * Für die Verwendung von CARDREFID="new" muss bei Saferpay zunächst ein numerischer Startwert für den
// Account hinterlegt werden. Kontaktieren Sie hierfür [email protected].
$data['CARDREFID'] = 'new';
$data['FAILLINK'] = url('saferpay/business/scd/' . $payment->id(), array('absolute' => TRUE));
$data['SUCCESSLINK'] = $data['FAILLINK'];
$data['BACKLINK'] = $data['FAILLINK'];
return payment_saferpay_initpay($settings, $data);
}
/**
* Returns the initial payment transaction URL to redirect or post to.
*
* Deals with the arguments common to both payment methods.
*
* @param $settings
* Array of payment method settings.
* @param array $data
* Array of additional arguments.
*
* @return string
* URL to redirect the user to make payment.
*/
function payment_saferpay_initpay($settings, array $data = array()) {
$data['ACCOUNTID'] = $settings['account_id'];
if (!empty($settings['password'])) {
$data['spPassword'] = $settings['password'];
}
// Saferpay only supports en, de, it and fr. For everything else, fall back to
// en.
$language = \Drupal::languageManager()->getCurrentLanguage()->id;
$data['LANGID'] = in_array($language, array('en', 'de', 'fr', 'it')) ? $language : 'EN';
$url = url('https://www.saferpay.com/hosting/CreatePayInit.asp', array('external' => TRUE, 'query' => $data));
$return = payment_saferpay_process_url($url);
if (strpos($return, 'ERROR') !== FALSE) {
drupal_set_message(t('An error occurred during payment: @error.', array('@error' => $return)), 'error');
return FALSE;
}
return $return;
}
/**
* Proxy for saferpay's requests.
*
* @param $url
* The webservice prepared url, i.e. initpay, verifypayconfirm, paycomplete
*
* @return bool
* Webservice response.
*/
function payment_saferpay_process_url($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$sReturn = curl_exec($ch);
curl_close($ch);
return $sReturn;
}