/** * Create a new payment request, return the URL * to redirect the user to. */ function new_payment($is_giftcard, $media, $email, $custom, $return_url, $cancel_url, $ipn_url, $is_test) { require_once 'payson/lib/paysonapi.php'; // Assume that the user always want to buy a jump // Amount to send to receiver $amount = 2990; $prefix = $is_giftcard ? 'Presentkort: ' : ''; // Set the list of products. $order_items = array(); $order_items[] = new OrderItem($prefix . 'Tandemhopp', 2392, 1, 0.25, 'Hopp'); if ($media != null) { if (in_array('photo', $media) && in_array('video', $media)) { $order_items[] = new OrderItem($prefix . 'Video & Foto', 960, 1, 0.25, 'Foto+Video'); $amount += 1200; } else { if (in_array('photo', $media) || in_array('video', $media)) { $order_items[] = new OrderItem($prefix . 'Video eller Foto', 720, 1, 0.25, 'FotoEllerVideo'); $amount += 900; } } } $credentials = new PaysonCredentials(PAYSON_AGENT_ID, PAYSON_API_KEY); $api = new PaysonApi($credentials, IS_TEST); /* * To initiate a direct payment the steps are as follows * 1. Set up the details for the payment * 2. Initiate payment with Payson * 3. Verify that it suceeded * 4. Forward the user to Payson to complete the payment */ // Step 1: Set up details // Details about the receiver $receiver = new Receiver(PAYSON_RECEIVER, $amount); $receivers = array($receiver); // Details about the user that is the sender of the money $sender = new Sender($email, '', ''); $expire = date('Y-m-d', strtotime('+1 years')); $order_description = "Notera att din order måste nyttjas senast {$expire}."; $pay_data = new PayData($return_url, $cancel_url, $ipn_url, $order_description, $sender, $receivers); $pay_data->setOrderItems($order_items); // Set the payment method $constraints = array(FundingConstraint::BANK, FundingConstraint::CREDITCARD); $pay_data->setFundingConstraints($constraints); $pay_data->setFeesPayer(FeesPayer::PRIMARYRECEIVER); $pay_data->setCurrencyCode(CurrencyCode::SEK); $pay_data->setLocaleCode(LocaleCode::SWEDISH); $pay_data->setGuaranteeOffered(GuaranteeOffered::NO); $pay_data->setCustom(json_encode(array('is_giftcard' => $is_giftcard, 'custom' => $custom))); $pay_data->setShowReceiptPage(false); // Step 2: initiate payment $pay_response = $api->pay($pay_data); // Step 3: verify that it suceeded if (!$pay_response->getResponseEnvelope()->wasSuccessful()) { return false; } // Step 4: forward user return $api->getForwardPayUrl($pay_response); }
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; } }
ini_set("display_errors", 1); /* * Payson API Integration example for PHP * * More information can be found att https://api.payson.se * */ /* * On every page you need to use the API you * need to include the file lib/paysonapi.php * from where you installed it. */ require_once '../lib/paysonapi.php'; /* Every interaction with Payson goes through the PaysonApi object which you set up as follows */ $credentials = new PaysonCredentials("<your api userid>", "<your api password>"); $api = new PaysonApi($credentials); /* * To initiate a direct payment the steps are as follows * 1. Set up the details for the payment * 2. Initiate payment with Payson * 3. Verify that it suceeded * 4. Forward the user to Payson to complete the payment */ /* * Step 1: Set up details */ // URLs to which Payson sends the user depending on the success of the payment $returnUrl = "http://localhost/return.php"; $cancelUrl = "http://localhost/cancel.php"; // URL to which Payson issues the IPN $ipnUrl = "http://localhost/ipn.php";
<?php 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 }
/** * setup a payson connection, return the PayResponse object. * Only step 1 and 2 are done here * * To initiate a direct payment the steps are as follows * 1. Set up the details for the payment * 2. Initiate payment with Payson * 3. Verify that it suceeded * 4. Forward the user to Payson to complete the payment */ public static function setupPaysonConnection($payerEmail, $payerFname, $payerLname, $sumtopay, $paysonMsg) { global $SETTINGS; require_once '../php/libs/payson/paysonapi.php'; $credentials = new PaysonCredentials($SETTINGS["paysonAgentId"], $SETTINGS["paysonMD5"]); $api = new PaysonApi($credentials); // Step 1: Set up details $receiver = new Receiver($SETTINGS["paysonReceiverEmail"], $sumtopay); // The receiver and amount you want to charge the user, here in SEK (the default currency) $receivers = array($receiver); // Details about the user that is the sender of the money $sender = new Sender($payerEmail, $payerFname, $payerLname); $payData = new PayData($SETTINGS["paysonReturnUrl"], $SETTINGS["paysonCancelUrl"], $SETTINGS["paysonIpnUrl"], $paysonMsg, $sender, $receivers); $payData->setGuaranteeOffered(GuaranteeOffered::NO); // Step 2 initiate payment $payResponse = $api->pay($payData); $data['payResponse'] = $payResponse; $data['api'] = $api; return $data; }
<?php 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"; // Fetch the token that are returned $token = $_GET["TOKEN"]; // Initialize the API in test mode $credentials = new PaysonCredentials($agentID, $md5Key); $api = new PaysonApi($credentials, TRUE); // Get the details about this purchase $detailsResponse = $api->paymentDetails(new PaymentDetailsData($token)); // First we verify that the call to payson succeeded. if ($detailsResponse->getResponseEnvelope()->wasSuccessful()) { // Get the payment details from the response $details = $detailsResponse->getPaymentDetails(); // If the call to Payson went well we also have to check the actual status // of the transfer if ($details->getType() == "TRANSFER" && $details->getStatus() == "COMPLETED") { echo "Purchase has been completed <br /><h4>Details</h4><pre>" . $details . "</pre>"; } elseif ($details->getType() == "INVOICE" && $details->getInvoiceStatus() == "ORDERCREATED") { echo "Invoice has been created <br /><h4>Details</h4><pre>" . $details . "</pre>"; } else { if ($details->getStatus() == "ERROR") { echo "An error occured has occured <br /><h4>Details</h4><pre>" . $details . "</pre>"; } } /* Below are the other data that can be retreived from payment details
/** * Sets up the PaysonAPI with credentials * * @param PaysonCredentials $credentials */ public function __construct($credentials) { if (get_class($credentials) != "PaysonCredentials") { throw new PaysonApiException("Parameter must be of type PaysonCredentials"); } $this->credentials = $credentials; self::$instance = $this; }
function payment_page() { if ($this->erm->is_empty_cart()) { return $this->epl_util->epl_invoke_error(20, null, false); } global $event_details; $this->erm->_set_relevant_data(); $this->ecm->setup_event_details($this->erm->get_current_event_id()); $flow = epl_regis_flow(); if ($flow == 2 || $flow == 10) { $this->erm->_set_relevant_data(); //from the regis form, add to session $this->erm->add_registration_to_db(); } $this->erm->set_mode('overview'); $data['cart_data'] = $this->erm->show_cart(); $gateway_info = $this->erm->get_gateway_info(); $egm = $this->epl->load_model('epl-gateway-model'); $this->_setup_payment_type($gateway_info); $pay_type = $gateway_info['_epl_pay_type']; $is_cc = $gateway_info['_epl_pay_type'] == '_pp_pro' || $gateway_info['_epl_pay_type'] == '_auth_net_aim' || $gateway_info['_epl_pay_type'] == '_firstdata' || $gateway_info['_epl_pay_type'] == '_usa_epay' || $gateway_info['_epl_pay_type'] == '_qbmc' ? true : false; //will be refactored if ($pay_type == '_stripe') { $r = $egm->stripe_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } if ($pay_type == '_pp_pro') { $r = $egm->paypal_pro_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } if ($pay_type == '_pp_payflow') { $r = $egm->payflow_pro_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } elseif ($pay_type == '_auth_net_aim') { $r = $egm->authnet_aim_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } elseif ($pay_type == '_usa_epay') { $r = $egm->usa_epay_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } elseif ($pay_type == '_firstdata') { $r = $egm->firstdata_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } elseif ($pay_type == '_qbmc') { $r = $egm->qbmc_process(); if ($r === true) { return $this->thank_you_page($add_to_db); } else { $this->error = $r; return $this->show_cart_overview(); } } elseif ($pay_type == '_payson') { $r = $egm->payson_process(); if ($r !== false) { header("Location: " . PaysonApi::get_instance()->getForwardPayUrl($r)); } else { $this->error = '<div class="epl_error">ERROR: Please notify the website administrator.</div>'; return $this->regis_form(); } } elseif ($pay_type == '_moneris') { $r = $egm->moneris_process(); if ($r === true) { return $this->thank_you_page(false); } else { $this->error = $r; return $this->show_cart_overview(); } } else { $egm->_express_checkout_redirect(); } }