0
点赞
收藏
分享

微信扫一扫

thinkphp5.1接入paypal支付

王小沫 2022-03-11 阅读 63
php

thinkphp5.1接入paypal支付

php计入paypal,要先到https://developer.paypal.com/developer/dashboard/sandbox
下面以测试环境的来说明:
注册个开发者用户,然后在左边的菜单栏Sandbox accounts 新建测试用户,入下图:
在这里插入图片描述其中 Types:Business为商家(收款用) Types:Personal为个人(支付用)

获取商家的clientId,clientSecret,到左边菜单
在这里插入图片描述
创建个应用,然后点击应用,就可以 获取clientId,clientSecret,入下图:
在这里插入图片描述设置Webhook路径,再进入应用后,点击Add Webhook
在这里插入图片描述下面代码部分:


    function createOrder(){
        $clientId = "Ab4QAgRbIpIzDSxLQgE2dfffaan7mLR92rF0S8_-Vtrm0_Tq2SdKyh_-of6NuPlp_o5E-buPYtTh";
        $clientSecret = "EFop6xRqpbhdvatOckCs2-2bG0l8QycfatttffNuj0TADSm7TMwbq_EMWsRI-IWxEZKM46_t196JB-cLR";

        $environment = new SandboxEnvironment($clientId, $clientSecret);
        $client = new PayPalHttpClient($environment);

        // Construct a request object and set desired parameters
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders

        $request = new OrdersCreateRequest();
        $request->prefer('return=representation');
        $request->body = self::buildRequestBody(); 
        try {
            // Call API with your client and get a response for your call
            $response = $client->execute($request); 
            print_r($response);  
        }catch (HttpException $ex) {
            print_r($ex->getMessage());
        }
    }

接口返回的结果为:

PayPalHttp\HttpResponse Object
(
[statusCode] => 201
[result] => stdClass Object
(
[id] => 8YP3336604988663M
[intent] => AUTHORIZE
[status] => CREATED
[purchase_units] => Array
(
[0] => stdClass Object
(
[reference_id] => PUHF
[amount] => stdClass Object
(
[currency_code] => USD
[value] => 220.00
[breakdown] => stdClass Object
(
[item_total] => stdClass Object
(
[currency_code] => USD
[value] => 180.00
)

[shipping] => stdClass Object
(
[currency_code] => USD
[value] => 20.00
)

[handling] => stdClass Object
(
[currency_code] => USD
[value] => 10.00
)

[tax_total] => stdClass Object
(
[currency_code] => USD
[value] => 20.00
)

[shipping_discount] => stdClass Object
(
[currency_code] => USD
[value] => 10.00
)

)

)

[payee] => stdClass Object
(
[email_address] => sb-k6m0t14193073@business.example.com
[merchant_id] => VQZ5Q73L4S48S
)

[description] => Sporting Goods
[custom_id] => CUST-HighFashions
[soft_descriptor] => HighFashions
[items] => Array
(
[0] => stdClass Object
(
[name] => T-Shirt
[unit_amount] => stdClass Object
(
[currency_code] => USD
[value] => 90.00
)

[tax] => stdClass Object
(
[currency_code] => USD
[value] => 10.00
)

[quantity] => 1
[description] => Green XL
[sku] => sku01
[category] => PHYSICAL_GOODS
)

[1] => stdClass Object
(
[name] => Shoes
[unit_amount] => stdClass Object
(
[currency_code] => USD
[value] => 45.00
)

[tax] => stdClass Object
(
[currency_code] => USD
[value] => 5.00
)

[quantity] => 2
[description] => Running, Size 10.5
[sku] => sku02
[category] => PHYSICAL_GOODS
)

)

[shipping] => stdClass Object
(
[method] => United States Postal Service
[name] => stdClass Object
(
[full_name] => John Doe
)

[address] => stdClass Object
(
[address_line_1] => 123 Townsend St
[address_line_2] => Floor 6
[admin_area_2] => San Francisco
[admin_area_1] => CA
[postal_code] => 94107
[country_code] => US
)

)

)

)

[create_time] => 2022-03-02T05:27:04Z
[links] => Array
(
[0] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/8YP3336604988663M
[rel] => self
[method] => GET
)

[1] => stdClass Object
(
[href] => https://www.sandbox.paypal.com/checkoutnow?token=8YP3336604988663M
[rel] => approve
[method] => GET
)

[2] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/8YP3336604988663M
[rel] => update
[method] => PATCH
)

[3] => stdClass Object
(
[href] => https://api.sandbox.paypal.com/v2/checkout/orders/8YP3336604988663M/authorize
[rel] => authorize
[method] => POST
)

)

)

[headers] => Array
(
[] =>
[Content-Type] => application/json
[Content-Length] => 1801
[Connection] => keep-alive
[Date] => Wed, 02 Mar 2022 05
[Application_id] => APP-80W284485P519543T
[Cache-Control] => max-age=0, no-cache, no-store, must-revalidate
[Caller_acct_num] => VQZ5Q73L4S48S
[Paypal-Debug-Id] => b7c55b9bcbe64
[Strict-Transport-Security] => max-age=31536000; includeSubDomains
)

)

怎么已经创建订单成功了,接下来就是支付了。

另附:paypal-php-sdk下载

举报

相关推荐

0 条评论