Paypal PHP SDK返回10002安全标头无效

时间:2016-06-07 03:43:50

标签: php paypal paypal-sandbox

我刚接触到paypal php SDK这是使用

的代码
 $RPProfileDetails = new RecurringPaymentsProfileDetailsType();
        $RPProfileDetails->SubscriberName = 'Test Customer';
        $RPProfileDetails->BillingStartDate = '29/5/2016';
        $activationDetails = new ActivationDetailsType();
        $activationDetails->InitialAmount = new BasicAmountType($currencyCode, 10);

        $activationDetails->FailedInitialAmountAction = 'ContinueOnFailure';//$_REQUEST['failedInitialAmountAction'];
        $paymentBillingPeriod =  new BillingPeriodDetailsType();
        $paymentBillingPeriod->BillingFrequency = 365;//$_REQUEST['billingFrequency'];
        $paymentBillingPeriod->BillingPeriod = 'Day';//$_REQUEST['billingPeriod'];
        $paymentBillingPeriod->TotalBillingCycles = 365;//$_REQUEST['totalBillingCycles'];
        $paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, 10);//$_REQUEST['paymentAmount']
        $scheduleDetails = new ScheduleDetailsType();
        $scheduleDetails->Description = 'Artist Access amount';//$_REQUEST['profileDescription'];
        $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
        $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
        $_REQUEST['token'] ='';
        if(trim($_REQUEST['token']) != "") {
            $createRPProfileRequestDetail->Token  = $_REQUEST['token'];
        } else {
            $creditCard = new CreditCardDetailsType();
            $creditCard->CreditCardNumber = '41111111111111111';//$_REQUEST['creditCardNumber'];
            $creditCard->CreditCardType = 'Visa';//$_REQUEST['creditCardType'];
            $creditCard->CVV2 = '111';//$_REQUEST['cvv'];
            $creditCard->ExpMonth = '9';//$_REQUEST['expMonth'];
            $creditCard->ExpYear = '2022';//$_REQUEST['expYear'];
            $createRPProfileRequestDetail->CreditCard = $creditCard;
        }
        $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
        $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
        $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
        $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
        $createRPProfileReq =  new CreateRecurringPaymentsProfileReq();
        $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
        $config = array(
                // values: 'sandbox' for testing
                //         'live' for production
                "mode" => "sandbox",
                'log.LogEnabled' => true,
                'log.FileName' => '../PayPal.log',
                'log.LogLevel' => 'FINE',

                // These values are defaulted in SDK. If you want to override default values, uncomment it and add your value.
                // "http.ConnectionTimeOut" => "5000",
                // "http.Retry" => "2",
                // Signature Credential
                "acct1.UserName" => "asp.mobileappz_api1.gmail.com",
                "acct1.Password" => "TR2R87Q3W7XT7UJQ",
                "acct1.Signature" => "AFcWxV21C7fd0v3bYYYRCpSSRl31Abq4txmPS2AOjtNVgh-ZRkhGwY3D",
                // Subject is optional and is required only in case of third party authorization
                // "acct1.Subject" => "",

                // Sample Certificate Credential
                // "acct1.UserName" => "certuser_biz_api1.paypal.com",
                // "acct1.Password" => "D6JNKKULHN3G5B8A",
                // Certificate path relative to config folder or absolute path in file system
                // "acct1.CertPath" => "cert_key.pem",
                // Subject is optional and is required only in case of third party authorization
                // "acct1.Subject" => "",
        );

        $paypalService = new PayPalAPIInterfaceServiceService($config);
        try {
            /* wrap API method calls on the service object with a try catch */
            $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
        } catch (Exception $ex) {
            echo '<pre>';
            PRINT_r($ex);
            //include_once("../Error.php");
            exit;
        }
        if(isset($createRPProfileResponse)) {
            echo "<table>";
            echo "<tr><td>Ack :</td><td><div id='Ack'>$createRPProfileResponse->Ack</div> </td></tr>";
            echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>".$createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID ."</div> </td></tr>";
            echo "</table>";
            echo "<pre>";
            print_r($createRPProfileResponse);
            echo "</pre>";
        }
    }
    Ack :   
Failure
ProfileID : 
PayPal\PayPalAPI\CreateRecurringPaymentsProfileResponseType Object
(
    [CreateRecurringPaymentsProfileResponseDetails] => PayPal\EBLBaseComponents\CreateRecurringPaymentsProfileResponseDetailsType Object
        (
            [ProfileID] => 
            [ProfileStatus] => 
            [TransactionID] => 
            [DCCProcessorResponse] => 
            [DCCReturnCode] => 
        )

    [Timestamp] => 2016-06-07T03:29:31Z
    [Ack] => Failure
    [CorrelationID] => 9c2a8533bb7f5
    [Errors] => Array
        (
            [0] => PayPal\EBLBaseComponents\ErrorType Object
                (
                    [ShortMessage] => Security error
                    [LongMessage] => Security header is not valid
                    [ErrorCode] => 10002
                    [SeverityCode] => Error
                    [ErrorParameters] => 
                )

        )

    [Version] => 106.0
    [Build] => 22204133
)

我已经越过检查它不是因为错误的凭证我在developer.paypal.com上设置了一个沙盒帐户,网址是sdk create也是沙箱,但是显示它不起作用请帮忙。我完全没有线索。这也是paypal sdk本身的标准示例。请提出错误的地方。

1 个答案:

答案 0 :(得分:0)

10002指的是不正确的API凭据, 您正在使用实时PayPal帐户凭据,并且已为沙箱设置代码

        "mode" => "sandbox",

将其更改为实时环境,然后重试。