function payment($paymentDetails = array(array('paypalemail' => '*****@*****.**', 'amount' => 10.0)))
 {
     $payRequest = new PayRequest();
     $payRequest->actionType = "PAY";
     $returnURL = RETURN_URL;
     $cancelURL = CENCEL_URL;
     $payRequest->cancelUrl = $cancelURL;
     $payRequest->returnUrl = $returnURL;
     $payRequest->clientDetails = new ClientDetailsType();
     $payRequest->clientDetails->applicationId = API_APPLICATIONID;
     $payRequest->clientDetails->deviceId = '127001';
     $payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
     $payRequest->currencyCode = 'USD';
     $payRequest->senderEmail = PAYPAL_SENDER_EMAIL;
     $payRequest->requestEnvelope = new RequestEnvelope();
     $payRequest->requestEnvelope->errorLanguage = 'en_US';
     $receiverList = array();
     $i = 0;
     foreach ($paymentDetails as $paymentDetail) {
         $receiverList[$i] = new receiver();
         $receiverList[$i]->email = $paymentDetail['paypalemail'];
         $receiverList[$i]->amount = $paymentDetail['amount'];
         $i++;
     }
     $payRequest->receiverList = $receiverList;
     // Create service wrapper object
     $ap = new AdaptivePayments();
     // invoke business method on service wrapper passing in appropriate request params
     $response = $ap->Pay($payRequest);
     $adaptiveResponce['ap'] = $ap;
     $adaptiveResponce['response'] = $response;
     //$response1 = $ap->ExecutePayment($adaptiveResponce['response'],true);
     return $adaptiveResponce;
 }
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->firstName = $_REQUEST['firstName'];
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->lastName = $_REQUEST['lastName'];
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->displayName = $_REQUEST['displayName'];
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->institutionCustomerId = $_REQUEST['institutionCustomerId'];
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->countryCode = $_REQUEST['countryCode'];
     $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->email = $_REQUEST['email'];
 }
 $SetPaymentOptionsRequest->displayOptions = new DisplayOptions();
 $SetPaymentOptionsRequest->displayOptions->emailHeaderImageUrl = $_REQUEST['emailHeaderImageUrl'];
 $SetPaymentOptionsRequest->displayOptions->emailMarketingImageUrl = $_REQUEST['emailMarketingImageUrl'];
 /* Make the call to PayPal to get the Pay token
 	 If the API call succeded, then redirect the buyer to PayPal
 	 to begin to authorize payment.  If an error occured, show the
 	 resulting errors
 	 */
 $ap = new AdaptivePayments();
 $response = $ap->SetPaymentOptions($SetPaymentOptionsRequest);
 if (strtoupper($ap->isSuccess) == 'FAILURE') {
     $_SESSION['FAULTMSG'] = $ap->getLastError();
     $location = "APIError.php";
     header("Location: {$location}");
 } else {
     $_SESSION['payKey'] = $response->payKey;
     if ($response->responseEnvelope->ack == "Success") {
         if (isset($_GET['cs'])) {
             $_SESSION['payKey'] = '';
         }
         if (isset($_REQUEST["payKey"])) {
             $payKey = $_REQUEST["payKey"];
         }
         if (empty($payKey)) {
Exemplo n.º 3
0
 if (isset($_GET['cs'])) {
     $_SESSION['payKey'] = '';
 }
 try {
     if (isset($_REQUEST["payKey"])) {
         $payKey = $_REQUEST["payKey"];
     }
     if (empty($payKey)) {
         $payKey = $_SESSION['payKey'];
     }
     $pdRequest = new PaymentDetailsRequest();
     $pdRequest->payKey = $payKey;
     $rEnvelope = new RequestEnvelope();
     $rEnvelope->errorLanguage = "en_US";
     $pdRequest->requestEnvelope = $rEnvelope;
     $ap = new AdaptivePayments();
     $response = $ap->PaymentDetails($pdRequest);
     /* Display the API response back to the browser.
     		   If the response from PayPal was a success, display the response parameters'
     		   If the response was an error, display the errors received using APIError.php.
     		 */
     if (strtoupper($ap->isSuccess) == 'FAILURE') {
         $_SESSION['FAULTMSG'] = $ap->getLastError();
         $location = "APIError.php";
         header("Location: {$location}");
     }
 } catch (Exception $ex) {
     $fault = new FaultMessage();
     $errorData = new ErrorData();
     $errorData->errorId = $ex->getFile();
     $errorData->message = $ex->getMessage();
Exemplo n.º 4
0
function refund_order()
{
    global $wpdb;
    if (isset($_POST['btnRefundSubmit'])) {
        session_start();
        try {
            $currencyCode = $_REQUEST["currencyCode"];
            $payKey = $_REQUEST["payKey"];
            $email = $_REQUEST["receiveremail"];
            $amount = $_REQUEST["amount"];
            /* Make the call to PayPal to get the Pay token
               If the API call succeded, then redirect the buyer to PayPal
               to begin to authorize payment.  If an error occured, show the
               resulting errors
               */
            $refundRequest = new RefundRequest();
            $refundRequest->currencyCode = $currencyCode;
            $refundRequest->payKey = $payKey;
            $refundRequest->requestEnvelope = new RequestEnvelope();
            $refundRequest->requestEnvelope->errorLanguage = "en_US";
            $refundRequest->receiverList = new ReceiverList();
            $receiver1 = new Receiver();
            $receiver1->email = $email;
            $receiver1->amount = $amount;
            $refundRequest->receiverList->receiver = $receiver1;
            $ap = new AdaptivePayments();
            $response = $ap->Refund($refundRequest);
            if (strtoupper($ap->isSuccess) == 'FAILURE') {
                $_SESSION['FAULTMSG'] = $ap->getLastError();
                $location = "APIError.php";
                header("Location: {$location}");
            }
        } catch (Exception $ex) {
            $fault = new FaultMessage();
            $errorData = new ErrorData();
            $errorData->errorId = $ex->getFile();
            $errorData->message = $ex->getMessage();
            $fault->error = $errorData;
            $_SESSION['FAULTMSG'] = $fault;
            $location = "APIError.php";
            //header("Location: $location");
        }
    }
    //end if
    $order_pay_info = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_pay_info WHERE id = '" . $_GET['orderid'] . "'");
    $product_data = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_products WHERE product_id = '" . $order_pay_info->product_id . "'");
    $paypal_settings = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ign_pay_settings WHERE product_id = '" . $order_pay_info->product_id . "'");
    require 'languages/text_variables.php';
    echo '<div class="wrap">
			' . admin_menu_html();
    include_once 'templates/admin/_orderRefund.php';
    echo '</div>';
}
Exemplo n.º 5
0
 /**
  * Gets PayPal preapproval needed for the challenge
  */
 function get_preapproval_key(Challenge $challenge)
 {
     $amount = "50.00";
     // FIXME: calculate maximum amount that challenger may need to pay out (donation + challenge)
     error_reporting(E_ALL & ~E_STRICT);
     $token = '';
     $startDate = date('Y-m-d');
     $endDate = date('Y-m-d', time() + 3600 * 24 * 30 * 6);
     // FIXME: use real months
     $preapprovalRequest = new PreapprovalRequest();
     $preapprovalRequest->memo = "To be paid to charity if challenge is met";
     $preapprovalRequest->cancelUrl = $this->abs_url('cancel') . '?preapprovalKey=${preapprovalKey}';
     $preapprovalRequest->returnUrl = $this->abs_url('ok') . '?preapprovalKey=${preapprovalKey}';
     $preapprovalRequest->clientDetails = $this->clientDetails();
     $preapprovalRequest->currencyCode = self::CURRENCY;
     $preapprovalRequest->startingDate = $startDate;
     $preapprovalRequest->endingDate = $endDate;
     //		$preapprovalRequest->maxNumberOfPayments = "10" ;
     $preapprovalRequest->maxTotalAmountOfAllPayments = $amount;
     $preapprovalRequest->requestEnvelope = new RequestEnvelope();
     $preapprovalRequest->requestEnvelope->errorLanguage = "en_US";
     //default it is en_US, which is the only language currently supported
     $ap = new AdaptivePayments();
     $response = $ap->Preapproval($preapprovalRequest);
     if (strtoupper($ap->isSuccess) == 'FAILURE') {
         $FaultMsg = $ap->getLastError();
         $error = is_array($FaultMsg->error) ? $FaultMsg->error[0] : $FaultMsg->error;
         throw new Exception("Transaction Preapproval Failed: error Id: " . $error->errorId . ", error message: " . $error->message);
     } else {
         error_reporting(E_ALL | E_STRICT);
         return $response->preapprovalKey;
     }
 }
Exemplo n.º 6
0
    /* Make the call to PayPal to get the Pay token
       If the API call succeded, then redirect the buyer to PayPal
       to begin to authorize payment.  If an error occured, show the
       resulting errors
       */
    $refundRequest = new RefundRequest();
    $refundRequest->currencyCode = $currencyCode;
    $refundRequest->payKey = $payKey;
    $refundRequest->requestEnvelope = new RequestEnvelope();
    $refundRequest->requestEnvelope->errorLanguage = "en_US";
    $refundRequest->receiverList = new ReceiverList();
    $receiver1 = new Receiver();
    $receiver1->email = $email;
    $receiver1->amount = $amount;
    $refundRequest->receiverList->receiver = $receiver1;
    $ap = new AdaptivePayments();
    $response = $ap->Refund($refundRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    }
} catch (Exception $ex) {
    $fault = new FaultMessage();
    $errorData = new ErrorData();
    $errorData->errorId = $ex->getFile();
    $errorData->message = $ex->getMessage();
    $fault->error = $errorData;
    $_SESSION['FAULTMSG'] = $fault;
    $location = "APIError.php";
    header("Location: {$location}");
Exemplo n.º 7
0
 $receiver1->email = $_POST['receiveremail'][0];
 $receiver1->amount = $_REQUEST['amount'][0];
 $receiver1->primary = $_REQUEST['primary'][0];
 $receiver2 = new receiver();
 $receiver2->email = $_POST['receiveremail'][1];
 $receiver2->amount = $_REQUEST['amount'][1];
 $receiver2->primary = $_REQUEST['primary'][1];
 $payRequest->receiverList = array($receiver1, $receiver2);
 $payRequest->feesPayer = $feesPayer;
 $payRequest->memo = $memo;
 /* Make the call to PayPal to get the Pay token
    If the API call succeded, then redirect the buyer to PayPal
    to begin to authorize payment.  If an error occured, show the
    resulting errors
    */
 $ap = new AdaptivePayments();
 $response = $ap->Pay($payRequest);
 if (strtoupper($ap->isSuccess) == 'FAILURE') {
     $_SESSION['FAULTMSG'] = $ap->getLastError();
     $location = "APIError.php";
     header("Location: {$location}");
 } else {
     $_SESSION['payKey'] = $response->payKey;
     if ($response->paymentExecStatus == "COMPLETED") {
         $location = "PaymentDetails.php";
         header("Location: {$location}");
     } else {
         $token = $response->payKey;
         $payPalURL = PAYPAL_REDIRECT_URL . '_ap-payment&paykey=' . $token;
         header("Location: " . $payPalURL);
     }
Exemplo n.º 8
0
 function payment($paymentDetails = array(array('email' => '*****@*****.**', 'amount' => 10.0)))
 {
     $payRequest = new PayRequest();
     $payRequest->actionType = "PAY";
     $returnURL = RETURN_URL;
     $cancelURL = CENCEL_URL;
     $payRequest->cancelUrl = $cancelURL;
     $payRequest->returnUrl = $returnURL;
     $payRequest->clientDetails = new ClientDetailsType();
     $payRequest->clientDetails->applicationId = 'APP-80W284485P519543T';
     $payRequest->clientDetails->deviceId = '127001';
     $payRequest->clientDetails->ipAddress = '127.0.0.1';
     $payRequest->currencyCode = 'USD';
     $payRequest->senderEmail = '*****@*****.**';
     $payRequest->requestEnvelope = new RequestEnvelope();
     $payRequest->requestEnvelope->errorLanguage = 'en_US';
     /*$receiver1 = new receiver();
     		$receiver1->email = '*****@*****.**';
     		$receiver1->amount = '1.00';*/
     /*$receiver2 = new receiver();
     		$receiver2->email = '*****@*****.**';
     		$receiver2->amount = '1.00';*/
     $receiverList = array();
     $i = 0;
     foreach ($paymentDetails as $paymentDetail) {
         $receiverList[$i] = new receiver();
         $receiverList[$i]->email = $paymentDetail['email'];
         $receiverList[$i]->amount = $paymentDetail['amount'];
         $i++;
     }
     //$payRequest->receiverList = //array($receiver1, $receiver2);
     $payRequest->receiverList = $receiverList;
     // Create service wrapper object
     $ap = new AdaptivePayments();
     // invoke business method on service wrapper passing in appropriate request params
     $response = $ap->Pay($payRequest);
     $adaptiveResponce['ap'] = $ap;
     $adaptiveResponce['response'] = $response;
     return $adaptiveResponce;
 }
function idpp_process_handler()
{
    global $wpdb;
    $product_id = $_POST['Project'];
    $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'ign_pay_info WHERE product_id = %s AND status=%s', $product_id, 'W');
    //echo $sql;
    $res = $wpdb->get_results($sql);
    //print_r($res);
    $adaptive_pay_settings = getAdaptivePayPalSettings();
    // GETTING product default settings
    $default_prod_settings = getProductDefaultSettings();
    // Getting product settings and if they are not present, set the default settings as product settings
    $prod_settings = getProductSettings($product_id);
    if (empty($prod_settings)) {
        $prod_settings = $default_prod_settings;
    }
    require_once 'paypal/lib/AdaptivePayments.php';
    # Endpoint: this is the server URL which you have to connect for submitting your API request.
    //Chanege to https://svcs.paypal.com/  to go live */
    if ($adaptive_pay_settings->paypal_mode == "sandbox") {
        define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=');
        $app_id = "APP-80W284485P519543T";
    } else {
        define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/');
        define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=');
        $app_id = $adaptive_pay_setings->app_id;
    }
    /***** 3token API credentials *****************/
    define('API_AUTHENTICATION_MODE', '3token');
    define('API_USERNAME', $adaptive_pay_settings->api_username);
    define('API_PASSWORD', $adaptive_pay_settings->api_password);
    define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
    require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
    $no_success = array();
    $no_failures = array();
    foreach ($res as $payment) {
        if ($payment->preapproval_key !== '') {
            // Setting the necessary variables for the payment
            $returnURL = site_url('/');
            $cancelURL = site_url('/');
            $notifyURL = site_url('/') . '?ipn_handler=1';
            $currencyCode = $prod_settings->currency_code;
            $email = $payment->email;
            $preapprovalKey = $payment->preapproval_key;
            $requested = '';
            $payRequest = new PayRequest();
            $payRequest->actionType = "PAY";
            $payRequest->cancelUrl = $cancelURL;
            $payRequest->returnUrl = $returnURL;
            $payRequest->ipnNotificationUrl = $notifyURL;
            $payRequest->clientDetails = new ClientDetailsType();
            $payRequest->clientDetails->applicationId = $app_id;
            //"APP-1JE4291016473214C";
            //$payRequest->clientDetails->deviceId = DEVICE_ID;
            $payRequest->clientDetails->ipAddress = $_SERVER['REMOTE_ADDR'];
            $payRequest->currencyCode = $currencyCode;
            $payRequest->senderEmail = html_entity_decode($email);
            $payRequest->requestEnvelope = new RequestEnvelope();
            $payRequest->requestEnvelope->errorLanguage = "en_US";
            //$payRequest->preapprovalKey = "PA-16707604HP296522Y";
            //print_r($payRequest);
            if ($preapprovalKey !== "") {
                $payRequest->preapprovalKey = $preapprovalKey;
                //echo $preapprovalKey."keyhere";
            }
            $receiver1 = new receiver();
            $receiver1->email = $adaptive_pay_settings->paypal_email;
            $receiver1->amount = $payment->prod_price;
            $payRequest->receiverList = new ReceiverList();
            $payRequest->receiverList = array($receiver1);
            /* 	Make the call to PayPal to get the Pay token
             *	If the API call succeded, then redirect the buyer to PayPal
             *	to begin to authorize payment.  If an error occured, show the
             *	resulting errors
             */
            $ap = new AdaptivePayments();
            $response = $ap->Pay($payRequest);
            //echo "end of line<br/>";
            if (strtoupper($ap->isSuccess) == 'SUCCESS') {
                $no_success[] = 'success';
            } else {
                if (strtoupper($ap->isSuccess) == 'FAILURE') {
                    $no_failures[] = 'failure';
                    //echo "inside failure<br/>";
                    $fault = $ap->getLastError();
                    $errors_content = $fault->error->message;
                    //echo $errors_content;
                    // For error handling
                    /*if (is_object($fault->error))
                    				{ 
                    
                    					//$errors_content = '<table width =\"450px\" align=\"center\">';
                    					$errors_content;
                    					$errors_content = '';
                    					foreach($fault->error as $err) {
                    
                    						//$errors_content .= '<tr>';
                    						//$errors_content .= '<td>';
                    						//$errors_content .= 'Error ID: ' . $err->errorId . '<br />';
                    						//$errors_content .= 'Domain: ' . $err->domain . '<br />';
                    						//$errors_content .= 'Severity: ' . $err->severity . '<br />';
                    						//$errors_content .= 'Category: ' . $err->category . '<br />';
                    						$errors_content .= $err . "<br />";
                    
                    						if(empty($err->parameter)) {
                    							//$errors_content .= '<br />';
                    						}
                    						else {
                    							//$errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
                    						}
                    							
                    						//$errors_content .= '</td>';
                    						//$errors_content .= '</tr>';
                    					}
                    					//$errors_content .= '</table>';
                    				}
                    				else
                    				{
                    
                    					$errors_content = "";
                    					//$errors_content .= 'Error ID: ' . $fault->error->errorId . '<br />';
                    					//$errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
                    					//$errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
                    					//$errors_content .= 'Category: ' . $fault->error->category . '<br />';
                    					$errors_content .= $fault->error->message . '<br />';
                    					if(empty($fault->error->parameter)) {
                    						//$errors_content .= '</br>';
                    					}
                    					else {
                    						//$errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
                    					}
                    				}*/
                }
            }
        }
    }
    $response_array['counts'] = array('success' => count($no_success), 'failures' => count($no_failures));
    print_r(json_encode($response_array));
    exit;
}
Exemplo n.º 10
0
function ConvertCurrency()
{
    $CCRequest = new ConvertCurrencyRequest();
    $list = array();
    $baseamount = array('1.00', '100.00');
    $fromcode = array('GBP', 'EUR');
    $tocode = array('USD', 'CAD', 'JPY');
    for ($i = 0; $i < count($baseamount); $i++) {
        $ccType = new currency();
        $ccType->amount = $baseamount[$i];
        $ccType->code = $fromcode[$i];
        $list[$i] = $ccType;
    }
    $clist = array();
    for ($i = 0; $i < count($tocode); $i++) {
        $clist[$i] = array('currencyCode' => $tocode[$i]);
    }
    $CCRequest->baseAmountList = $list;
    $CCRequest->convertToCurrencyList = $clist;
    $CCRequest->requestEnvelope = new RequestEnvelope();
    $CCRequest->requestEnvelope->errorLanguage = "en_US";
    $ap = new AdaptivePayments();
    $response = $ap->ConvertCurrency($CCRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $FaultMsg = $ap->getLastError();
        echo "Transaction ConvertCurrency Failed: error Id: ";
        if (is_array($FaultMsg->error)) {
            echo $FaultMsg->error[0]->errorId . ", error message: " . $FaultMsg->error[0]->message;
        } else {
            echo $FaultMsg->error->errorId . ", error message: " . $FaultMsg->error->message;
        }
    } else {
        echo "ConvertCurrency Transaction Successful! \n";
    }
}
Exemplo n.º 11
0
session_start();
if (isset($_GET['cs'])) {
    $_SESSION['preapprovalKey'] = '';
}
try {
    if (isset($_REQUEST["preapprovalKey"])) {
        $preapprovalKey = $_REQUEST["preapprovalKey"];
    }
    if (empty($preapprovalKey)) {
        $preapprovalKey = $_SESSION['preapprovalKey'];
    }
    $PDRequest = new PreapprovalDetailsRequest();
    $PDRequest->requestEnvelope = new RequestEnvelope();
    $PDRequest->requestEnvelope->errorLanguage = "en_US";
    $PDRequest->preapprovalKey = $preapprovalKey;
    $ap = new AdaptivePayments();
    $response = $ap->PreapprovalDetails($PDRequest);
    /* Display the API response back to the browser.
    			   If the response from PayPal was a success, display the response parameters'
    			   If the response was an error, display the errors received using APIError.php.
    			*/
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    }
} catch (Exception $ex) {
    $fault = new FaultMessage();
    $errorData = new ErrorData();
    $errorData->errorId = $ex->getFile();
    $errorData->message = $ex->getMessage();
Exemplo n.º 12
0
    $preapprovalRequest = new PreapprovalRequest();
    $preapprovalRequest->cancelUrl = $cancelURL;
    $preapprovalRequest->returnUrl = $returnURL;
    $preapprovalRequest->clientDetails = new ClientDetailsType();
    $preapprovalRequest->clientDetails->applicationId = APPLICATION_ID;
    $preapprovalRequest->clientDetails->deviceId = DEVICE_ID;
    $preapprovalRequest->clientDetails->ipAddress = "127.0.0.1";
    $preapprovalRequest->currencyCode = $currencyCode;
    $preapprovalRequest->startingDate = $startingDate;
    $preapprovalRequest->endingDate = $endingDate;
    $preapprovalRequest->maxNumberOfPayments = $maxNumberOfPayments;
    $preapprovalRequest->maxTotalAmountOfAllPayments = $maxTotalAmountOfAllPayments;
    $preapprovalRequest->requestEnvelope = new RequestEnvelope();
    $preapprovalRequest->requestEnvelope->errorLanguage = "en_US";
    $preapprovalRequest->senderEmail = $senderEmail;
    $ap = new AdaptivePayments();
    $response = $ap->Preapproval($preapprovalRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        //Redirecting to APIError.php to display errors.
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    } else {
        // Redirect to paypal.com here
        $_SESSION['preapprovalKey'] = $response->preapprovalKey;
        $token = $response->preapprovalKey;
        $payPalURL = PAYPAL_REDIRECT_URL . '_ap-preapproval&preapprovalkey=' . $token;
        header("Location: " . $payPalURL);
    }
} catch (Exception $ex) {
    $fault = new FaultMessage();
Exemplo n.º 13
0
 $list = array();
 for ($i = 0; $i < count($_POST['baseamount']); $i++) {
     $ccType = new currency();
     $ccType->amount = $_REQUEST['baseamount'][$i];
     $ccType->code = $_REQUEST['fromcode'][$i];
     $list[$i] = $ccType;
 }
 $clist = array();
 for ($i = 0; $i < count($_POST['tocode']); $i++) {
     $clist[$i] = array('currencyCode' => $_REQUEST['tocode'][$i]);
 }
 $CCRequest->baseAmountList = $list;
 $CCRequest->convertToCurrencyList = $clist;
 $CCRequest->requestEnvelope = new RequestEnvelope();
 $CCRequest->requestEnvelope->errorLanguage = "en_US";
 $ap = new AdaptivePayments();
 $response = $ap->ConvertCurrency($CCRequest);
 /* Display the API response back to the browser.
 		   If the response from PayPal was a success, display the response parameters'
 		   If the response was an error, display the errors received using APIError.php.
 		*/
 if (empty($response->estimatedAmountTable)) {
     echo "<center><br><br><b>Invalid response from server</b><br></center>";
     echo "<center><a  href='Calls.html'>Home</a></center>";
     exit;
 }
 if (strtoupper($ap->isSuccess) == 'FAILURE') {
     $_SESSION['FAULTMSG'] = $ap->getLastError();
     $location = "APIError.php";
     header("Location: {$location}");
 }
Exemplo n.º 14
0
 public static function cancelPreapproval($invest, &$errors = array(), $fail = false)
 {
     try {
         if (empty($invest->preapproval)) {
             $invest->cancel($fail);
             return true;
         }
         $CPRequest = new \CancelPreapprovalRequest();
         $CPRequest->requestEnvelope = new \RequestEnvelope();
         $CPRequest->requestEnvelope->errorLanguage = "es_ES";
         $CPRequest->preapprovalKey = $invest->preapproval;
         $ap = new \AdaptivePayments();
         $response = $ap->CancelPreapproval($CPRequest);
         if (strtoupper($ap->isSuccess) == 'FAILURE') {
             Invest::setDetail($invest->id, 'paypal-cancel-fail', 'Ha fallado al cancelar el preapproval. Proceso libary/paypal::cancelPreapproval');
             $errors[] = 'Preapproval cancel failed.' . $ap->getLastError();
             @mail(\GOTEO_FAIL_MAIL, 'Fallo al cancelar preapproval Paypal API', 'ERROR en ' . __FUNCTION__ . '<br /><pre>' . print_r($ap->getLastError(), 1) . '</pre>');
             return false;
         } else {
             Invest::setDetail($invest->id, 'paypal-cancel', 'El Preapproval se ha cancelado y con ello el aporte. Proceso libary/paypal::cancelPreapproval');
             $invest->cancel($fail);
             return true;
         }
     } catch (Exception $ex) {
         $fault = new \FaultMessage();
         $errorData = new \ErrorData();
         $errorData->errorId = $ex->getFile();
         $errorData->message = $ex->getMessage();
         $fault->error = $errorData;
         Invest::setDetail($invest->id, 'paypal-cancel-fail', 'Ha fallado al cancelar el preapproval. Proceso libary/paypal::cancelPreapproval');
         $errors[] = 'Error fatal en la comunicación con Paypal, se ha reportado la incidencia. Disculpe las molestias.';
         @mail(\GOTEO_FAIL_MAIL, 'Error fatal en comunicacion Paypal API', 'ERROR en ' . __FUNCTION__ . '<br /><pre>' . print_r($fault, 1) . '</pre>');
         return false;
     }
 }
function adaptivePreapproval()
{
    if (isset($_POST['btnSubmitPreapproval'])) {
        global $wpdb;
        $tz = get_option('timezone_string');
        if (empty($tz)) {
            $tz = 'UTC';
        }
        date_default_timezone_set($tz);
        //print_r($_POST);
        session_start();
        $payment_variables = array("fname" => $_POST['first_name'], "lname" => $_POST['last_name'], "email" => $_POST['email'], "address" => $_POST['address'], "country" => $_POST['country'], "state" => $_POST['state'], "city" => $_POST['city'], "zip" => $_POST['zip'], "product_id" => absint($_POST['project_id']), "level" => absint($_POST['level']), "prod_price" => str_replace(',', '', $_POST['price']));
        $preapproval_key = "";
        $project = new ID_Project($variables['product_id']);
        $post_id = $project->get_project_postid();
        $product_name = get_the_title($post_id);
        $_SESSION['ig_payment_variables'] = http_build_query($payment_variables);
        // Getting the Adaptive payment settings
        $adaptive_pay_settings = getAdaptivePayPalSettings();
        require_once 'paypal/lib/AdaptivePayments.php';
        // GETTING product default settings
        $default_prod_settings = getProductDefaultSettings();
        // Getting product settings and if they are not present, set the default settings as product settings
        $prod_settings = getProductSettings(absint(esc_attr($_POST['project_id'])));
        if (empty($prod_settings)) {
            $prod_settings = $default_prod_settings;
        }
        # Endpoint: this is the server URL which you have to connect for submitting your API request.
        //Chanege to https://svcs.paypal.com/  to go live */
        if ($adaptive_pay_settings->paypal_mode == "sandbox") {
            define('API_BASE_ENDPOINT', 'https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval/');
            define('PAYPAL_REDIRECT_URL', 'https://www.sandbox.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey=' . $preapproval_key);
            $app_id = "APP-80W284485P519543T";
        } else {
            define('API_BASE_ENDPOINT', 'https://svcs.paypal.com/AdaptivePayments/Preapproval/');
            define('PAYPAL_REDIRECT_URL', 'https://www.paypal.com/webscr&cmd=_ap-preapproval&preapprovalkey=' . $preapproval_key);
            $app_id = $adaptive_pay_settings->app_id;
        }
        /***** 3token API credentials *****************/
        define('API_AUTHENTICATION_MODE', '3token');
        define('API_USERNAME', $adaptive_pay_settings->api_username);
        define('API_PASSWORD', $adaptive_pay_settings->api_password);
        define('API_SIGNATURE', $adaptive_pay_settings->api_signature);
        define('X_PAYPAL_APPLICATION_ID', $app_id);
        require_once 'paypal/lib/Config/paypal_sdk_clientproperties.php';
        $returnURL = site_url() . "/?payment_success=1&product_id=" . absint(esc_attr($_POST['project_id']));
        $cancelURL = site_url() . "/?payment_cancel=1";
        $notifyURL = esc_url(site_url()) . "/?ipn_handler=1&type=paypal_preauth&" . $_SESSION['ig_payment_variables'];
        $currencyCode = $prod_settings->currency_code;
        $senderEmail = esc_attr($_POST['email']);
        $preauth = new PreapprovalRequest();
        $preauth->cancelUrl = $cancelURL;
        $preauth->ipnNotificationUrl = $notifyURL;
        $preauth->returnUrl = $returnURL;
        $preauth->currencyCode = $currencyCode;
        $preauth->maxNumberOfPayments = "1";
        $preauth->maxNumberofPaymentsPerPeriod = 1;
        $preauth->endingDate = date("Y-m-d\\Z", strtotime("+ 364 day"));
        $preauth->startingDate = date('Y-m-d\\Z');
        $preauth->maxTotalAmountOfAllPayments = esc_attr(str_replace(',', '', $_POST['price']));
        $preauth->memo = $product_name . ' pledge of ' . number_format($_POST['price'], 2, '.', ',') . ' ' . $currencyCode;
        $preauth->clientDetails = new ClientDetailsType();
        $preauth->clientDetails->applicationId = $app_id;
        //$preauth->clientDetails->deviceId = DEVICE_ID;
        //$preauth->clientDetails->ipAddress = "127.0.0.1";
        //$preapprovalRequest->maxNumberOfPayments = $maxNumberOfPayments;
        //$preapprovalRequest->maxTotalAmountOfAllPayments = $maxTotalAmountOfAllPayments;
        $preauth->requestEnvelope = new RequestEnvelope();
        $preauth->requestEnvelope->errorLanguage = "en_US";
        $preauth->senderEmail = $senderEmail;
        $ap = new AdaptivePayments();
        $response = $ap->Preapproval($preauth);
        //print_r($preauth);
        //print_r($response);
        //print_r($ap);
        if (strtoupper($ap->isSuccess) == 'FAILURE') {
            $fault = $ap->getLastError();
            // For error handling
            if (is_array($fault->error)) {
                $errors_content = '<table width =\\"450px\\" align=\\"center\\">';
                foreach ($fault->error as $err) {
                    $errors_content .= '<tr>';
                    $errors_content .= '<td>';
                    $errors_content .= 'Error ID: ' . $err->errorId . '<br />';
                    $errors_content .= 'Domain: ' . $err->domain . '<br />';
                    $errors_content .= 'Severity: ' . $err->severity . '<br />';
                    $errors_content .= 'Category: ' . $err->category . '<br />';
                    $errors_content .= 'Message: ' . $err->message . '<br />';
                    if (empty($err->parameter)) {
                        $errors_content .= '<br />';
                    } else {
                        $errors_content .= 'Parameter: ' . $err->parameter . '<br /><br />';
                    }
                    $errors_content .= '</td>';
                    $errors_content .= '</tr>';
                }
                $errors_content .= '</table>';
            } else {
                $errors_content = 'Error ID: ' . $fault->error->errorId . '<br />';
                $errors_content .= 'Domain: ' . $fault->error->domain . '<br />';
                $errors_content .= 'Severity: ' . $fault->error->severity . '<br />';
                $errors_content .= 'Category: ' . $fault->error->category . '<br />';
                $errors_content .= 'Message: ' . $fault->error->message . '<br />';
                if (empty($fault->error->parameter)) {
                    $errors_content .= '</br>';
                } else {
                    $errors_content .= 'Parameter: ' . $fault->error->parameter . '<br /><br />';
                }
            }
            $_SESSION['paypal_errors_content'] = $errors_content;
        } else {
            // Redirect to paypal.com here
            $_SESSION['preapprovalKey'] = $response->preapprovalKey;
            $token = $response->preapprovalKey;
            $payPalURL = PAYPAL_REDIRECT_URL . '_ap-preapproval&preapprovalkey=' . $token;
            echo '<script type="text/javascript">window.location="' . $payPalURL . '";</script>';
        }
    }
}
Exemplo n.º 16
0
require_once '../../../lib/Stub/AP/AdaptivePaymentsProxy.php';
session_start();
try {
    $serverName = $_SERVER['SERVER_NAME'];
    $serverPort = $_SERVER['SERVER_PORT'];
    $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
    /* The returnURL is the location where buyers return when a
    	 payment has been succesfully authorized.
    	 The cancelURL is the location buyers are sent to when they hit the
    	 cancel button during authorization of payment during the PayPal flow                 */
    $payKey = $_REQUEST["payKey"];
    $executePaymentRequest = new ExecutePaymentRequest();
    $executePaymentRequest->payKey = $payKey;
    $executePaymentRequest->requestEnvelope = new RequestEnvelope();
    $executePaymentRequest->requestEnvelope->errorLanguage = "en_US";
    $ap = new AdaptivePayments();
    $response = $ap->ExecutePayment($executePaymentRequest);
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    } else {
        if ($response->paymentExecStatus == "COMPLETED") {
            if ($response->responseEnvelope->ack == "Success") {
                ?>
<html>
<head>

<title>PayPal Platform SDK - Execute Payment Options</title>
<link href="sdk.css" rel="stylesheet" type="text/css">
</head>
require_once '../../../lib/AdaptivePayments.php';
require_once '../../../lib/Stub/AP/AdaptivePaymentsProxy.php';
session_start();
if (isset($_GET['cs'])) {
    $_SESSION['preapprovalKey'] = '';
}
try {
    $preapprovalKey = $_REQUEST["preapprovalKey"];
    if (empty($preapprovalKey)) {
        $preapprovalKey = $_SESSION['preapprovalKey'];
    }
    $CPRequest = new CancelPreapprovalRequest();
    $CPRequest->requestEnvelope = new RequestEnvelope();
    $CPRequest->requestEnvelope->errorLanguage = "en_US";
    $CPRequest->preapprovalKey = $preapprovalKey;
    $ap = new AdaptivePayments();
    $response = $ap->CancelPreapproval($CPRequest);
    /* Display the API response back to the browser.
    		   If the response from PayPal was a success, display the response parameters'
    		   If the response was an error, display the errors received using APIError.php.
    		*/
    if (strtoupper($ap->isSuccess) == 'FAILURE') {
        $_SESSION['FAULTMSG'] = $ap->getLastError();
        $location = "APIError.php";
        header("Location: {$location}");
    }
} catch (Exception $ex) {
    $fault = new FaultMessage();
    $errorData = new ErrorData();
    $errorData->errorId = $ex->getFile();
    $errorData->message = $ex->getMessage();