Ejemplo n.º 1
0
<?php

if (isset($_GET)) {
    //require paypal class
    require_once "paypal.php";
    //GetExpressCheckoutDetails is optional, returns customer's details from paypal
    $paypal = new GetExpressCheckoutDetails();
    $details = $paypal->getResponse();
    $totalPrice = '100';
    //however you want to receive this (database linked to INVNUM, session var, etcetera)
    //DoExpressCheckoutPayment - returns success or failure
    //amount is optional, if not set, amount from .ini file is used
    $payment = new DoExpressCheckoutPayment($totalPrice);
    $payment_response = $payment->getResponse();
    if ($payment_response['PAYMENTSTATUS'] == 'Completed') {
        //print responce from GetExpressCheckoutDetails
        echo '<pre>';
        print_r($details);
        //print responce from DoExpressCheckoutPayment
        echo '<pre>';
        print_r($payment_response);
    } else {
        //print error
    }
}
Ejemplo n.º 2
0
 public function actionSubmitpaypal()
 {
     $paypal = new GetExpressCheckoutDetails();
     $details = $paypal->getResponse();
     //$totalPrice = urldecode($details['AMT']);
     $what = urldecode($details['CUSTOM']);
     $desc = urldecode($details["DESC"]);
     $cst = $details["CUSTOM"];
     $cst = explode("_", $cst);
     $type = $cst[2];
     $cst = $cst[1];
     $discount = $cst[3];
     if ($type == "basic") {
         $totalPrice = "19.95";
     } else {
         if ($type == "basicplus") {
             $totalPrice = "24.95";
         } else {
             if ($type == "pro") {
                 $totalPrice = "29.95";
             }
         }
     }
     $prorate = round($totalPrice * (((double) date('t') - (double) date('j')) / (double) date('t')), 2);
     $initAmt = $prorate + 0;
     // switch ($_SESSION["discount"]) {
     //     case 'MFVideoMgr-100':
     //         $prorate = $initAmt = 0;
     //         break;
     //     case 'MFVM-50A':
     //         $prorate = round((float)$prorate * 0.50, 2);
     //         $initAmt = round((float)$initAmt * 0.50, 2);
     //         break;
     //     case 'MFVM25':
     //         $prorate = round((float)$prorate * 0.25, 2);
     //         $initAmt = round((float)$initAmt * 0.25, 2);
     //         break;
     // }
     if (isset($_SESSION["discount"])) {
         Yii::import('admin.models.*');
         $coupon = Coupon::model()->findByAttributes(array('name' => $_SESSION["discount"]));
         if ($coupon) {
             if ($coupon->discount >= 100) {
                 //$initAmt = $initAmt - (2*$initAmt);
                 $prorate = 0.01;
                 $initAmt = 0.01;
             } else {
                 $prorate = $prorate - round((double) $prorate * ($coupon->discount / 100), 2);
                 $initAmt = $initAmt - round((double) $initAmt * ($coupon->discount / 100), 2);
             }
         }
     }
     $payment = new DoExpressCheckoutPayment($initAmt);
     $payment_response1 = $payment->getResponse();
     $recur = new CreateRecurringPaymentsProfile(ucfirst($type) . " Subscription for VidMgr, {$totalPrice} /mo", $totalPrice);
     // \n $0 One Time Setup Fee
     $recur->setNVP("SUBSCRIBERNAME", user()->Name);
     $recur->setNVP("PROFILEREFERENCE", "userid_" . uid() . "_" . $cst);
     $recur->setNVP("PROFILESTARTDATE", date("Y-m-d\\TH:i:s\\Z", mktime(0, 0, 0, date("m") + 1, 1, date("y"))));
     $recur->setNVP("MAXFAILEDPAYMENTS", "1");
     $recur->setNVP("BILLINGPERIOD", "Month");
     $recur->setNVP("BILLINGFREQUENCY", "1");
     $recur->setNVP("CURRENCYCODE", "USD");
     $recur->setNVP('L_PAYMENTREQUEST_0_NAME0', "Video Subscription - Basic 40MB");
     $recur->setNVP('L_PAYMENTREQUEST_0_ITEMCATEGORY0', 'Digital');
     $recur->setNVP('L_PAYMENTREQUEST_0_AMT0', $totalPrice);
     $recur->setNVP('L_PAYMENTREQUEST_0_QTY0', "1");
     $recur->setNVP("INITAMT", $initAmt);
     $payment_response = $recur->getResponse();
     Ytrace($payment_response);
     Ytrace($details);
     if ($payment_response["ACK"] == "Success" && $payment_response1["ACK"] == "Success") {
         Video::model()->updateByPk($cst, array("active" => "1", "lastPayment" => sqlDate(), "payModel" => $type));
         User::model()->updateByPk(uid(), array("payModel" => $type, "coupon" => ""));
         $this->process($cst, $type);
     } else {
         $this->renderText("There was some problem in processing your request. Please try again. If you repeatedly face this error please use the contact page, we would love to help you.");
     }
 }