2015-12-15 54 views
0

我在项目中工作因为我需要整合自适应支付网关。我提到代码here,它看起来简单和容易,但一旦我下载并运行该代码它不工作并行paypal付款不工作

,我发现这个问题。在进程页变量$ack被恢复故障

我怎样才能解决此问题

下面是示例代码

Process.php

<?php 
    session_start(); 
    require_once('../PPBootStrap.php'); 
    require_once('../Common/Constants.php'); 
    define("DEFAULT_SELECT", "- Select -"); 
    $returnUrl = "http://www.formget.com/tutorial/paypal-adaptive- payment/parallel/success.php"; 
    $cancelUrl = "http://www.formget.com/tutorial/paypal-adaptive- payment/parallel/index.php"; 
    $memo = "Adaptive Payment"; 
    $actionType = "PAY"; 
    $currencyCode = "USD"; 

    if ($_POST['booking'] == 'f') { 
     $receiverEmail = array("[email protected]"); 
     $receiverAmount = array("300.00"); 
     $primaryReceiver = array("false"); 
     $_SESSION['facilty_provider'] = array("AirGo Airline's Test Store"); 
    } elseif ($_POST['booking'] == 'h') { 
     $receiverEmail = array("[email protected]"); 
     $receiverAmount = array("200.00"); 
     $primaryReceiver = array("false"); 
     $_SESSION['facilty_provider'] = array("Hotel TheCompany's Test Store"); 
    } elseif ($_POST['booking'] == 'c') { 
     $receiverEmail = array("[email protected]"); 
     $receiverAmount = array("100.00"); 
     $primaryReceiver = array("false"); 
     $_SESSION['facilty_provider'] = array("MyCar Car Company's Test Store"); 
    } elseif ($_POST['booking'] == 'fh') { 
     $receiverEmail = array("[email protected]", "[email protected]"); 
     $receiverAmount = array("300.00", "200.00"); 
     $primaryReceiver = array("false", "false"); 
     $_SESSION['facilty_provider'] = array("AirGo Airline's Test Store", "Hotel  TheCompany's Test Store"); 
    } elseif ($_POST['booking'] == 'fc') { 
     $receiverEmail = array("[email protected]", "[email protected]"); 
     $receiverAmount = array("300.00", "100.00"); 
     $primaryReceiver = array("false", "false"); 
     $_SESSION['facilty_provider'] = array("AirGo Airline's Test Store", "MyCar  Car Company's Test Store"); 
    } elseif ($_POST['booking'] == 'hc') { 
     $receiverEmail = array("[email protected]", "[email protected]"); 
     $receiverAmount = array("200.00", "100.00"); 
     $primaryReceiver = array("false", "false"); 
     $_SESSION['facilty_provider'] = array("Hotel TheCompany's Test Store",  "MyCar Car Company's Test Store"); 
    } elseif ($_POST['booking'] == 'fhc') { 
     $receiverEmail = array("[email protected]", "[email protected]", "[email protected]"); 
     $receiverAmount = array("295.00", "195.00", "95.00"); 
     $primaryReceiver = array("false", "false", "false"); 
     $_SESSION['facilty_provider'] = array("AirGo Airline's Test Store", "Hotel  TheCompany's Test Store", "MyCar Car Company's Test Store"); 
    } else { 
     $receiverEmail = array("[email protected]"); 
     $receiverAmount = array("300.00"); 
     $primaryReceiver = array("false"); 
     $_SESSION['facilty_provider'] = array("AirGo Airline's Test Store"); 
    } 
    if (isset($receiverEmail)) { 
     $receiver = array(); 
     /* 
     * A receiver's email address 
     */ 
     for ($i = 0; $i < count($receiverEmail); $i++) { 
     $receiver[$i] = new Receiver(); 
     $receiver[$i]->email = $receiverEmail[$i]; 
     /* 
     * Amount to be credited to the receiver's account 
     */ 
     $receiver[$i]->amount = $receiverAmount[$i]; 
     /* 
     * Set to true to indicate a chained payment; only one receiver can be a  primary receiver. Omit this field, or set it to false for simple and parallel  payments. 
     */ 
     $receiver[$i]->primary = $primaryReceiver[$i]; 
    } 
     $receiverList = new ReceiverList($receiver); 
} 
$payRequest = new PayRequest(new RequestEnvelope("en_US"), $actionType, $cancelUrl, $currencyCode, $receiverList, $returnUrl); 
// Add optional params 
if ($memo != "") { 
    $payRequest->memo = $memo; 
} 
/* 
* ## Creating service wrapper object 
Creating service wrapper object to make API call and loading 
Configuration::getAcctAndConfig() returns array that contains credential and  config parameters 
*/ 


$service = new AdaptivePaymentsService(Configuration::getAcctAndConfig()); 
try { 
    /* wrap API method calls on the service object with a try catch */ 
    $response = $service->Pay($payRequest); 
    echo $ack = strtoupper($response->responseEnvelope->ack); 
    if ($ack == "SUCCESS") { 
     $_SESSION['pay_key'] = $payKey = $response->payKey; 
     $payKey = $response->payKey; 
     $payPalURL = PAYPAL_REDIRECT_URL . '_ap-payment&paykey=' . $payKey; 
     header('Location: ' . $payPalURL); 
    } 
} catch (Exception $ex) { 
    require_once '../Common/Error.php'; 
    exit; 
} 
+0

我建议你缩进你的代码,因为它是很难理解的。它会帮助你太在未来,如果你不需要做任何改变.. –

+0

什么是错误代码你从答复中得到了什么?介意分享? –

回答

0

我在这里发现了问题,问题出在你的配置文件中。有一个acct1.AppId变量。默认情况下,此示例代码的创建者已对其发表评论,因此您发送的请求中未包含App ID。要解决这个问题,你应该取消注释。之后尝试再次运行。

enter image description here