$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)) {
             $payKey = $_SESSION['payKey'];
function SetPaymentOption($token)
{
    $SetPaymentOptionsRequest = new SetPaymentOptionsRequest();
    $SetPaymentOptionsRequest->requestEnvelope = new RequestEnvelope();
    $SetPaymentOptionsRequest->requestEnvelope->errorLanguage = "en_US";
    $SetPaymentOptionsRequest->payKey = $token;
    /*$SetPaymentOptionsRequest->initiatingEntity = new InitiatingEntity();
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer = new InstitutionCustomer();
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->institutionId = '';
    
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->firstName = '';
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->lastName = '';
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->displayName = '';
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->institutionCustomerId = '';
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->countryCode = '';
    	 $SetPaymentOptionsRequest->initiatingEntity->institutionCustomer->email = '';
    	 }
    	 $SetPaymentOptionsRequest->displayOptions = new DisplayOptions();
    	 $SetPaymentOptionsRequest->displayOptions->emailHeaderImageUrl = '';
    	 $SetPaymentOptionsRequest->displayOptions->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') {
        $FaultMsg = $ap->getLastError();
        echo "Transaction SetPaymentOption 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 "Transaction SetPaymentOption Successful! \n";
    }
}