예제 #1
0
$receivers = array($receiver);
// Details about the user that is the sender of the money
$sender = new Sender($senderEmail, $senderFirstname, $senderLastname);
$payData = new PayData($returnURL, $cancelURL, $ipnURL, "Min fina vara", $sender, $receivers);
//Set the list of products. For direct payment this is optional
$orderItems = array();
$orderItems[] = new OrderItem("Test produkt", 100, 1, 0.25, "kalle");
$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
예제 #2
0
/**
 * 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);
}
 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);
     }
 }