Exemple #1
0
if (isset($_GET['action']) && $_GET['action'] == 'continue' && !empty($_GET['msorder']) && !empty($_GET['mscode'])) {
    if ($order = $modx->getObject('msOrder', $_GET['msorder'])) {
        if ($_GET['mscode'] == $handler->getOrderHash($order)) {
            $response = $handler->send($order);
            if ($response['success'] && !empty($response['data']['redirect'])) {
                $modx->sendRedirect($response['data']['redirect']);
            } else {
                exit($response['message']);
            }
        }
    }
    exit('Error when continuing order');
} elseif (empty($_GET['token'])) {
    exit('Access denied');
}
$response = $handler->request(array('METHOD' => 'GetExpressCheckoutDetails', 'TOKEN' => $_GET['token']));
$context = '';
$params = array();
if (!is_array($response)) {
    $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Error on receive details of PayPal operation: ' . $response . '; ' . print_r($_GET, 1));
} else {
    if (!empty($response['PAYMENTREQUEST_0_INVNUM'])) {
        if ($order = $modx->getObject('msOrder', $response['PAYMENTREQUEST_0_INVNUM'])) {
            $handler->receive($order, $response);
            $context = $order->get('context');
            $params['msorder'] = $order->get('id');
        } else {
            $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Could not retrieve order with id ' . $response['PAYMENTREQUEST_0_INVNUM']);
        }
    } else {
        $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Error on receive details of PayPal operation: ' . print_r($response, 1) . '; ' . print_r($_GET, 1));
 public function jxCompletePayment()
 {
     $this->validate(__FUNCTION__);
     $json = array();
     if (!isset($this->request->post['selected'])) {
         $json['error'] = $this->language->get('ms_error_withdraw_norequests');
         $this->response->setOutput(json_encode($json));
         return;
     }
     require_once DIR_SYSTEM . 'library/ms-paypal.php';
     $requestParams = array('RECEIVERTYPE' => 'EmailAddress', 'CURRENCYCODE' => $this->config->get('config_currency'));
     $paymentParams = array();
     $i = 0;
     foreach ($this->request->post['selected'] as $payment_id) {
         $result = $this->MsLoader->MsPayment->getPayments(array('payment_id' => $payment_id, 'payment_status' => array(MsPayment::STATUS_UNPAID), 'payment_type' => array(MsPayment::TYPE_PAYOUT, MsPayment::TYPE_PAYOUT_REQUEST), 'single' => 1));
         if (!empty($result)) {
             $paymentParams['L_EMAIL' . $i] = $result['ms.paypal'];
             $paymentParams['L_AMT' . $i] = abs($result['mw.amount']);
             $i++;
         }
     }
     if (empty($paymentParams)) {
         $json['error'] = $this->language->get('ms_error_withdraw_norequests');
         $this->response->setOutput(json_encode($json));
         return;
     }
     $paypal = new PayPal($this->config->get('msconf_paypal_api_username'), $this->config->get('msconf_paypal_api_password'), $this->config->get('msconf_paypal_api_signature'), $this->config->get('msconf_paypal_sandbox'));
     $response = $paypal->request('MassPay', $requestParams + $paymentParams);
     if (!$response) {
         $json['error'] = $this->language->get('ms_error_withdraw_response');
         $json['response'] = print_r($paypal->getErrors(), true);
     } else {
         if ($response['ACK'] != 'Success') {
             $json['error'] = $this->language->get('ms_error_withdraw_status');
             $json['response'] = print_r($response, true);
         } else {
             $json['success'] = $this->language->get('ms_success_transactions');
             $json['response'] = print_r($response, true);
             //$mails = array();
             foreach ($this->request->post['selected'] as $payment_id) {
                 $result = array_shift($this->MsLoader->MsPayment->getPayments(array('payment_id' => $payment_id, 'payment_status' => array(MsPayment::STATUS_UNPAID), 'payment_type' => array(MsPayment::TYPE_PAYOUT, MsPayment::TYPE_PAYOUT_REQUEST), 'single' => 1)));
                 $this->MsLoader->MsPayment->updatePayment($payment_id, array('payment_status' => MsPayment::STATUS_PAID, 'description' => 'Paid', 'date_paid' => 1));
                 $this->MsLoader->MsBalance->addBalanceEntry($result['seller_id'], array('payment_id' => $payment_id, 'balance_type' => MsBalance::MS_BALANCE_TYPE_WITHDRAWAL, 'amount' => -$result['amount'], 'description' => 'Payout'));
             }
         }
     }
     return $this->response->setOutput(json_encode($json));
 }