function payson_process($ipn = false)
 {
     global $event_details;
     $event_id = $this->erm->get_current_event_id();
     //key( ( array ) $_SESSION['__epl'][$regis_id]['events'] );
     if (is_null($event_id)) {
         return false;
     }
     $this->epl->load_file('libraries/gateways/payson/paysonapi.php');
     $url = epl_get_url();
     $regis_id = epl_get_element('regis_id', $_REQUEST, $this->erm->get_regis_id());
     $post_ID = epl_get_element('trackingId', $_REQUEST) ? intval(epl_get_element('trackingId', $_REQUEST)) : $this->erm->get_regis_post_id();
     if (!$ipn) {
         $gwID = epl_get_element('custom', $_REQUEST) ? intval(epl_get_element('custom', $_REQUEST)) : $this->erm->get_payment_profile_id();
         $gw_credentials = $this->_get_credentials($gwID, array('_epl_seller_email'));
         $credentials = new PaysonCredentials($gw_credentials['_epl_user'], $gw_credentials['_epl_pwd']);
         $api = new PaysonApi($credentials);
     }
     // echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r(get_post_meta($post_ID, '_epl_payment_method'), true). "</pre>";
     //ipn processor
     if ($ipn && $post_ID) {
         $gwID = get_post_meta($post_ID, '_epl_payment_method', true);
         $gw_credentials = $this->_get_credentials($gwID, array('_epl_seller_email'));
         $credentials = new PaysonCredentials($gw_credentials['_epl_user'], $gw_credentials['_epl_pwd']);
         $api = new PaysonApi($credentials);
         $postData = file_get_contents("php://input");
         $response = $api->validate($postData);
         if ($response->isVerified()) {
             // IPN request is verified with Payson
             // Check details to find out what happened with the payment
             $details = $response->getPaymentDetails();
             $data['post_ID'] = $post_ID;
             $data['_epl_regis_status'] = 5;
             $data['_epl_payment_amount'] = get_post_meta($post_ID, '_epl_grand_total', true);
             //$details->receivers[0]['amount'];
             $data['_epl_payment_date'] = current_time('mysql');
             //$data['_epl_transaction_id'] = $details->purchaseId;
             //$data = apply_filters( 'epl_payson_before_update_db', $data );
             $this->erm->update_payment_data($data);
         }
         return true;
     }
     $this->ecm->setup_event_details($event_id);
     $_totals = $this->erm->calculate_cart_totals();
     $returnUrl = add_query_arg(array('cart_action' => false, 'trackingId' => $post_ID, 'gw_id' => $gwID, 'custom' => $gwID, 'epl_action' => '_payson_success'), $url);
     $cancelUrl = add_query_arg(array('cart_action' => false, 'trackingId' => $post_ID, 'gw_id' => $gwID, 'custom' => $gwID, 'epl_action' => 'regis_form'), $url);
     $ipnUrl = add_query_arg(array('cart_action' => false, 'trackingId' => $post_ID, 'gw_id' => $gwID, 'custom' => $gwID, 'epl_action' => '_payson_ipn'), $url);
     $buyer_email = $this->erm->get_primary_field_value('email');
     $buyer_f_name = $this->erm->get_primary_field_value('first_name');
     $buyer_l_email = $this->erm->get_primary_field_value('last_name');
     $total = $_totals['money_totals']['grand_total'];
     $description = $event_details['post_title'];
     $receiver = new Receiver($gw_credentials['_epl_seller_email'], number_format($total, 2, ',', ''));
     // The amount you want to charge the user, here in SEK (the default currency)
     $receivers = array($receiver);
     $sender = new Sender($buyer_email, $buyer_f_name, $buyer_l_email);
     $payData = new PayData($returnUrl, $cancelUrl, $ipnUrl, $description, $sender, $receivers);
     // Set guarantee options
     $payData->setGuaranteeOffered(GuaranteeOffered::NO);
     /*
      * Step 2 initiate payment
      */
     $payResponse = $api->pay($payData);
     /*
      * Step 3: verify that it suceeded
      */
     if ($payResponse->getResponseEnvelope()->wasSuccessful()) {
         $data['post_ID'] = $post_ID;
         $data['_epl_regis_status'] = 2;
         $data['_epl_grand_total'] = number_format(epl_get_balance_due(), 2);
         $data['_epl_payment_amount'] = 0;
         $data['_epl_payment_date'] = '';
         $data['_epl_payment_method'] = $gwID;
         $data['_epl_transaction_id'] = '';
         $data['_epl_prediscount_total'] = number_format(epl_get_element('pre_discount_total', $_totals['money_totals'], 0), 2);
         $data['_epl_discount_amount'] = number_format(epl_get_element('discount_amount', $_totals['money_totals'], 0), 2);
         $data = apply_filters('epl_payson_before_update_db', $data);
         $this->erm->update_payment_data($data);
         return $payResponse;
         //need to return the $payResponse object
     } else {
         return false;
     }
 }
Exemple #2
0
/**
 * Read the request state (GET/POST) and return
 * our custom magic value (suspended booking ID).
 */
function confirm_payment()
{
    require_once 'payson/lib/paysonapi.php';
    $data = file_get_contents('php://input');
    $credentials = new PaysonCredentials(PAYSON_AGENT_ID, PAYSON_API_KEY);
    $api = new PaysonApi($credentials, IS_TEST);
    $response = $api->validate($data);
    if (!$response->isVerified()) {
        return false;
    }
    return payment_details_to_structure($response->getPaymentDetails());
}
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
require '../lib/paysonapi.php';
// Your agent ID and md5 key
$agentID = "4";
$md5Key = "2acab30d-fe50-426f-90d7-8c60a7eb31d4";
// Get the POST data
$postData = file_get_contents("php://input");
file_put_contents("test.txt", $postData);
// Set up API
$credentials = new PaysonCredentials($agentID, $md5Key);
$api = new PaysonApi($credentials, TRUE);
// Validate the request
$response = $api->validate($postData);
if ($response->isVerified()) {
    // IPN request is verified with Payson
    // Check details to find out what happened with the payment
    $details = $response->getPaymentDetails();
    // After we have checked that the response validated we have to check the actual status
    // of the transfer
    if ($details->getType() == "TRANSFER" && $details->getStatus() == "COMPLETED") {
        // Handle completed card & bank transfers here
    } elseif ($details->getType() == "INVOICE" && $details->getStatus() == "PENDING" && $details->getInvoiceStatus() == "ORDERCREATED") {
        // Handle accepted invoice purchases here
    } else {
        if ($details->getStatus() == "ERROR") {
            // Handle errors here
        }
    }