$tpls['rsvpme.list'] = $rsvpme->getChunk($listTpl, $rsvpme->validator->errors); } } } elseif (isset($_REQUEST['token'])) { if (!isset($_SESSION[$_REQUEST['token']])) { $modx->log(modX::LOG_LEVEL_ERROR, 'Token not set in session. How did they get here?'); return 'PayPal token not found.'; } /* paypal token is set */ $modx->log(modX::LOG_LEVEL_INFO, '[RSVPMe] PayPal TOKEN detected. Finishing registration and processing.'); if (!$modx->loadClass('rsvpme.payment.PayPal', $rsvpme->config['modelPath'], true, true)) { $modx->log(modX::LOG_LEVEL_ERROR, '[RSVPMe] Could not load PayPal class.'); return 'Sorry, there was an error completing the transaction.'; } $paypal = new PayPal($modx); $paypal->initialize(); $payer = $paypal->getExpressCheckoutDetails(array('token' => $_REQUEST['token'])); $modx->log(modX::LOG_LEVEL_INFO, 'PayPal transaction info: ' . print_r($payer, true)); $request = array('PAYMENTACTION' => 'Sale'); $details = array('TOKEN' => $_REQUEST['token'], 'PAYERID' => $payer['PAYERID'], 'AMT' => $_SESSION[$_REQUEST['token']]['AMT']); // Must re-initialize PayPal, as it closes the cURL object after each command. $paypal->initialize(); $result = $paypal->doExpressCheckoutPayment($request, $details); if ($result['ACK'] == 'Success' || $result['ACK'] == 'SuccessWithWarning') { $modx->log(modX::LOG_LEVEL_INFO, 'Payment completed: ' . print_r($result, true) . print_r($payer, true)); // Now that the payment has completed, we can finish registering the user. if (!($regtype = $modx->getObject('RSVPMeRegType', array('id' => $_SESSION[$_REQUEST['token']]['regtypeid'])))) { $modx->log(modX::LOG_LEVEL_ERROR, '[RSVPMe] There was an error when attempting to register paid guest. ' . print_r($result, true)); } $guest = array('name' => $payer['FIRSTNAME'] . ' ' . $payer['LASTNAME'], 'email' => $payer['EMAIL'], 'paid' => true); if ($rsvpme->registerPerson($regtype->id, $guest)) {