public function getEC()
 {
     $logger = new PPLoggingManager('GetExpressCheckout');
     // ## GetExpressCheckoutDetailsReq
     $getExpressCheckoutDetailsReq = new GetExpressCheckoutDetailsReq();
     // A timestamped token, the value of which was returned by
     // `SetExpressCheckout` response.
     $setEc = new SetExpressCheckout();
     $setEcResponse = $setEc->setExpressCheckout();
     var_dump($setEcResponse->Token);
     $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($setEcResponse->Token);
     $getExpressCheckoutDetailsReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     // ## Creating service wrapper object
     // Creating service wrapper object to make API call and loading
     // configuration file for your credentials and endpoint
     $service = new PayPalAPIInterfaceServiceService();
     try {
         // ## Making API call
         // Invoke the appropriate method corresponding to API in service
         // wrapper object
         $response = $service->GetExpressCheckoutDetails($getExpressCheckoutDetailsReq);
     } catch (Exception $ex) {
         $logger->error("Error Message : " + $ex->getMessage());
     }
     // ## Accessing response parameters
     // You can access the response parameters using variables in
     // response object as shown below
     // ### Success values
     if ($response->Ack == "Success") {
         // PayerID is PayPal Customer Account identification number
         // ($response->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID). This
         // value will be null unless you authorize the payment by
         // redirecting to PayPal after `SetExpressCheckout` call.
         $logger->log("PayerID : " . $response->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID);
     } else {
         $logger->error("API Error Message : " . $response->Errors[0]->LongMessage);
     }
     return $response;
 }
Example #2
0
 public function checkoutAction()
 {
     Zend_Session::start();
     $r = $this->getRequest();
     $paymentType = $r->getParam('paymentType');
     //$paymentType = $_GET['paymentType'];
     $this->view->paymentType = $paymentType;
     require_once "paypal/paypal.php";
     //paypal express checkout
     $paypal = new SetExpressCheckout();
     //amount is optional, if not provided,
     //amount from .ini file will be used
     $paypal->setNVP("L_NAME0", "Peraturan 2 2009");
     $paypal->setNVP("L_NUMBER0", "1");
     $paypal->setNVP("L_DESC0", "Hak Paten");
     $paypal->setNVP("L_AMT0", "20.00");
     $paypal->setNVP("L_QTY0", "1");
     $paypal->setNVP("AMT", "20.00");
     $paypal->setNVP("ALLOWNOTE", "1");
     $paypal->getResponse();
 }
Example #3
0
 public function actionPay($id = null, $type = "small")
 {
     if (!$id) {
         if (!isset($_SESSION["video_id"]) || !is_numeric($_SESSION["video_id"])) {
             app()->user->setFlash("success", "Select the video first");
             $this->redirect(array("video/admin"));
         }
         $id = $_SESSION["video_id"];
     }
     if ($type == "basic") {
         $totalPrice = "19.95";
     } else {
         if ($type == "basicplus") {
             $totalPrice = "24.95";
         } else {
             if ($type == "pro") {
                 $totalPrice = "29.95";
             }
         }
     }
     if (!is_numeric($totalPrice)) {
         // || (strpos($what, strtolower(getCompany())) === false))
         $this->redirect(url('site/pricing'));
     }
     $prorate = round($totalPrice * (((double) date('t') - (double) date('j')) / (double) date('t')), 2);
     $initAmt = $prorate + 0;
     if (isset($_SESSION["discount"])) {
         Yii::import('admin.models.*');
         $coupon = Coupon::model()->findByAttributes(array('name' => $_SESSION["discount"]));
         if ($coupon) {
             if ($coupon->discount >= 100) {
                 User::model()->updateByPk(uid(), array("payModel" => $type, "coupon" => $_SESSION["discount"]));
                 unset($_SESSION["discount"]);
                 app()->user->setFlash("success", "Your Subscription has been updated successfully! Thank you!");
                 //$this->redirect(url("video/update", array("id" => $cst)));
                 $this->redirect(url("/video/admin"));
                 //$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);
             }
         }
     }
     // 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;
     // }
     /*disp(sess("discount"));
       disp($_SESSION);
       disp($totalPrice);
       disp($initAmt);
       app()->end();
       */
     $paypal = new SetExpressCheckout($initAmt);
     $paypal->setNVP('METHOD', 'SetExpressCheckout');
     $paypal->setNVP("BRANDNAME", "VidMgr");
     $paypal->setNVP('PAYMENTREQUEST_0_ITEMAMT', $initAmt);
     if (isset($_SESSION["discount"])) {
         $paypal->setNVP("PAYMENTREQUEST_0_CUSTOM", "videoid_" . $id . "_{$type}" . "_" . $_SESSION["discount"]);
     } else {
         $paypal->setNVP("PAYMENTREQUEST_0_CUSTOM", "videoid_" . $id . "_{$type}" . "_0");
     }
     $paypal->setNVP('PAYMENTREQUEST_0_DESC', 'monthly credits');
     $paypal->setNVP('L_PAYMENTREQUEST_0_NAME0', "Prorated Video Subscription - " . ucfirst($type));
     $paypal->setNVP('L_PAYMENTREQUEST_0_ITEMCATEGORY0', 'Digital');
     $paypal->setNVP('L_PAYMENTREQUEST_0_AMT0', $prorate);
     /*        $paypal->setNVP('L_PAYMENTREQUEST_0_AMT1', $initAmt - $prorate);
               $paypal->setNVP('L_PAYMENTREQUEST_0_NAME1', "One Time Feee");
               $paypal->setNVP('L_PAYMENTREQUEST_0_ITEMCATEGORY1', 'Digital');*/
     $paypal->setNVP("L_BILLINGTYPE0", "RecurringPayments");
     $paypal->setNVP("L_BILLINGAGREEMENTDESCRIPTION0", ucfirst($type) . " Subscription for VidMgr, {$totalPrice} /mo");
     // \n $0 One Time Setup Fee
     $paypal->setNVP('PAYMENTREQUEST_0_AMT', $initAmt);
     $paypal->setNVP('BUYERREGISTRATIONDATE', '2013-06-24T05:38:48Z');
     $paypal->setNVP("BUYERID", "userid_" . uid() . "_" . $id);
     $paypal->setNVP('SOLUTIONTYPE', 'Sole');
     $paypal->setNVP('LANDINGPAGE', 'billing');
     $paypal->setNVP('REQCONFIRMSHIPPING', '0');
     $paypal->setNVP('ALLOWNOTE', '0');
     $paypal->setNVP("NOSHIPPING", "1");
     $paypal->setNVP("RETURNURL", $this->createAbsoluteUrl('payment/submitPaypal'));
     $paypal->setNVP('CANCELURL', $this->createAbsoluteUrl('/'));
     $paypal->setNVP("HDRIMG", "http://www.mfvideomgr.com/sites/default/files/LogoMediaFur.png");
     $paypal->setNVP("EMAIL", user()->email);
     $paypal->getResponse();
     unset($_SESSION["discount"]);
 }
Example #4
0
SetExpressCheckout::request("50.00");
//amount is optional, if not set
//amount from .ini file is used
//GetExpressCheckoutDetails - optional, returns customer's details from paypal
//this has to be one the page specified in SetExpressCheckout.ini
$response = GetExpressCheckoutDetails::request();
//DoExpressCheckoutPayment - returns success or failure
$response = DoExpressCheckoutPayment::request("50.00");
//amount is optional, if not set
//amount from .ini file is used
/*
+-------------------------------------------------------------------------------+
|   Recurring payments implementation                                           |
+-------------------------------------------------------------------------------+
*/
$test = new SetExpressCheckout("50.00");
//amount - optional, if not set
//amount form .ini file will be used
$test->setNVP("L_BILLINGTYPE0", "RecurringPayments");
$test->setNVP("L_BILLINGAGREEMENTDESCRIPTION0", "book order");
$test->getResponse();
//!!! you cannot use static method if you wan to use recurring payment, because
//you neet to set L_BILLINGTYPEn and L_BILLINGAGREEMENTDESCRIPTIONn
//get express checkout details (optional)
//the code below has to be placed in the file specified in RETURNURL
//(in SetExpressCheckout.ini) or setNVP() method
$result = GetExpressCheckoutDetails::request();
//there's no need to use: $data = new GetExpressCheckoutDetails();
//but if you want, you can
// now you can save data in database or whatever you want
//do express checkout returns success or failure
 /**
  * @test
  */
 public function setExpressCheckoutTest()
 {
     $setEc = new SetExpressCheckout();
     $response = $setEc->setEC();
     $this->assertNotNull($response->Token);
 }