Пример #1
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);
}
Пример #2
0
/*
 * 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";
// Details about the receiver
$receiver = new Receiver("<your payson account>", 100);
// The 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("<sender email", "<sender firstname", "<sender lastname>");
print "\nPay:\n";
$payData = new PayData($returnUrl, $cancelUrl, $ipnUrl, "description", $sender, $receivers);
// 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));
}