Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

plugin/buycourses/src/service_success.php (2 issues)

1
<?php
2
/* For license terms, see /license.txt */
3
4
/**
5
 * Success page for the purchase of a service in the Buy Courses plugin.
6
 *
7
 * @package chamilo.plugin.buycourses
8
 */
9
require_once '../config.php';
10
11
$plugin = BuyCoursesPlugin::create();
12
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
13
14
if (!$paypalEnabled) {
15
    api_not_allowed(true);
16
}
17
18
$serviceSaleId = $_SESSION['bc_service_sale_id'];
19
$serviceSale = $plugin->getServiceSale($serviceSaleId);
20
$itemPrice = $serviceSale['price'];
21
22
if (empty($serviceSale)) {
23
    api_not_allowed(true);
24
}
25
26
$paypalParams = $plugin->getPaypalParams();
27
28
$pruebas = $paypalParams['sandbox'] == 1;
29
$paypalUsername = $paypalParams['username'];
30
$paypalPassword = $paypalParams['password'];
31
$paypalSignature = $paypalParams['signature'];
32
33
require_once "paypalfunctions.php";
34
35
$buyerInformation = GetShippingDetails(urlencode($_SESSION['TOKEN']));
0 ignored issues
show
The function GetShippingDetails was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
$buyerInformation = /** @scrutinizer ignore-call */ GetShippingDetails(urlencode($_SESSION['TOKEN']));
Loading history...
36
37
$form = new FormValidator(
38
    'success',
39
    'POST',
40
    api_get_self(),
41
    null,
42
    null,
43
    FormValidator::LAYOUT_INLINE
44
);
45
$form->addButton(
46
    'confirm',
47
    $plugin->get_lang('ConfirmOrder'),
48
    'check',
49
    'success'
50
);
51
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
52
53
if ($form->validate()) {
54
    $formValues = $form->getSubmitValues();
55
    if (isset($formValues['cancel'])) {
56
        $plugin->cancelServiceSale($serviceSale['id']);
57
58
        unset($_SESSION['bc_service_sale_id']);
59
60
        Display::addFlash(
61
            Display::return_message($plugin->get_lang('OrderCancelled'), 'error', false)
62
        );
63
64
        header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
65
        exit;
66
    }
67
68
    $confirmPayments = ConfirmPayment($itemPrice);
0 ignored issues
show
The function ConfirmPayment was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
    $confirmPayments = /** @scrutinizer ignore-call */ ConfirmPayment($itemPrice);
Loading history...
69
    if ($confirmPayments['ACK'] !== 'Success') {
70
        $erroMessage = vsprintf(
71
            $plugin->get_lang('ErrorOccurred'),
72
            [$expressCheckout['L_ERRORCODE0'], $confirmPayments['L_LONGMESSAGE0']]
73
        );
74
        Display::addFlash(
75
            Display::return_message($erroMessage, 'error', false)
76
        );
77
        unset($_SESSION['wizard']);
78
        header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
79
        exit;
80
    }
81
82
    switch ($confirmPayments["PAYMENTINFO_0_PAYMENTSTATUS"]) {
83
        case 'Completed':
84
            $serviceSaleIsCompleted = $plugin->completeServiceSale($serviceSale['id']);
85
86
            if ($serviceSaleIsCompleted) {
87
                Display::addFlash(
88
                    Display::return_message(
89
                        sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']),
90
                        'success'
91
                    )
92
                );
93
94
                break;
95
            }
96
97
            Display::addFlash(
98
                Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
99
            );
100
            break;
101
        case 'Pending':
102
            switch ($confirmPayments["PAYMENTINFO_0_PENDINGREASON"]) {
103
                case 'address':
104
                    $purchaseStatus = $plugin->get_lang('PendingReasonByAddress');
105
                    break;
106
                case 'authorization':
107
                    $purchaseStatus = $plugin->get_lang('PendingReasonByAuthorization');
108
                    break;
109
                case 'echeck':
110
                    $purchaseStatus = $plugin->get_lang('PendingReasonByEcheck');
111
                    break;
112
                case 'intl':
113
                    $purchaseStatus = $plugin->get_lang('PendingReasonByIntl');
114
                    break;
115
                case 'multicurrency':
116
                    $purchaseStatus = $plugin->get_lang('PendingReasonByMulticurrency');
117
                    break;
118
                case 'order':
119
                    $purchaseStatus = $plugin->get_lang('PendingReasonByOrder');
120
                    break;
121
                case 'paymentreview':
122
                    $purchaseStatus = $plugin->get_lang('PendingReasonByPaymentReview');
123
                    break;
124
                case 'regulatoryreview':
125
                    $purchaseStatus = $plugin->get_lang('PendingReasonByRegulatoryReview');
126
                    break;
127
                case 'unilateral':
128
                    $purchaseStatus = $plugin->get_lang('PendingReasonByUnilateral');
129
                    break;
130
                case 'upgrade':
131
                    $purchaseStatus = $plugin->get_lang('PendingReasonByUpgrade');
132
                    break;
133
                case 'verify':
134
                    $purchaseStatus = $plugin->get_lang('PendingReasonByVerify');
135
                    break;
136
                case 'other':
137
                default:
138
                    $purchaseStatus = $plugin->get_lang('PendingReasonByOther');
139
                    break;
140
            }
141
142
            Display::addFlash(
143
                Display::return_message(
144
                    sprintf($plugin->get_lang('PurchaseStatusX'), $purchaseStatus),
145
                    'warning',
146
                    false
147
                )
148
            );
149
            break;
150
        default:
151
            $plugin->cancelServiceSale(intval($serviceSale['id']));
152
153
            Display::addFlash(
154
                Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
155
            );
156
            break;
157
    }
158
159
    unset($_SESSION['bc_service_sale_id']);
160
    header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
161
    exit;
162
}
163
164
$token = isset($_GET['token']) ? Security::remove_XSS($_GET['token']) : null;
165
if (empty($token)) {
166
    api_not_allowed(true);
167
}
168
169
$interbreadcrumb[] = [
170
    "url" => "service_catalog.php",
171
    "name" => $plugin->get_lang('ListOfServicesOnSale'),
172
];
173
174
$templateName = $plugin->get_lang('PaymentMethods');
175
$tpl = new Template($templateName);
176
$tpl->assign('title', $serviceSale['service']['name']);
177
$tpl->assign('price', $serviceSale['price']);
178
$tpl->assign('currency', $serviceSale['currency_id']);
179
$tpl->assign('service', $serviceSale);
180
$tpl->assign('buying_service', true);
181
$tpl->assign('user', api_get_user_info($serviceSale['buyer']['id']));
182
$tpl->assign('form', $form->returnForm());
183
184
$content = $tpl->fetch('buycourses/view/success.tpl');
185
$tpl->assign('content', $content);
186
$tpl->display_one_col_template();
187