openpayau/openpaylaravel

这是为Openpay实现支付服务的一个客户端

dev-master 2019-04-09 08:17 UTC

This package is not auto-updated.

Last update: 2024-09-21 10:03:20 UTC


README

  本文档主要针对composer php。如果您想使用我们的SDK进行基于composer的php开发,如Laravel,请前往安装Openpay composer包,运行以下命令

      composer require openpayau/openpaylaravel dev-master

  这里有一个使用说明。在这里,openpayau是Laravel框架的别名

  • 要安装Openpay composer包,请运行以下命令 composer require openpayau/openpaylaravel dev-master
     *After Installation give write permission to the log folder in the path: 
     "/vendor/openpayau/openpay/lib/Openpay/log".
  • 在任一控制器页面中包含Openpay.php
      require(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay/Common/Openpay.php'));
  • 在该文件中,基本URL定义如下,并使用这些常量
      define("URL","https://retailer.myopenpay.com.au/ServiceTraining/JAMServiceImpl.svc/");  //Openpay

测试模式或实时模式URL放置于此
        define("CALLBACK_URL",url('/callback'));                                      //Openpay Callback URL place here
        define("CANCEL_URL",url('/cancel'));                                          //Openpay Cancel URL place here
        define("FAILURE_URL",url('/failure'));                                        //Openpay Failure URL place here
        define("FORM_URL","https://retailer.myopenpay.com.au/WebSalesTraining/");     //Openpay Form Submit URL place here
        define("JAMTOKEN","Put your jamtoken here");  //Openpay Test Mode or Live Mode JAMTOKEN place here.(* When it is generate just change the JAMTOKEN) 
  • 然后您需要设置以下基本参数

                                                来自网站的用户参数

   

        if (!Session::has('cart')) 
        {
            return redirect()->route('product.shoppingcart');
        }
        
        $oldCart = Session::get('cart');
        
        $cart = new Cart($oldCart);
       
        try 
        {
              $chars = "0123456789";
              $res = "";
                 for ($i = 0; $i < 4; $i++) 
                 {
                   $res .= $chars[mt_rand(0, strlen($chars)-1)];
                 }

      $url=URL;

      $jamtoken=JAMTOKEN; 

      $PurchasePrice = 170.00;             //Format : 100.00(Not more than $1 million) , This values are comming form checkout form
      
      $JamCallbackURL = CALLBACK_URL;     //Not more than 250 characters
      
      $JamCancelURL = CANCEL_URL;         //Not more than 250 characters
      
      $JamFailURL =FAILURE_URL;          //Not more than 250 characters
	        
      $form_url =   FORM_URL;
      
      $JamRetailerOrderNo = '10000478';         //Consumer site order number, This values are comming form checkout form
      
      $JamEmail = 'gautamtest@gmail.com';       //Not more than 150 characters, This values are comming form checkout form
      
      $JamFirstName = 'Test';                   //First name(Not more than 50 characters), This values are comming form checkout form
      
      $JamOtherNames = 'Devloper';              //Middle name(Not more than 50 characters), This values are comming form checkout form
      
      $JamFamilyName = 'Test';                  //Last name(Not more than 50 characters), This values are comming form checkout form
      
      $JamDateOfBirth = '04 Nov 1982';          //dd mmm yyyy, This values are comming form checkout form
      
      $JamAddress1 = '15/520 Collins Street';   //Not more than 100 characters, This values are comming form checkout form
      
      $JamAddress2 = '';                        //Not more than 100 characters, This values are comming form checkout form
      
      $JamSubrub = 'Melbourne';                 //Not more than 100 characters, This values are comming form checkout form
      
      $JamState = 'VIC';                        //Not more than 3 characters, This values are comming form checkout form
      
      $JamPostCode = '3000';                    //Not more than 4 characters, This values are comming form checkout form
      
      $JamDeliveryDate = '01 Jan 2019';         //dd mmm yyyy, This values are comming form checkout form

      $JamGender = 'M';                         //M/F, This values are comming form checkout form

      $JamPhoneNumber = '9830000000';          //, This values are comming form checkout form

      $ChargeBackCount = 0;                     //How many chargebacks are known to have been received from this customer?-1 = Unknown

      $CustomerQuality = 1;

$PostValues = array(
                  'RetailerOrderNo'=>$JamRetailerOrderNo,
                  'ChargeBackCount'=>$ChargeBackCount,
                  'CustomerQuality'=>$CustomerQuality,
                  'FirstName'=>$JamFirstName,
                  'OtherNames'=>$JamOtherNames,
                  'FamilyName'=>$JamFamilyName,
                  'Email'=>$JamEmail,
                  'DateOfBirth'=>$JamDateOfBirth,
                  'Gender'=>$JamGender,
                  'PhoneNumber'=>$JamPhoneNumber,
                  'ResAddress1'=>$JamAddress1,
                  'ResAddress2'=>$JamAddress2,
                  'ResSuburb'=>$JamSubrub,
                  'ResState'=>$JamState,
                  'ResPostCode'=>$JamPostCode,
                  'DelAddress1'=>$JamAddress1,
                  'DelAddress2'=>$JamAddress2,
                  'DelSuburb'=>$JamSubrub,
                  'DelState'=>$JamState,
                  'DelPostCode'=>$JamPostCode
                  );  

  • 现在您需要调用Call-1 NEW ONLINE ORDER API方法,如下所示
        
  $Method = "NewOnlineOrder";
        $obj = new \openpayau\openpaylaravel\lib\Openpay\Api\NewOnlineOrder(URL,$Method,$PurchasePrice,JAMTOKEN, AUTHTOKEN,'','','','','','',$PostValues);
        $responsecall1 = $obj->_checkorder();
        $output = json_decode($responsecall1,true);
        $openErrorStatus = new \openpayau\openpaylaravel\lib\OpenPay\Exception\ErrorHandler();
        if($openErrorStatus !='')
        {
            $openErrorStatus->_checkstatus($output['status']);  
        } 

  • 将Call-1响应存储到日志文件,使用以下代码
       $log  = "Call-time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
       "Log: ".$responsecall1.PHP_EOL.
       "-------------------------".PHP_EOL;
            

将字符串保存到日志,使用FILE_APPEND以追加

      file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);

  • 现在我们已获得计划ID并准备进行支付,所以这里是Call-2 API
     
  
    if($output)
            {
              if($output['status'] == 0){

                $userdetails = Auth::user();
                $order = new Order;
                    $order->user_id = $userdetails->id;
                    $order->payment_id = 0;
                    $order->address = $request->input('address');
                    $order->name = $request->input('name');
                    $order->email = $request->input('email');
                    $order->final_amount = $PurchasePrice;
                    $order->plan_id = $output['PlanID'];

                    $order->save();
                    
                  $JamPlanID = $output['PlanID'];             //Plan ID retrieved from Web Call 1 API
                  $pagegurl = $form_url.'?JamCallbackURL='.$JamCallbackURL.'&JamCancelURL='.$JamCancelURL.'&JamFailURL='.$JamFailURL.'&JamAuthToken='.urlencode(JAMTOKEN).'&JamPlanID='.urlencode( (string) $JamPlanID);
                  
                  
                  try {
                    if($JamDateOfBirth)
                      \openpayau\openpaylaravel\lib\OpenPay\Validation\Validation::_validateDate($JamDateOfBirth);   
                    if($JamDateOfBirth)
                      \openpayau\openpaylaravel\lib\OpenPay\Validation\Validation::_validateDate($JamDeliveryDate);
                    if($JamState)
                      \openpayau\openpaylaravel\lib\OpenPay\Validation\Validation::_validateState($JamState);
                    if($JamPostCode)
                      \openpayau\openpaylaravel\lib\OpenPay\Validation\Validation::_validatePostcode($JamPostCode);     
                    $charge = \openpayau\openpaylaravel\lib\OpenPay\Api\OpenpayCharge::_charge($pagegurl);
                  }
                  catch(Exception $e) {
                    echo 'Message: ' .$e->getMessage();
                  }
                }else{
                  return redirect()->route('checkout')->with('error',$output['reason']);

                }
            }

        } catch (\Exception $e) {
            return redirect()->route('checkout')->with('error', $e->getMessage());
        }

  • 在openpay完成支付流程后,它将通过回调URL将用户重定向到商家网站
        成功URL
        [JamCallbackURL]?status=SUCCESS&planid=3000000022284&orderid=1402

        成功结果

          Array(
                  [status] => 0 
                    [reason] => Array
                              (
                              ) 
                      [PlanID] => 3000000022284
                      [PurchasePrice] => 110.0000
              )

        取消URL
        [JamCancelURL or JamCallbackURL]?status=CANCELLED&planid=3000000022284&orderid=1402

        取消结果

          Array (
                  [status] => CANCELLED 
                  [planid] => 3000000022284 
                  [orderid] => 1402 
               ) 

        失败URL
        [JamFailURL or JamCallbackURL]?status=FAILURE&planid=3000000022284&orderid=1402

        失败结果

          Array ( 
                  [status] => FAILURE 
                  [planid] => 3000000022284 
                  [orderid] => 1402 
               )

  • 添加以下Call-3 PAYMENT CAPTURE API
       
		$PlanID = '3000000019868'; // callback url get  
        $Method = "OnlineOrderCapturePayment";
        $obj=new\openpayau\openpaylaravel\lib\OpenPay\Api\OnlineOrderCapturePayment(URL,$Method,'',JAMTOKEN,AUTHTOKEN,$PlanID);
        $response = $obj->_checkorder(); 
        $output = json_decode($response,true); 
        $openErrorStatus=new\openpayau\openpaylaravel\lib\OpenPay\Exception\ErrorHandler();
        if($openErrorStatus !='')
            {
                $openErrorStatus->_checkstatus($output['status']);  
            }

向txt日志写入内容

      $log  = "Call 3 log time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
      "Log: ".$response.PHP_EOL.
      "-------------------------".PHP_EOL;

将字符串保存到日志,使用FILE_APPEND以追加

      file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);

  • 检查订单状态
      $PlanID = '3000000019868';                                      //Plan ID retrieved from Web Call 1 API
      $Method = "OnlineOrderStatus";
      $obj = new \openpayau\openpaylaravel\lib\OpenPay\Api\OnlineOrderStatus(URL,$Method,'',JAMTOKEN,AUTHTOKEN,$PlanID);
      $response = $obj->_checkorder(); 
      $output = json_decode($response,true); 
      $openErrorStatus=new\openpayau\openpaylaravel\lib\OpenPay\Exception\ErrorHandler();

向txt日志写入内容

       $log  = "Order status log time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
       "Log: ".$response.PHP_EOL.
       "-------------------------".PHP_EOL;

将字符串保存到日志,使用FILE_APPEND以追加

      file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);

  • 退款流程
        $PlanID = '3000000020110';          //Plan ID retrieved from Web Call 1 API
        $Method = "OnlineOrderReduction";
        $ReducePriceBy = 50.00;             //The amount you want to refund
        $type = False;                      //make True if want to refund full Plan price
        //echo $ReducePriceBy.'=='.$type;
        //die;
        //True if want to refund full Plan price
        $obj = new \openpayau\openpaylaravel\lib\Openpay\Api\PlanPurchasePriceReductionCall(URL, $Method, '', JAMTOKEN, AUTHTOKEN, $PlanID, '', $ReducePriceBy, $type);
        $response = $obj->_checkorder(); 
        $output = json_decode($response,true);    [dd($output);]
        $openErrorStatus=new\openpayau\openpaylaravel\lib\Openpay\Exception\ErrorHandler();

向txt日志写入内容

         $log  = "Order refund log time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
         "Log: ".$response.PHP_EOL.
         "-------------------------".PHP_EOL;

将字符串保存到日志,使用FILE_APPEND以追加

        file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);
    .

退款流程将按照以下步骤执行

    1. At the time of full refund the $ReducePriceBy should be set null and $type should be set False.

    2.For Partial refund $ReducePriceBy should be set as needed and $type should be set True.

    3.Retailers will get refund upto a certain amount which will be set by the Openpay merchant.Once the retailer has reached maximum refund amount limit they will get a message like “Invalid Web Sales Plan Status For Partial Refund”.

  • 计划分发

        此调用支持尚未设置接收任何付款的零售商,直到他们的系统发出分发通知。这允许那些零售商在履行之前根据需要调整他们的订单,然后在分发事件发生后接收付款和对账信息。

    $PlanID = '3000000020110';                                    //Plan ID retrieved from Web Call 1 API
    $Method = "OnlineOrderDispatchPlan";
    $obj=new\openpayau\openpaylaravel\lib\Openpay\Api\OnlineOrderDispatchPlan(URL,$Method,'',JAMTOKEN,AUTHTOKEN,$PlanID);
    $response = $obj->_checkOrderDispatchPlan(); 
    $output = json_decode($response,true); 
    $openErrorStatus=new\openpayau\openpaylaravel\lib\Openpay\Exception\ErrorHandler();

向txt日志写入内容

    $log  = "Order dispatch log time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
    "Log: ".$response.PHP_EOL.
    "-------------------------".PHP_EOL;

将字符串保存到日志,使用FILE_APPEND以追加

    file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);
  • 在线订单欺诈警报流程
        $PlanID = '3000000020110';          //Plan ID retrieved from Web Call 1 API
        $Method = "OnlineOrderFraudAlert";
        $Details = $req->input('fdetails'); //fraud text
        


       $obj = new \openpayau\openpaylaravel\lib\Openpay\Api\OnlineOrderFraudAlert(URL, $Method, '', JAMTOKEN, AUTHTOKEN, $PlanID, '', '' , '',$Details);
       $response = $obj->_OnlineOrderFraudAlert(); 
        $output = json_decode($response,true);    [dd($output);]
        $openErrorStatus=new\openpayau\openpaylaravel\lib\Openpay\Exception\ErrorHandler();

Something to write to txt log:

         $log  = "Order fraud log time: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
         "Log: ".$response.PHP_EOL.
         "-------------------------".PHP_EOL;

Save string to log, use FILE_APPEND to append:

        file_put_contents(app_path('/../vendor/openpayau/openpaylaravel/lib/Openpay').'/Log/log'.date("j.n.Y").'.log', $log, FILE_APPEND);
    .

This API call is provided for those systems that support latent customer fraud warning alerts that may be received outside of the normal process.