使用我的购物车设置paypal-checkout-SDK。 [英] Setting up paypal-checkout-SDK with my shopping cart.

查看:1168
本文介绍了使用我的购物车设置paypal-checkout-SDK。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Paypal,



我正在努力将结帐SDK放入购物车。我一直按照开发者页面上的说明进行操作,并且我在页面上打开了paypal窗口的按钮。我有一个沙盒帐户。我可以从购物车到paypal窗口获得正确的价格,但我对实际的产品信息有疑问。我的问题是我使用JavaScript并将购物车总数输入到JSON对象中。我有SDK和示例,我看到创建沙箱环境客户端,如何单击按钮并在php中创建我的订单,以在paypal窗口中显示正确的详细信息。在我的沙盒上,我得到了买家帐户和商家帐户的正确总数,但产品详细信息和付款人信息我想从我的表单中获取用户信息并自动将它们插入到paypal窗口中。这是我的代码和我一直使用的一些示例代码。我找到了以旧方式执行此操作的方法,但在开发人员网站上,它表示使用新的集成而不是旧的方式。我的产品在$ _SESSION中并且用户数据被序列化

 <   div     class   =  容器 >  
< div class = col-md-12 my-3 > ;
< 按钮 type = button class = btn btn-primary > 测试详情< / button >
< / div >
< div class = col-md-12 >
< a < span class =code-attribute> id = btnPayPal > < / a >
< / div >
< < span class =code-leadattribute> / div >
< script >
var totalPrice = < ?php echo $ newtTotal; ?> ;
paypal.Buttons({
createOrder:function(data,actions){
// 设置事务
return actions.order.create({
payer:{
payer_info:{
email:' <?php echo $ email;?>'
first_name:' <?php echo $ fname;?>'
last_name: ' <?php echo $ lname;?>'
}
},
purchase_units:[{
金额:{
价值:totalPrice
}
}]
});
},
onApprove:function(data,actions){
// capture来自交易的资金
return actions.order.capture()。then(function(details){

< span class =code-comment> // 向买方显示成功消息
// alert(交易成功 - + details.payer.name.given_name);
/ / 调用事务到服务器保存
return fetch(' / paypal-transaction-complete',{
method:' post'
bod y:JSON.stringify({
orderID:data.orderID
})
});
});
}
})。render(' #btnPayPal');
在创建顺序中如何调用php createorder()
< ?php
namespace Sample\AuthorizeIntentExamples;
需要__DIR__。 ' /../../ vendor / autoload.php';
使用PayPalCheckoutSdk \ Orders \ OrdersCreateRequest;
使用Sample\PayPalClient;

class CreateOrder {
private static function buildRequestBody(){
return array(
' intent' = > ' AUTHORIZE'
' application_context' = >
array(),
' purchase_units' = >
数组(
0 = >
数组(
' CURRENCY_CODE' = > ' USD'
' value' = > ' 220.00'
),' items' = >
array(
< span class =code-digit> 0 = >
数组(
' name' = > ' T恤'
' description' = > ' Green XL'
' sku' = > ' sku01'
' unit_amount' = >
数组(
' currency_code' = > ' USD'
' value' = > ' 90.00'
),
// 代码是复制和粘贴的样本我需要的。





我看到PayPalClient和GetOrder和CreateOrder我想正确设置我的购物车所以我可以使用paypalclient - paypal-checkout-sdk php项目。



我的项目位于paypal沙箱的Rest API面板中。



我尝试了什么:



在完整的javascript中构建订单但被告知最好在php中执行此操作所以用户无法编辑订单。现在我想创建订单,并能够使用paypal sdk创建获取并将订单提交给paypal服务器进行交易

解决方案

_SESSION和用户数据被序列化

 <   div     class   =  container >  
< div class = col-md-12 my-3 >
< 按钮 = 按钮 class = btn btn-primary > 测试详情< / button >
< / div >
< div class = col-md-12 >
< a id = btnPayPal > < / a >
< / div >
< / div >
< script >
var totalPrice = < ?php echo


newtTotal; ?> ;
paypal.Buttons({
createOrder:function(data,actions){
// 设置事务
return actions.order.create({
payer:{
payer_info:{
email:' <?php echo


email;?> ',
first_name:' <?php echo


Hello Paypal,

I am working on putting your checkout SDK into my shopping cart. I been following the directions on the developers page and I have the buttons that open the paypal window on my page. I have a sandbox account. I can get the price correct from the cart to the paypal window but I have having problems with the actual product information. My problem is I am using JavaScript and inputting the cart total into the JSON object. I have the SDK and the examples and I see creating the sandbox environment client, how can I click the button and create my order in php to show the correct details in the paypal window. On my sandbox I get the correct total with the buyer account and the business account but the product details and payer info I want to grab the user info from the form I have and automatically insert them into the paypal window. Here is code I have and some of your example code I have been using. I found ways to do this the older way but on your developer site it says to use the new integration instead of the old way. My products are in the $_SESSION and user data is serialized

<div class="container">
    <div class="col-md-12 my-3">
        <button type="button" class="btn btn-primary">Test Details</button>
    </div>
    <div class="col-md-12">
        <a id="btnPayPal"></a>
    </div>
</div>
<script>
    var totalPrice = <?php echo $newtTotal; ?>;
paypal.Buttons({
        createOrder: function(data, actions) {
            // setup transaction
            return actions.order.create({
                payer: {
                    payer_info: {
                        email: '<?php echo $email; ?>',
                        first_name: '<?php echo $fname; ?>',
                        last_name: '<?php echo $lname; ?>'
                    }
                },
                purchase_units: [{
                   amount: {
                       value: totalPrice
                   }
                }]
            });
        },
        onApprove: function(data, actions) {
            // capture funds from transaction
            return actions.order.capture().then(function(details) {

                // show success msg to buyer
                // alert("Transaction success - " + details.payer.name.given_name);
                // call transaction to server save
                return fetch('/paypal-transaction-complete', {
                    method: 'post',
                    body: JSON.stringify({
                        orderID: data.orderID
                    })
                });
            });
        }
    }).render('#btnPayPal');
In the create order how can I call the php createorder()
<?php
namespace Sample\AuthorizeIntentExamples;
require __DIR__ . '/../../vendor/autoload.php';
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use Sample\PayPalClient;

class CreateOrder{
private static function buildRequestBody(){
        return array(
            'intent' => 'AUTHORIZE',
            'application_context' =>
                array(),
'purchase_units' =>
                array(
                    0 =>
                        array(
'currency_code' => 'USD',
                         'value' => '220.00',
), 'items' =>
                                array(
                                    0 =>
                                        array(
                                            'name' => 'T-Shirt',
                                            'description' => 'Green XL',
                                            'sku' => 'sku01',
                                            'unit_amount' =>
                                                array(
                                                    'currency_code' => 'USD',
                                                    'value' => '90.00',
                                                ),
// The code is pieces copy and pasted out samples I’ll need.



I see the PayPalClient and GetOrder and CreateOrder I would like to setup my shopping cart correctly so I can use the paypalclient – paypal-checkout-sdk php project.

My project is in the Rest API panel in the paypal sandbox.

What I have tried:

building a order in full javascript but been told it is better to do it in php so the user cannot edit the order. now i want to have the order created and be able to use the paypal sdk to create get and submit the order to the paypal server for a transaction

解决方案

_SESSION and user data is serialized

<div class="container">
    <div class="col-md-12 my-3">
        <button type="button" class="btn btn-primary">Test Details</button>
    </div>
    <div class="col-md-12">
        <a id="btnPayPal"></a>
    </div>
</div>
<script>
    var totalPrice = <?php echo


newtTotal; ?>; paypal.Buttons({ createOrder: function(data, actions) { // setup transaction return actions.order.create({ payer: { payer_info: { email: '<?php echo


email; ?>', first_name: '<?php echo


这篇关于使用我的购物车设置paypal-checkout-SDK。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆