/** * 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; } }
/** * 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; }
$payData->setOrderItems($orderItems); //Set the payment method //$constraints = array(FundingConstraint::BANK, FundingConstraint::CREDITCARD); // bank and card //$constraints = array(FundingConstraint::INVOICE); // only invoice //$constraints = array(FundingConstraint::BANK, FundingConstraint::CREDITCARD, FundingConstraint::INVOICE); // bank, card and invoice //$constraints = array(FundingConstraint::SMS); // only live environment. $constraints = array(FundingConstraint::BANK); // only bank $payData->setFundingConstraints($constraints); //Set the payer of Payson fees //Must be PRIMARYRECEIVER if using FundingConstraint::INVOICE $payData->setFeesPayer(FeesPayer::PRIMARYRECEIVER); // Set currency code $payData->setCurrencyCode(CurrencyCode::SEK); // Set locale code $payData->setLocaleCode(LocaleCode::SWEDISH); // Set guarantee options $payData->setGuaranteeOffered(GuaranteeOffered::OPTIONAL); /* * Step 2 initiate payment */ $payResponse = $api->pay($payData); /* * Step 3: verify that it suceeded */ if ($payResponse->getResponseEnvelope()->wasSuccessful()) { /* * Step 4: forward user */ header("Location: " . $api->getForwardPayUrl($payResponse)); }
private function getPaymentURL() { require_once 'payson/paysonapi.php'; $this->load->language('payment/paysondirect'); if (!$this->testMode) { $receiver = new Receiver(trim($this->config->get('payson_user_name')), $this->data['amount']); } else { $receiver = new Receiver('*****@*****.**', $this->data['amount']); } $sender = new Sender($this->data['sender_email'], $this->data['sender_first_name'], $this->data['sender_last_name']); $receivers = array($receiver); $payData = new PayData($this->data['ok_url'], $this->data['cancel_url'], $this->data['ipn_url'], $this->data['store_name'] . ' Order: ' . $this->data['order_id'], $sender, $receivers); $payData->setCurrencyCode($this->currencyPaysondirect()); $payData->setLocaleCode($this->languagePaysondirect()); $orderItems = $this->getOrderItems(); $constraints = ""; if ($this->isInvoice) { if ($this->hasInvoiceEnabled()) { $constraints = array(FundingConstraint::INVOICE); foreach ($orderItems as $key => $orderTotal) { if ($orderTotal->getSku() == "paysoninvoice_fee") { $payData->setInvoiceFee($orderTotal->getUnitPrice() * ($orderTotal->getTaxPercentage() + 1)); unset($orderItems[$key]); } } } else { $this->paysonApiError($this->language->get('error_invoice_not_enabled')); return; } } else { $constraints = array($this->config->get('payson_payment_method')); } $payData->setOrderItems($orderItems); $showReceiptPage = $this->config->get('paysondirect_receipt'); $payData->setShowReceiptPage($showReceiptPage); $this->writeArrayToLog($orderItems, sprintf('Order items sent to Payson (%sSEK)', $this->data['amount'])); $payData->setFundingConstraints($constraints); $payData->setGuaranteeOffered('NO'); $payData->setTrackingId($this->data['salt']); $payResponse = $this->api->pay($payData); if ($payResponse->getResponseEnvelope()->wasSuccessful()) { return array("Result" => "OK", "PaymentURL" => $this->api->getForwardPayUrl($payResponse)); } else { $errors = $this->logErrorsAndReturnThem($payResponse); return array("Result" => "ERROR", "ERRORS" => $errors); } }