2

嗨,我注意到示例中有 3 个示例请求。

授权购买捕获

我不断收到 Security Header 无效的错误消息,所以我尝试编写自己的代码进行测试。

我想做的就是通过快速结账开始购买,而不发送信用卡详细信息。

到目前为止我的代码:

<?php


echo 'testing the omnipay';

require __DIR__.'/../Vendor/autoload.php';

use Omnipay\Common\GatewayFactory;

$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('some_username');
$gateway->setPassword('some_password');
$gateway->setSignature('some_signature');
$gateway->setTestMode(true);

echo 'start';
$params = array(
    'amount' => '1.99',
    'currency' => 'SGD',
    'description' => 'test purchase',
    'transactionId' => '123',
    'transactionReference' => '123ref',
    'returnUrl' => 'http://localhost:8000/gateways/PayPal_Express/completeAuthorize',
    'cancelUrl' => 'http://localhost:8000/gateways/PayPal_Express/authorize',

 );


echo 'end';

$response = $gateway->capture($params);
echo 'after capture';
echo '<pre> ';
print_r ($response);
echo '</pre> ';

我的输出是:

testing the omnipaystartendafter capture
 Omnipay\PayPal\Message\CaptureRequest Object
(
    [liveEndpoint:protected] => https://api-3t.paypal.com/nvp
    [testEndpoint:protected] => https://api-3t.sandbox.paypal.com/nvp
    [parameters:protected] => Symfony\Component\HttpFoundation\ParameterBag Object
        (
            [parameters:protected] => Array
                (
                    [username] => some_username
                    [password] => some_password
                    [signature] => some_signature
                    [testMode] => 1
                    [solutionType] => Sole
                    [landingPage] => Billing
                    [headerImageUrl] => 
                    [amount] => 1.99
                    [currency] => SGD
                    [description] => test purchase
                    [transactionId] => 123
                    [transactionReference] => 123ref
                    [returnUrl] => http://localhost:8000/gateways/PayPal_Express/completeAuthorize
                    [cancelUrl] => http://localhost:8000/gateways/PayPal_Express/authorize
                )

        )

    [httpClient:protected] => Guzzle\Http\Client Object
        (
            [defaultHeaders:protected] => Guzzle\Common\Collection Object
                (
                    [data:protected] => Array
                        (
                        )

                )

            [userAgent:protected] => Guzzle/3.7.2 curl/7.29.0 PHP/5.4.9-4ubuntu2.2
            [config:Guzzle\Http\Client:private] => Guzzle\Common\Collection Object
                (
                    [data:protected] => Array
                        (
                            [curl.options] => Array
                                (
                                    [78] => 60
                                    [10065] => /var/virtual/childlabel/label-ecommerce/src/labelecommapp/Vendor/guzzle/http/Guzzle/Http/Resources/cacert.pem
                                    [64] => 1
                                    [81] => 2
                                )

                        )

                )

            [baseUrl:Guzzle\Http\Client:private] => 
            [curlMulti:Guzzle\Http\Client:private] => 
            [uriTemplate:Guzzle\Http\Client:private] => 
            [requestFactory:protected] => Guzzle\Http\Message\RequestFactory Object
                (
                    [methods:protected] => Array
                        (
                            [getInstance] => 0
                            [__construct] => 1
                            [fromMessage] => 2
                            [fromParts] => 3
                            [create] => 4
                            [cloneRequestWithMethod] => 5
                            [applyOptions] => 6
                            [visit_headers] => 7
                            [visit_body] => 8
                            [visit_allow_redirects] => 9
                            [visit_auth] => 10
                            [visit_query] => 11
                            [visit_cookies] => 12
                            [visit_events] => 13
                            [visit_plugins] => 14
                            [visit_exceptions] => 15
                            [visit_save_to] => 16
                            [visit_params] => 17
                            [visit_timeout] => 18
                            [visit_connect_timeout] => 19
                            [visit_debug] => 20
                            [visit_verify] => 21
                            [visit_proxy] => 22
                            [visit_cert] => 23
                            [visit_ssl_key] => 24
                        )

                    [requestClass:protected] => Guzzle\Http\Message\Request
                    [entityEnclosingRequestClass:protected] => Guzzle\Http\Message\EntityEnclosingRequest
                )

            [eventDispatcher:protected] => Symfony\Component\EventDispatcher\EventDispatcher Object
                (
                    [listeners:Symfony\Component\EventDispatcher\EventDispatcher:private] => Array
                        (
                            [request.sent] => Array
                                (
                                    [100] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => Guzzle\Http\RedirectPlugin Object
                                                        (
                                                            [defaultMaxRedirects:protected] => 5
                                                        )

                                                    [1] => onRequestSent
                                                )

                                        )

                                )

                            [request.clone] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => Guzzle\Http\RedirectPlugin Object
                                                        (
                                                            [defaultMaxRedirects:protected] => 5
                                                        )

                                                    [1] => cleanupRequest
                                                )

                                        )

                                )

                            [request.before_send] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => Guzzle\Http\RedirectPlugin Object
                                                        (
                                                            [defaultMaxRedirects:protected] => 5
                                                        )

                                                    [1] => cleanupRequest
                                                )

                                        )

                                )

                        )

                    [sorted:Symfony\Component\EventDispatcher\EventDispatcher:private] => Array
                        (
                        )

                )

        )

    [httpRequest:protected] => Symfony\Component\HttpFoundation\Request Object
        (
            [attributes] => Symfony\Component\HttpFoundation\ParameterBag Object
                (
                    [parameters:protected] => Array
                        (
                        )

                )

            [request] => Symfony\Component\HttpFoundation\ParameterBag Object
                (
                    [parameters:protected] => Array
                        (
                        )

                )

            [query] => Symfony\Component\HttpFoundation\ParameterBag Object
                (
                    [parameters:protected] => Array
                        (
                        )

                )

            [server] => Symfony\Component\HttpFoundation\ServerBag Object
                (
                    [parameters:protected] => Array
                        (
                            [DOCUMENT_ROOT] => /var/virtual/childlabel/label-ecommerce/src/labelecommapp/example
                            [REMOTE_ADDR] => 127.0.0.1
                            [REMOTE_PORT] => 35783
                            [SERVER_SOFTWARE] => PHP 5.4.9-4ubuntu2.2 Development Server
                            [SERVER_PROTOCOL] => HTTP/1.1
                            [SERVER_NAME] => localhost
                            [SERVER_PORT] => 8000
                            [REQUEST_URI] => /test.php
                            [REQUEST_METHOD] => GET
                            [SCRIPT_NAME] => /test.php
                            [SCRIPT_FILENAME] => /var/virtual/childlabel/label-ecommerce/src/labelecommapp/example/test.php
                            [PHP_SELF] => /test.php
                            [HTTP_HOST] => localhost:8000
                            [HTTP_CONNECTION] => keep-alive
                            [HTTP_CACHE_CONTROL] => max-age=0
                            [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                            [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
                            [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
                            [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
                            [HTTP_COOKIE] => PHPSESSID=gm3gv1sb85rh0dpq8iiidut325
                            [REQUEST_TIME_FLOAT] => 1377418274.3256
                            [REQUEST_TIME] => 1377418274
                        )

                )

            [files] => Symfony\Component\HttpFoundation\FileBag Object
                (
                    [parameters:protected] => Array
                        (
                        )

                )

            [cookies] => Symfony\Component\HttpFoundation\ParameterBag Object
                (
                    [parameters:protected] => Array
                        (
                            [PHPSESSID] => gm3gv1sb85rh0dpq8iiidut325
                        )

                )

            [headers] => Symfony\Component\HttpFoundation\HeaderBag Object
                (
                    [headers:protected] => Array
                        (
                            [host] => Array
                                (
                                    [0] => localhost:8000
                                )

                            [connection] => Array
                                (
                                    [0] => keep-alive
                                )

                            [cache-control] => Array
                                (
                                    [0] => max-age=0
                                )

                            [accept] => Array
                                (
                                    [0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                                )

                            [user-agent] => Array
                                (
                                    [0] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
                                )

                            [accept-encoding] => Array
                                (
                                    [0] => gzip,deflate,sdch
                                )

                            [accept-language] => Array
                                (
                                    [0] => en-US,en;q=0.8
                                )

                            [cookie] => Array
                                (
                                    [0] => PHPSESSID=gm3gv1sb85rh0dpq8iiidut325
                                )

                        )

                    [cacheControl:protected] => Array
                        (
                            [max-age] => 0
                        )

                )

            [content:protected] => 
            [languages:protected] => 
            [charsets:protected] => 
            [acceptableContentTypes:protected] => 
            [pathInfo:protected] => 
            [requestUri:protected] => 
            [baseUrl:protected] => 
            [basePath:protected] => 
            [method:protected] => 
            [format:protected] => 
            [session:protected] => 
            [locale:protected] => 
            [defaultLocale:protected] => en
        )

    [response:protected] => 
)
4

1 回答 1

3

我不断收到安全标头无效的错误消息

请仔细检查您设置为网关的用户名、签名和密码。

您可以在https://developer.paypal.com/ Applications -> Sandbox Accounts 上找到它们。

选择一个企业帐户(如果不存在,则必须创建它),然后单击“个人资料”。然后打开选项卡“API 凭据”。而已。

注意:您的代码未完成,它应该包含响应检查(重定向?成功?)和当您从贝宝返回时调用 purchaseComplete 方法。

于 2013-08-29T11:04:02.660 回答