芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/thefirstcookout.com/support/application/libraries/APPPaddle.php
hasAdminSettingsAccess()) { AddOnManager::AddFilter("admin-menu-payment-list", [$this, "AdminMenu"]); } AddOnManager::AddAction('process-payment-paddle',[$this,"process_payment"],10,3); AddOnManager::AddAction('action-paddle-response',[$this, "paddle_response"],10,2); AddOnManager::AddAction('action-paddle-webhook',[$this, "paddle_web_hook"],10,2); if($this->GetSettingsValue("is_test_mode","N")=="Y"){ $this->is_test_mode=true; $this->api_endpoint="https://sandbox-checkout.paddle.com/api/"; $this->vendor_root="https://sandbox-vendors.paddle.com/api/"; $this->vendor_id=$this->GetSettingsValue("sand_vendor_id",""); $this->auth_code=$this->GetSettingsValue("sand_api_key","");; $this->valid_method=$this->GetSettingsValue("send_wh_valid_method","");; $this->public_key=$this->GetSettingsValue("sand_public_key","");; }else{ $this->api_endpoint="https://checkout.paddle.com/api/"; $this->vendor_root="https://vendors.paddle.com/api/"; $this->vendor_id=$this->GetSettingsValue("vendor_id",""); $this->auth_code=$this->GetSettingsValue("api_key","");; $this->valid_method=$this->GetSettingsValue("wh_valid_method","");; $this->public_key=$this->GetSettingsValue("public_key","");; } AddOnManager::AddAction('system-notification',[$this,"showNotification"]); add_filter("payment-method",function($methods){ $methods['D']="Paddle"; return $methods; },9); AddOnManager::AddFilter("payment-method-icon",function($methods){ $methods['D']=" ap ap-paddle-short"; return $methods; }); AddOnManager::AddFilter("payment-method-color",function($methods){ $methods['D']=" paddle-color text-bold"; return $methods; }); } /** * @param AppMenu $menuObj */ public function AdminMenu($menuObj){ $menuObj->AddSubMenu("AD", "Paddle Setting", "admin/addons/admin-page/paddle", "ap ap-paddle-short"); return $menuObj; } function showNotification(){ if(!ISDEMOMODE && $this->isActive() && $this->GetSettingsValue("is_test_mode")=="Y"){ GetSystemMsgItem("PDLN",'Paddle :',"Paddle payment has been enabled in test mode. So no real transaction will be done.
Please contact admin as early as possible
","danger",false); } } public function get_supported_currency() { return ['ARS','AUD','BRL','GBP','CAD','CNY','CZK','DKK','EUR','HKD','HUF','INR','ILS','JPY','MXN','TWD','NZD','NOK','PLN','RUB','SGD','ZAR','KRW','SEK','CHF','THB','TRY','UAH','USD']; } public function is_supported_currency($currency) { $supportedCurrencies=$this->get_supported_currency(); return in_array($currency,$supportedCurrencies); } function isActive() { return $this->GetSettingsValue("is_enable","N")=="Y"; } /** * @param String $payment_id * @param Mticket_payment $payment_obj * @param APP_Controller $controller */ public function process_payment($payment_id,$payment_obj,$controller) { $name = ""; $email = ""; $country = ""; $ticket = Mticket::FindBy("id", $payment_obj->ticket_id); if (!empty($ticket)) { $user = Msite_user::FindBy("id", $ticket->ticket_user); if (!empty($user->user_type == "U")) { $name = $user->first_name . ' ' . $user->last_name; $email = $user->email; $country = $user->country; } } $data = array(); $data['vendor_id'] = $this->vendor_id; $data['vendor_auth_code'] = $this->auth_code; $data['prices'] = array($payment_obj->payment_currency . ':' . ($payment_obj->amount)); $data['return_url'] = site_url("site/action/paddle-response/S/{$payment_obj->ticket_id}/{$payment_obj->reply_id}/{$payment_obj->id}"); $data['title'] = $payment_obj->payment_des; $data['image_url'] = image_url("images/logo.png"); $data['webhook_url'] = site_url("site/action/paddle-webhook/S/{$payment_obj->ticket_id}/{$payment_obj->reply_id}/{$payment_obj->id}"); $data['discountable'] = 0; $data['quantity_variable'] = 0; $data['customer_email'] = $email; $data['customer_postcode'] = ""; $data['customer_country'] = $country; $link = $this->getCheckoutLlink($data,$error); if (!empty($link)) { $this->showPopup($link,$email,$country); } else { echo '
'.$error.'
'; } } private function showPopup($link,$email,$country,$postCode=''){ ?>
$ticket_id, "reply_id" => $reply_id]); if (!$payment_obj) { $controller->DisplayMSGOnly("Process Failed"); return; } $controller->DisplayMSGOnly("Payment success", site_url("ticket/details/{$payment_obj->ticket_id}"), 10, true); return; } function paddle_web_hook($controller, $params) { $postvalue = AppSecurity::$_POSTData; $this->valid_method = strtoupper( $this->valid_method ); if ( $this->valid_method == "P" ) { if ( $this->VerifySignature( $postvalue ) ) { $this->complete_payment( $controller, $params ); } else { $this->AddFailedLog( "Payment request received form public key does not verified", $params ); } } else { if ( $this->isValidIP() ) { $this->complete_payment( $controller, $params ); } else { $this->AddFailedLog( "Payment request received form unauthorized IP", $params ); } } } private function complete_payment($controller, $params){ $ticket_id=$params[1]; $reply_id=$params[2]; $payment_id=$params[3]; $customer_name=""; $payment_obj = Mticket_payment::FindBy("id", $payment_id, ["ticket_id" => $ticket_id, "reply_id" => $reply_id]); $ticket=Mticket::FindBy("id",$payment_obj->ticket_id); if(!empty($ticket)){ $user=Msite_user::FindBy("id",$ticket->ticket_user); if(!empty($user->user_type =="U")){ $customer_name=$user->first_name.' '.$user->last_name; $email=$user->email; } } if (!empty($payment_obj)) { $customer_name = PostValue("p_customer_name",$customer_name); $card_or_payment_email = PostValue("p_customer_name",$customer_name); $total_amount = PostValue("p_price"); $transaction_id = PostValue("p_order_id"); $transaction_time = PostValue("event_time"); $approval_code = $transaction_id; $result_msg = "captured"; $country = PostValue("p_country"); if (!Mticket_payment::CompletePayment($payment_obj, $customer_name, $card_or_payment_email, $total_amount, $transaction_id, $transaction_time, $approval_code, $result_msg, $country,'D')) { $this->AddFailedLog("Payment done but completed", $params); } }else{ $this->AddFailedLog("Payment done but payment information doesn't match with database", $params); } } private function AddFailedLog($title,$params) { $postvalue = AppSecurity::$_POSTData; $std=new stdClass(); $std->params=$params; $std->postvalues=$postvalue; $std->server_var=$_SERVER; Mdebug_log::AddGeneralLog($title, Mdebug_log::STATUS_FAILED, Mdebug_log::ENTRY_TYPE_ERROR, print_r($std, true)); } function isValidIP(){ $production=['34.232.58.13','34.195.105.136','34.237.3.244']; $sandbox=['34.194.127.46','54.234.237.108','3.208.120.145']; $params=['REMOTE_ADDR','HTTP_X_REAL_IP','HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_CF_CONNECTING_IP']; foreach ($params as $param){ if(isset($_SERVER[$param])){ if($this->is_test_mode){ if(in_array($_SERVER[$param],$sandbox)){ return true; } }else{ if(in_array($_SERVER[$param],$production)){ return true; } } }else{ file_put_contents(APPPATH."/logs/WebHAPPPaddle.txt",$_SERVER[$param]."=> failed {$param}\n".date('Y-m-d H:i:s'),FILE_APPEND); } } return false; } function VerifySignature($postvalue){ $public_key_string =app_trim($this->public_key); $public_key = openssl_get_publickey($public_key_string); $signature = base64_decode($postvalue['p_signature']); $fields = $postvalue; unset($fields['p_signature']); ksort($fields); foreach($fields as $k => $v) { if(!in_array(gettype($v), array('object', 'array'))) { $fields[$k] = "$v"; } } $data = serialize($fields); $verification = openssl_verify($data, $signature, $public_key, OPENSSL_ALGO_SHA1); if($verification == 1) { return true; } else { return false; } } /** * @param $data_array */ public function getCheckoutLlink($data_array,&$error=""){ $post_param=http_build_query($data_array); $curl = curl_init(); $url=$this->vendor_root."2.0/product/generate_pay_link"; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 15, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $post_param, CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded', ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { $error= "cURL Error #:" . $err; } else { $resObj=json_decode($response); if(!empty($resObj->success) && !empty($resObj->response->url)){ return $resObj->response->url; }else{ $error=!empty($resObj->error->message)?$resObj->error->message:""; return ''; } } } public function getTitle() { return "Paddle"; } public function getButtonImageHTML() { return '
'; } public function AdminSettings($controller,$args){ $controller->SetTitle("Paddle Settings"); $params=http_build_query(array( 'app_name' => get_app_title().'- Paddle Payment Gateway', 'app_description' => 'Paddle Payment Gateway. Site name: ' .get_app_title(), 'app_icon' => image_url('images/logo.png', true) )); $PaddleConnectorUrl="https://vendors.paddle.com/vendor/external/integrate?". $params; $PaddleConnectorSandboxUrl="https://sandbox-vendors.paddle.com/vendor/external/integrate?". $params; $validation_types=["I"=>"Paddle Server IP Validation","P"=>"Public Key Validation"]; ?>
getUpdateUrl(),array("class"=>"form app-ajax-form form-horizontal","id"=>"app_basic_form","method"=>"post", "data-on-complete"=>"ajax_default_complete"));?>
GetPostValue("is_enable","N")=="Y"?' checked="checked"':'';?> value="Y" class="has_depend_fld" id="is_enable" name="is_enable" >
GetPostValue("is_test_mode","N")=="Y"?' checked="checked"':'';?> value="Y" class="has_depend_fld" id="is_test_mode" name="is_test_mode" >
" class="form-control" id="vendor_id" name="vendor_id" placeholder="" data-bv-notempty="true" data-bv-notempty-message=" ">
Paddle API Key
" class="form-control" id="api_key" name="api_key" placeholder="" data-bv-notempty="true" data-bv-notempty-message="">
Webhook Validation Type
GetPostValue("wh_valid_method","I"); GetHTMLRadioByArray("wh_valid_method","wh_valid_method","wh_valid_method",true,$validation_types,$valid_selected,false,true,"has_depend_fld"); ?>
Public Key
">GetPostValue("public_key",""); ?></textarea>
" class="form-control" id="sand_vendor_id" name="sand_vendor_id" placeholder="" data-bv-notempty="true" data-bv-notempty-message=" ">
" class="form-control" id="sand_api_key" name="sand_api_key" placeholder="" data-bv-notempty="true" data-bv-notempty-message="">
Webhook Validation Type
GetSettingsValue("sand_wh_valid_method","I"); GetHTMLRadioByArray("sand_wh_valid_method","sand_wh_valid_method","sand_wh_valid_method",true,$validation_types,$sand_valid_selected,false,true,"has_depend_fld"); ?>
Public Key
">GetPostValue("sand_public_key",""); ?></textarea>
sandbox') ; ?>
Instruction for Paddle details :
Login into your paddle Panel
Go to Developer Tools.
Then, go to Authentication and create auth code
Or
Press the connect button to do automatically