当前位置: 首页>>代码示例>>PHP>>正文


PHP Paypal::doExpressCheckoutPayment方法代码示例

本文整理汇总了PHP中Paypal::doExpressCheckoutPayment方法的典型用法代码示例。如果您正苦于以下问题:PHP Paypal::doExpressCheckoutPayment方法的具体用法?PHP Paypal::doExpressCheckoutPayment怎么用?PHP Paypal::doExpressCheckoutPayment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Paypal的用法示例。


在下文中一共展示了Paypal::doExpressCheckoutPayment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Paypal

 function paypal_return($id = null)
 {
     //pr($this->params->query); //exit;
     $payerId = $this->params->query['PayerID'];
     $token = $this->params->query['token'];
     //get nvp string
     //use your own logic to get and set each variable
     $Payments = $this->Payment->findByToken($token);
     /*$nvpStr = "TOKEN=$token&PAYERID=$payerId";
       $nvpStr .="&PAYMENTREQUEST_0_CURRENCYCODE=MYR";
       $nvpStr .="&PAYMENTREQUEST_0_AMT=".number_format($Payments['Payment']['amount'],2,'.','');
       $nvpStr .="&PAYMENTREQUEST_0_AMT=".number_format($Payments['Payment']['amount'],2,'.','');
       $nvpStr .="&AYMENTREQUEST_0_PAYMENTACTION=Sale";
       $nvpStr .="&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital";
       $nvpStr .= "&L_PAYMENTREQUEST_0_NAME0=Harimau LTD \n Order#".$Payments['Payment']['order_no'];
       $nvpStr .= "&L_PAYMENTREQUEST_0_QTY0=1";
       $nvpStr .="&PAYMENTREQUEST_0_AMT=".number_format($Payments['Payment']['amount'],2,'.','');
       if(isset($shipping) and $shipping !=''){
           $nvpStr .= "&L_PAYMENTREQUEST_0_AMT0=5.00";
       }*/
     //echo $nvpStr;exit;
     $min_order_price = $this->Orderprices->find('first');
     $ShippingPrice = $this->ShippingPrice->find('first');
     if ($min_order_price['Orderprices']['price'] >= $Payments['Payment']['amount']) {
         $total = $Payments['Payment']['amount'] + $ShippingPrice['ShippingPrice']['price'];
         $shipping = 'ship';
     } else {
         $total = $Payments['Payment']['amount'];
     }
     $nvpStr = "TOKEN={$token}&PAYERID={$payerId}" . "&PAYMENTREQUEST_0_CURRENCYCODE=MYR" . "&PAYMENTREQUEST_0_AMT=" . number_format($total, 2, '.', '') . "&PAYMENTREQUEST_0_ITEMAMT=" . number_format($Payments['Payment']['amount'], 2, '.', '') . "&AYMENTREQUEST_0_PAYMENTACTION=Sale" . "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" . "&L_PAYMENTREQUEST_0_NAME0=Harimau LTD \n Order#" . $Payments['Payment']['order_no'] . "&L_PAYMENTREQUEST_0_QTY0=1" . "&L_PAYMENTREQUEST_0_AMT0=" . number_format($Payments['Payment']['amount'], 2, '.', '');
     if (isset($shipping) and $shipping == 'ship') {
         $nvpStr .= "&PAYMENTREQUEST_0_SHIPPINGAMT=" . number_format($ShippingPrice['ShippingPrice']['price'], 2, '.', '');
     }
     //do paypal setECCheckout
     App::import('Model', 'Paypal');
     $paypal = new Paypal();
     if ($paypal->doExpressCheckoutPayment($nvpStr) != false) {
         $result = $paypal->doExpressCheckoutPayment($nvpStr);
         $updatepaymetn = array();
         $updatepaymetn['Payment']['id'] = $Payments['Payment']['id'];
         $updatepaymetn['Payment']['transaction_id'] = $result['PAYMENTINFO_0_TRANSACTIONID'];
         $updatepaymetn['Payment']['status'] = $result['PAYMENTINFO_0_PAYMENTSTATUS'];
         $updatepaymetn['Payment']['amount'] = urldecode($result['PAYMENTINFO_0_AMT']);
         $updatepaymetn['Payment']['token'] = $token;
         $updatepaymetn['Payment']['payer_id'] = $payerId;
         $updatepaymetn['Payment']['paypal_date'] = urldecode($result['PAYMENTINFO_0_ORDERTIME']);
         if ($this->Payment->save($updatepaymetn)) {
             if (strtoupper($result['PAYMENTINFO_0_PAYMENTSTATUS']) == strtoupper('Completed')) {
                 $status = 'Paid';
                 $is_paid = '1';
             } else {
                 if (strtoupper($result['PAYMENTINFO_0_PAYMENTSTATUS']) == strtoupper('fail') or strtoupper($result['PAYMENTINFO_0_PAYMENTSTATUS']) == strtoupper('failed')) {
                     $status = 'Canceled';
                     $is_paid = '2';
                 } else {
                     $status = 'Pending';
                     $is_paid = '0';
                 }
             }
             //$this->PaymentConfig->updateAll(array('Image.type' => 'gallery'), array('Image.user_id' => $this->Auth->user('id')));
             $this->OrderDetail->updateAll(array('OrderDetail.status' => '"' . $status . '"', 'OrderDetail.is_paid' => '"' . $is_paid . '"', 'OrderDetail.payment_date' => "'" . date('Y-m-d H:i:s') . "'"), array('OrderDetail.order_no' => $Payments['Payment']['order_no']));
             $arr['Notification']['type'] = 'Order';
             $arr['Notification']['status'] = $status;
             $arr['Notification']['order_no'] = $Payments['Payment']['order_no'];
             $arr['Notification']['markas'] = 'Unread';
             $arr['Notification']['bell'] = 'On';
             $noti = $this->Notification->save($arr);
             $username = $this->Session->read('Auth.User.username');
             if (isset($username) and $username != '') {
                 $min_order_price = $this->Orderprices->find('first');
                 $ShippingPrice = $this->ShippingPrice->find('first');
                 $order_products = $this->OrderDetail->find('all', array('conditions' => array('order_no' => $Payments['Payment']['order_no'])));
                 $emaildata = $this->Product->paymentemail($order_products, $min_order_price, $ShippingPrice);
                 $Email = new CakeEmail('default');
                 $Email->template('welcome', 'fancy')->emailFormat('html')->from(array('harimau@test.com' => 'Harimau'))->to($username)->subject('Order details');
                 $Email->send($emaildata);
             }
         }
         //echo 'sfsdfsg';exit;
     } else {
         $this->log($paypal->errors);
         $result = false;
     }
     if ($result['PAYMENTINFO_0_ACK'] == 'Success') {
         $this->redirect('/purchases/success');
     }
     //pr($result);exit;
     //pr(urldecode($result['PAYMENTINFO_0_ORDERTIME']));
     // pr($paypal->errors); exit;
     if (false == $result) {
         //$this->Session->setFlash(__('Error while making payment, Please try again', true),'message_fail');
     } else {
         // $this->Session->setFlash(__('Thank you for purchasing our deal.', true),'message_ok');
     }
     //echo 'sdfsdf';exit;
     //$this->render('paypal_back');
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:97,代码来源:PurchasesController.php

示例2: paypal_return

 /**
  * Redirects buyer after the buyer approves the payment
  */
 public function paypal_return()
 {
     $this->layout = 'clean';
     $payerId = $this->request->query['PayerID'];
     $token = $this->request->query['token'];
     /*
      	If the buyer approves payment,you can optionally call GetExpressCheckoutDetails 
     	to obtain buyer details to display to your webpage.
     */
     //do paypal setECCheckout
     App::import('Model', 'Paypal');
     $paypal = new Paypal();
     //Build the NVP string
     $total_codes = $this->request->params['named']['filter']['total_codes'];
     $codePrice = $this->Upload->Code->getPrice($total_codes);
     $itemName = $this->Upload->Code->getItemName($total_codes);
     $nvpCheckoutStr = $paypal->buildNVPCheckoutString($token, $payerId, $codePrice, $itemName);
     if ($paypal->doExpressCheckoutPayment($nvpCheckoutStr)) {
         $result = true;
     } else {
         $this->log($paypal->errors, 'paypal_debug');
         $result = false;
     }
     if ($result === false) {
         $this->Session->setFlash(__('Error while making payment, Please try again', true), 'message_fail');
         // Send an email to the administor to see if he can resolve
         $message = 'There was an error generating the codes for the user\'s upload.';
         $message .= '\\n The user\'s name is: ' . $user['User']['fullname'];
         $message .= '\\n The user\'s email is: ' . $user['User']['email'];
         $message .= '\\n Upload ID: ' . $upload_id;
         $message .= '\\n Total codes to generate: ' . $total_codes;
         $subject = 'Payment error';
         $this->_sendErrorEmail($message, $subject);
     } else {
         $user_id = $this->request->params['named']['filter']['uuid'];
         $upload_id = $this->request->params['named']['filter']['uid'];
         //Generate file codes
         $codeCreationResult = $this->Upload->Code->generateCodes($upload_id, $total_codes);
         if ($codeCreationResult === true) {
             //Activate the user account
             $this->Upload->User->activate($user_id);
             //Add the total codes to the uploaded file for easy calculation and make the upload active
             $this->Upload->read(null, $upload_id);
             $this->Upload->set(array('total_codes' => $total_codes, 'active' => 1));
             $this->Upload->save();
             //Send the user their activation email
             $user = $this->Upload->User->read(null, $user_id);
             $this->_sendActivationEmail(null, array('user' => $user));
             //Codes generated successfully
             //$this->Session->setFlash(__('Thank you for purchasing.', true),'message_success');
         } else {
             //Code generation failed
             $this->Session->setFlash(__('Your purchase has completed, but there was an issue with the code generation. The administrator has been notified via email.', true), 'message_fail');
             // Send an email to the administor to see if he can resolve
             $message = 'There was an error generating the codes for the user\'s upload.';
             $message .= '\\n The user\'s name is: ' . $user['User']['fullname'];
             $message .= '\\n The user\'s email is: ' . $user['User']['email'];
             $message .= '\\n Upload ID: ' . $upload_id;
             $message .= '\\n Total codes to generate: ' . $total_codes;
             $subject = 'Code Generation Error';
             $this->_sendErrorEmail($message, $subject);
         }
     }
     //This window will close and redirect the user to the login page. To change the redirect, update this in the Views -> Uploads -> paypal_back.ctp file.
     $this->render('paypal_back');
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:69,代码来源:UploadsController.php


注:本文中的Paypal::doExpressCheckoutPayment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。