Javascript PayPal Express与JS:Production ID的签出集成

Javascript PayPal Express与JS:Production ID的签出集成,javascript,php,paypal,Javascript,Php,Paypal,我刚刚在CMS中实现了PayPal Express结账集成。有了我们的沙盒ID,一切正常,但对于我们的实时环境,我们的客户必须将他们的paypal API凭证放入我们的系统中。在paypal开发者文档中,我找不到任何解决方案,如何将这些客户凭证集成到Express Checkout集成代码中 谁能帮帮我吗 <div id='paypal-button'></div>

我刚刚在CMS中实现了PayPal Express结账集成。有了我们的沙盒ID,一切正常,但对于我们的实时环境,我们的客户必须将他们的paypal API凭证放入我们的系统中。在paypal开发者文档中,我找不到任何解决方案,如何将这些客户凭证集成到Express Checkout集成代码中

谁能帮帮我吗

                    <div id='paypal-button'></div>                          
                        <script>
                            paypal.Button.render({

                                env: 'production', // Specify 'sandbox' for the test environment, 'production'

                            style: {
                                        size: 'medium',
                                        color: 'silver',
                                        shape: 'rect'
                                    },                                  

                            client: {
                                    sandbox:    'ASoNxxxxxxxxxxxxxxxxxxx',
                                    production: '$customer_api'
                                },

                                payment: function(resolve, reject) {
                                    // Set up the payment here, when the buyer clicks on the button
                                    var env    = this.props.env;
                                    var client = this.props.client;

                                    return paypal.rest.payment.create(env, client, {
                                        'intent': 'sale',
                                        'payer':{
                                            'payer_info': {
                                                'email': '$email',
                                                'first_name': '$vorname',
                                                'last_name': '$nachname',
                                                'shipping_address': {
                                                    'line1': '$strasse',
                                                    'city': '$ort',                                                     
                                                    'postal_code': '$plz',
                                                    'country_code': '$land',
                                                    'recipient_name': '$firma'
                                                }
                                            }
                                        },
                                        transactions: [
                                            {
                                                amount: {
                                                    'total': '$total',
                                                    'currency': '$currency',
                                                    'details':{
                                                      'subtotal':'$total_netto',
                                                      'tax':'$tax',
                                                      'shipping':'$shipping',                                                         
                                                      }                                                     
                                            },  
                                            },
                                        ],
                                    });
                                },

                            commit: true,

                                onAuthorize: function(data, actions) {                                     
                                return actions.payment.execute().then(function() {
                                            location.href = '/shop/checkout/mode/4'
                                        });
                                },

                            onCancel: function(data, actions) {
                                    return actions.redirect();
                                },

                            onError: function(err) {
                                    location.href = '/shop/checkout/mode/4'
                                }


                            }, '#paypal-button');
                        </script>

paypal.Button.render({
env:'production',//为测试环境'production'指定'sandbox'
风格:{
尺寸:'中等',
颜色:“银色”,
形状:“rect”
},                                  
客户:{
沙盒:“asonxxxxxxxxxxxxxxxxxx”,
制作:“$customer\u api”
},
付款:功能(解决、拒绝){
//当买家点击按钮时,在此处设置付款
var env=this.props.env;
var client=this.props.client;
返回paypal.rest.payment.create(环境、客户端、{
“意图”:“出售”,
“付款人”:{
“付款人信息”:{
“email”:“$email”,
“名字”:“$vorname”,
“姓氏”:“$nachname”,
“发货地址”:{
“第1行”:“$strasse”,
“城市”:“$ort”,
“邮政编码”:“$plz”,
“国家代码”:“$land”,
“收件人姓名”:“$firma”
}
}
},
交易:[
{
金额:{
'总计':'总计',
“货币”:“美元货币”,
"详情":{
“小计”:“总计净额”,
"税":"税",,
“shipping”:“shipping美元”,
}                                                     
},  
},
],
});
},
承诺:对,
onAuthorize:函数(数据、操作){
返回actions.payment.execute().then(function()){
location.href='/shop/checkout/mode/4'
});
},
onCancel:函数(数据、操作){
returnactions.redirect();
},
onError:函数(err){
location.href='/shop/checkout/mode/4'
}
}“#贝宝按钮”);

我找到了一个解决方案,并编写了一个php脚本来实现快速paypal express签出按钮: (使用此sdk:)


<?php
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payee;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

class Application_Model_Paypal{

public function checkout(
            $total          = 0,        //Cost incl. tax
            $subtotal       = 0,        //Cost without tax
            $shipping       = 0,        //Cost for Shipping inkl. tax
            $tax            = 0,        //Tax
            $currency       = 'EUR',    //EUR, USD, ...
            $address        = array(),  //Array() of addressdata
            $items          = array(),  //Array() of Items, [name, amount, tax, price(without. tax), number, description]
            $clientid       = '',       //REST-API-ClientID
            $clientsecret   = '',       //REST-API-Secret
            $payee_email    = '',       //Emailadresse des PayPal-Accounts
            $url_success    = '',       //URL in case of payment success 
            $url_error      = ''        //URL in case of payment error
            ){

    /****
     * 
     * ATTENTION:
     * total =!= subtotal + shipping + tax
     * 
     * ITEMS:
     * subtotal = SUM_OF_ITEMS( price * amount )
     * 
     * ***/


    //Clientaddress data
    $email = $address['email'];
    $firma = $address['firma'];
    $vorname = $address['vorname'];
    $nachname = $address['nachname'];
    $strasse = $address['strasse'];
    $plz = $address['plz'];
    $ort = $address['ort'];
    $land = $address['land'];       


    //PayPalData
    $payer = new Payer();
    $payer->setPaymentMethod("paypal");

    $_itemlist = array();
    foreach($items as $it){
        $i = new Item();
        $i->setName($it['name'])
            ->setCurrency($currency)
            ->setDescription($it['description'])
            ->setQuantity($it['amount'])
            ->setTax($it['tax'])
            ->setSku($it['number']) // Similar to "item_number"
            ->setPrice($it['price']);

        //Item back array
        array_push($_itemlist, $i);
    }



    //Paypal itemlist
    $itemList = new ItemList();
    $itemList->setItems($_itemlist);        

    $details = new Details();
    $details->setShipping($shipping)
        ->setTax($tax)
        ->setSubtotal($subtotal);

    $amount = new Amount();
    $amount->setCurrency($currency)
        ->setTotal($total)
        ->setDetails($details);

    $payee = new Payee();
    $payee->setEmail($payee_email);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setItemList($itemList)
        ->setDescription("Payment description")
        ->setPayee($payee)
        ->setInvoiceNumber(uniqid());       

    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl("$url_success")
        ->setCancelUrl("$url_error");               


    $payment = new Payment();
    $payment->setIntent("sale")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));

    $request = clone $payment;

    try {
        $clientid = $clientid;
        $clientsecret = $clientsecret;

        $apiContext = new ApiContext(new OAuthTokenCredential($clientid, $clientsecret));
        $apiContext->setConfig(
            array(
            'mode' => 'live',
        ));             
        $payment->create($apiContext);

    } catch (Exception $e) {
        /*
         *  print_r($_itemlist);
            echo "<div class='alert alert-danger'>".
                    $e->getMEssage()."<br>".
                    "<pre>".$e->getData()."</pre><br>".
                    "Total: $total <br> Subtotal: $subtotal <br> Shipping: $shipping <br> Tax: $tax <br>".
                    "<pre>$payment</pre>".
                "</div>";
         */         
    }


    $res = "        
    <script src='https://www.paypalobjects.com/api/checkout.js'></script>       
    <div id='checkout_button'></div>        
    <script>

        // Render the PayPal button

        paypal.Button.render({

            // Set your environment

            env: 'production', // sandbox | production

            // PayPal Client IDs - replace with your own
            // Create a PayPal app: https://developer.paypal.com/developer/applications/create

            style: {
                size:  'medium',
                color: 'silver',
                shape: 'rect'
            },   

            client: {
                production: '$clientid'
            },

            // Wait for the PayPal button to be clicked

            payment: function() {

                // Make a client-side call to the REST api to create the payment

                return paypal.rest.payment.create(this.props.env, this.props.client, 
                     ".$payment."
                );
            },

            // Wait for the payment to be authorized by the customer

            onAuthorize: function(data, actions) {

                // Execute the payment

                return actions.payment.execute().then(function() {
                    location.href='$url_success';
                });
            },

            // Wait for the payment to be authorized by the customer

            onError: function(err) {
                // Show an error page here, when an error occurs
                location.href = '$url_error';
            },

            onCancel: function(data, actions) {
                return actions.redirect();
            },

        }, '#checkout_button');

    </script>


    ";

    return $res;
}
}