0

我在我的网站中使用 Paypal 自适应付款方式。

当我点击存款按钮时,我调用 deposit() 函数,然后贝宝为我提供类似于https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=PAY_KEY的重定向 URL

但是当我完成交易后返回我的网站时,我无法从贝宝获取会话中的支付密钥。

这是我的代码片段

function deposit() {
    try {
        $PayPalConfig = array('Sandbox' => true,
            'DeveloperAccountEmail' => xxx@yyy.com,
            'ApplicationID' => APP_ID,
            'DeviceID' => DEVICE_ID,
            'IPAddress' => IP_ADDRESS,
            'APIUsername' => API_USERNAME,
            'APIPassword' => API_PASSWORD,
            'APISignature' => API_SIGNATURE,
            'APISubject' => API_SUBJECT);
        $PayPal = new PayPal_Adaptive($PayPalConfig);
        // Prepare request arrays
        $PayRequestFields = array(
            'ActionType' => 'PAY', 
            'CancelURL' => CANCEL_URL, 
            'CurrencyCode' => 'USD',
            'FeesPayer' => 'SENDER',
            'IPNNotificationURL' => '',
            'Memo' => '',
            'Pin' => '', 
            'PreapprovalKey' => '',
            'ReturnURL' => RETURN_URL,
            'ReverseAllParallelPaymentsOnError' => '', 
            'SenderEmail' => '', 
            'TrackingID' => ''
        );
        $Receivers = array();

        $Receiver = array(
            'Amount' => 10,
            'Email' => MY_PAYPAL_ACCOUNT,
            'InvoiceID' => '',
            'PaymentType' => '',
            'PaymentSubType' => '',
            'Phone' => array('CountryCode' => '', 'PhoneNumber' => '', 'Extension' => ''), 
            'Primary' => 'false'
        );
        array_push($Receivers, $Receiver);


        $PayPalRequestData = array(
            'PayRequestFields' => $PayRequestFields,
            'Receivers' => $Receivers,
        );

        $PayPalResult = $PayPal->Pay($PayPalRequestData);

        if ($PayPalResult['Ack'] != 'Success')
            return FALSE;
        else if ($PayPalResult['PaymentExecStatus'] == CREATED)
            header('Location: '.$PayPalResult['RedirectURL']);
    } catch (Exception $ex) {
        die('Exception in API Call');
    }
}
4

0 回答 0