首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过GET和cURL转发PayPal沙箱数据

通过GET和cURL转发PayPal沙箱数据
EN

Stack Overflow用户
提问于 2022-11-15 07:50:35
回答 1查看 26关注 0票数 0

我试图传递paypal事务的数据,不是使用paypal建议的经典形式,而是使用cURL。有人能解释一下GET方法为什么会起作用吗?

代码语言:javascript
复制
    $fields = [
            'business'          => 'xxxxxxxxxxxxxxxxx@business.example.com',
            'cmd'               => '_xclick',
            'return'            => 'https://www.examplemysite.com/thank_you.php',
            'cancel_return'     => 'https://www.examplemysite.com/cart.php',
            'notify_url'        => 'https://www.examplemysite.com/ipn.php',
            'rm'                => '2',
            'currency_code'     => 'EUR',
            'lc'                => 'IT',
            'cbt'               => 'Continua',
            'shipping'          => $_POST['shipping'],
            'cs'                => '1',
            'item_name'         => $_POST['item_name'],
            'amount'            => $_POST['amount'],
            'custom'            => $_POST['custom'],
            'first_name'        => $_POST['first_name'],
            'last_name'         => $_POST['last_name'],
            'address1'          => $_POST['address1'],
            'city'              => $_POST['city'],
            'state'             => $_POST['state'],
            'zip'               => $_POST['zip'],
            'note'              => $_POST['note'],
            'email'             => $_POST['email']
    ];

    $fields_string = http_build_query($fields);

    header('Location: https://ipnpb.sandbox.paypal.com/cgi-bin/webscr?' . $fields_string);
    exit;

但当我使用cURL时,它不起作用吗?

代码语言:javascript
复制
    $fields = [
            'business'          => 'xxxxxxxxxxxxxxxxx@business.example.com',
            'cmd'               => '_xclick',
            'return'            => 'https://www.examplemysite.com/thank_you.php',
            'cancel_return'     => 'https://www.examplemysite.com/cart.php',
            'notify_url'        => 'https://www.examplemysite.com/ipn.php',
            'rm'                => '2',
            'currency_code'     => 'EUR',
            'lc'                => 'IT',
            'cbt'               => 'Continua',
            'shipping'          => $_POST['shipping'],
            'cs'                => '1',
            'item_name'         => $_POST['item_name'],
            'amount'            => $_POST['amount'],
            'custom'            => $_POST['custom'],
            'first_name'        => $_POST['first_name'],
            'last_name'         => $_POST['last_name'],
            'address1'          => $_POST['address1'],
            'city'              => $_POST['city'],
            'state'             => $_POST['state'],
            'zip'               => $_POST['zip'],
            'note'              => $_POST['note'],
            'email'             => $_POST['email']
    ];

    $fields_string = http_build_query($fields);

    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_SSLVERSION, 6);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    
    //execute post
    $result = curl_exec($ch);
    echo $result;

使用cURL,我看到,在地址栏中,仍然是我站点的地址(我故意更改了一些值,但概念是我应该看到paypal url):

IT&country.x=IT&flowId=4EY4066234167522P

EN

回答 1

Stack Overflow用户

发布于 2022-11-15 14:21:28

我试图传递paypal事务的数据,不是使用paypal建议的经典形式,而是使用cURL。

PayPal没有任何地方建议将头重定向到ipnpb.sandbox.paypal.com。对于结帐,应该使用paypal.com。ipnpb只是用于ipn验证的ipn回发,而您的代码不是这样的。

此外,这种网站付款标准的整合不能使用curl。它要求重定向实际客户的浏览器以及事务信息(post/get字段)。

要使用curl或类似的方法来设置事务,您需要使用PayPal API,例如当前/v2/结帐/订单 API。首先使用客户端id和机密获取access_token,然后创建订单。

一旦您能够成功地与PayPal API通信,最好的解决方案是在您的服务器上创建两条路由,并将它们与此审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server

对于API集成来说,IPN并不是必需的,捕获/执行响应会立即通知成功或失败以及事务信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74442163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档