2017-03-28 23 views
0

私はちょうど私たちのCMSにPayPal Express Checkout Integrationを実装しました。 Sandbox-IDではすべて正常に動作しますが、実際の環境では、お客様のPaypal API認証情報をGoogleのシステムに組み込む必要があります。 Paypalの開発者ドキュメントでは、これらの顧客資格情報をエクスプレスチェックアウト統合コードにどのように統合できるか、解決策は見つかりません。PayPal Express Checkout JSとの統合:プロダクションID

誰か助けてくれますか?

    <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> 

答えて

0

私は解決策を見つけたとクイックペイパル・エクスプレスチェックアウトボタンを実現するためのPHPスクリプトを書いた: (このSDK使用して:https://github.com/paypal/PayPal-PHP-SDK/releases)を

<?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; 
} 
} 

を各加盟店が作成する必要があります開発者REST-API-Toolの新しいアプリであり、paypal-business-accountを使用する必要があります。これらのアプリクレデンシャルを作成したら、ライブ環境に切り替える必要があります。 あなたのビジネスアカウントにログインし、「REST-APIアプリ」へのリンクをクリックしてください: https://developer.paypal.com/developer/applications/

関連する問題