Monday, October 15, 2012

point to currency convert from payal to customer using php

point convert to currency to  paypal using php
$success = false;
if($task == 'pay' && $point && $user_points > $point && $mail != '' && $point >= 1000)
{
    $environment = 'live';    // or 'beta-sandbox' or 'live'
    function PPHttpPost($methodName_, $nvpStr_) {
        global $environment, $setting;
        $API_UserName = urlencode($setting['setting_paypal_api_user']);
        $API_Password = urlencode($setting['setting_paypal_api_pass']);
        $API_Signature = urlencode($setting['setting_paypal_api_sign']);
        $API_Endpoint = "https://api-3t.paypal.com/nvp";
        if("sandbox" === $environment || "beta-sandbox" === $environment) {
            $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
        }
        $version = urlencode('51.0');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
        $httpResponse = curl_exec($ch);
        if(!$httpResponse) {
            exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
        }
        $httpResponseAr = explode("&", $httpResponse);
        $httpParsedResponseAr = array();
        foreach ($httpResponseAr as $i => $value) {
            $tmpAr = explode("=", $value);
            if(sizeof($tmpAr) > 1) {
                $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
            }
        }
        if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
            exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
        }
        return $httpParsedResponseAr;
    }
   
    $emailSubject =urlencode($setting['setting_paypal_api_user']);
    $receiverType = urlencode('EmailAddress');
    $currency = urlencode('USD');
    $nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";
    $receiverEmail = urlencode($mail);
    $amount = urlencode($point / 100);
    $uniqueID = urlencode($user->user_info['user_id']);
    $note = urlencode('note');
    $nvpStr .= "&L_EMAIL0=$receiverEmail&L_Amt0=$amount&L_UNIQUEID0=$uniqueID&L_NOTE0=$note";
    $httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);
    if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
        $success = true;
        $cash = ($point / 100);
        $msg = "You have successfully exchanged $point points for $$cash!";
          userpoints_deduct($user->user_info['user_id'], $point);
        $database->database_query("INSERT INTO `ememo_socialdb`.`se_redeem_points` (`redeem_id`, `redeem_user`, `redeem_points`, `redeem_cash`, `redeem_date`) VALUES (NULL, '{$user->user_info[user_id]}', '$point', '$cash', UNIX_TIMESTAMP());");
    } else  {
        $success = true;
        $msg = 'Enter valid transaction information';
        print_r($httpParsedResponseAr);
      }
}
elseif($task == 'pay' && $user_points < $point)
{
    $success = true;
    $msg = 'You don\'t have enough points';

}
elseif($task == 'pay' && $point < 1000)
{
    $success = true;
    $msg = '1000 points is the minimal amount to redeem';

}
elseif($task == 'pay' && $mail == '')
{
    $success = true;
    $msg = 'Enter a valid PayPal e-mail address';

}

No comments:

Post a Comment