コード例 #1
0
 /**
  * Validate payment
  */
 function ConfirmExpressCheckout()
 {
     $config = HCCoder_PayPalConfig::getInstance();
     // FIELDS
     $fields = array('USER' => get_option('paypal_api_username'), 'PWD' => get_option('paypal_api_password'), 'SIGNATURE' => get_option('paypal_api_signature'), 'VERSION' => '74.0', 'TOKEN' => $_GET['token'], 'METHOD' => 'GetExpressCheckoutDetails');
     $nb_fields = count($fields);
     $fields = http_build_query($fields);
     // $fields_string = '';
     // foreach ( $fields as $key => $value )
     // $fields_string .= $key.'='.$value.'&';
     // rtrim($fields_string,'&');
     // CURL
     $ch = curl_init();
     if (get_option('paypal_environment') == 'sandbox') {
         curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
     } elseif (get_option('paypal_environment') == 'live') {
         curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp');
     }
     curl_setopt($ch, CURLOPT_POST, $nb_fields);
     // curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //execute post
     $result = curl_exec($ch);
     //close connection
     curl_close($ch);
     parse_str($result, $result);
     if ($result['ACK'] == 'Success') {
         HCCoder_PayPalAPI::SavePayment($result, 'pending');
         HCCoder_PayPalAPI::DoExpressCheckout($result);
         return $result;
     } else {
         HCCoder_PayPalAPI::SavePayment($result, 'failed');
     }
 }