2017-05-17 19 views
2

vhost-> test.it/paypalを使用してApacheサーバのPHPデモテストでpaypalの統合をテストしています。 Express Checkout +サーバー側REST(cURL)を使用します。 私のjsはPayPalのボタンを追加します:PayPal Expressチェックアウト+ php cURL支払いを実行するとサンドボックスに支払い通知が表示されない

<script> 
 

 
     var CREATE_PAYMENT_URL = 'http://test.it/paypal/create-payment.php'; 
 
     var EXECUTE_PAYMENT_URL = 'http://test.it/paypal/execute-payment.php'; 
 

 
     paypal.Button.render({ 
 

 
      env: 'sandbox', // Or 'production', 
 

 
      commit: true, // Show a 'Pay Now' button 
 

 
      locale: 'it_IT', 
 

 
      style: { 
 
       size: 'small', 
 
       color: 'blue', 
 
       shape: 'pill', 
 
       label: 'checkout' 
 
      }, 
 

 
      commit: true, // Show a 'Pay Now' button 
 

 
      payment: function() { 
 

 
       // Make a call to the merchant server to set up the payment 
 

 
       return paypal.request.post(CREATE_PAYMENT_URL).then(function(res) { 
 
        //return res.payToken; 
 
        console.log(res); 
 
        return res.paymentID; 
 
       }); 
 
      }, 
 

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

 
     onAuthorize: function(data) { 
 
      //alert(data.payerID); 
 
      return paypal.request.post(EXECUTE_PAYMENT_URL, { 
 
       paymentID: data.paymentID, 
 
       payerID: data.payerID 
 
      }).then(function(res) { 
 
       /* Go to a success page */ 
 
       console.log('SUCCESS!!!!!!!!!'); 
 
       console.log(res); 
 
       // The payment is complete! 
 
       // You can now show a confirmation message to the customer 
 
       alert('pagamento completato'); 
 
      }).catch(function (err) { 
 
       /* Go to an error page */ 
 
       console.log('ERROR!!!!!!!!!'); 
 
       console.log(data); 
 
       console.log(err); 
 
      }); 
 
     } 
 

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

次のように作成-payment.phpは次のとおりです。

<?php 
 
session_start(); 
 
include 'config.php'; 
 

 
// autenticazione per ottenere user token 
 
$url_wbs="https://api.sandbox.paypal.com/v1/oauth2/token"; 
 

 

 
$ch = curl_init(); 
 
$clientId = "Aeet9T-pG4XQU-GnDL2uSrkJQ4_qaxgAu9XtVTP6qeuXDGBOnHf2TiVF2Qv5OurFmSo9dPkwVk-x0J3x"; 
 
$secret = "EGQguUgHcN4TLjAEAXb4Jo8qoTQCvC3o_54FL2r2wQUtjbGoRoWeRlDyNNhU3HO8lpdexzNsW-ePb2qe"; 
 
// id web experience profile 
 
$experience_profile_id="XP-V52K-SKNH-FK7Y-HLYQ"; 
 

 
curl_setopt($ch, CURLOPT_URL, $url_wbs); 
 
curl_setopt($ch, CURLOPT_HEADER, false); 
 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 
curl_setopt($ch, CURLOPT_POST, true); 
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret); 
 
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); 
 

 
$result = curl_exec($ch); 
 
curl_close($ch); 
 
if(empty($result))die("Error: No response."); 
 
else 
 
{ 
 
    $obj=json_decode($result); 
 

 
    //var_dump($obj->access_token); 
 
    $_SESSION['token']=$obj->access_token; 
 

 
    // imposto il web profile ottenendone l'id 
 
    $header_rest_call[]='Authorization: Bearer '.$obj->access_token; 
 

 

 
    $json_body='{ 
 
    "intent": "sale", 
 
    "experience_profile_id":"'.$experience_profile_id.'", 
 
    "redirect_urls": 
 
    { 
 
    "return_url": "http://test.it/paypal/checkout.php", 
 
    "cancel_url": "http://test.it/paypal/pagamento-cancellato.php" 
 
    }, 
 
    "payer": 
 
    { 
 
    "payment_method": "paypal" 
 
    }, 
 
    "transactions": [ 
 
    { 
 
    "amount": 
 
    { 
 
     "total": "4.00", 
 
     "currency": "EUR", 
 
     "details": 
 
     { 
 
     "subtotal": "2.00", 
 
     "shipping": "1.00", 
 
     "tax": "2.00", 
 
     "shipping_discount": "-1.00" 
 
     } 
 
    }, 
 
    "item_list": 
 
    { 
 
     "items": [ 
 
     { 
 
     "quantity": "1", 
 
     "name": "item 1", 
 
     "price": "1", 
 
     "currency": "EUR", 
 
     "description": "item 1 description", 
 
     "tax": "1" 
 
     }, 
 
     { 
 
     "quantity": "1", 
 
     "name": "item 2", 
 
     "price": "1", 
 
     "currency": "EUR", 
 
     "description": "item 2 description", 
 
     "tax": "1" 
 
     }] 
 
    }, 
 
    "description": "The payment transaction description.", 
 
    "invoice_number": "merchant invoice", 
 
    "custom": "merchant custom data" 
 
    }] 
 
}'; 
 

 
    $obj_payment=get_obj_json($payment_creation_url,$header_rest_call,$json_body,'POST'); 
 

 
    //var_dump($obj_payment->id); 
 
    $response=array(
 
    'paymentID'=>$obj_payment->id 
 
    ); 
 

 
    echo json_encode($response); 
 
} 
 
?>

execu

<?php 
 
session_start(); 
 
include 'config.php'; 
 

 

 
    // imposto il web profile ottenendone l'id 
 
    $header_rest_call[]='Authorization: Bearer '.$_SESSION['token']; 
 

 
    // indirizzo wbs per pagamento 
 
    $url_payment="https://api.sandbox.paypal.com/v1/payments/payment/".$_POST['paymentID']."/execute/"; 
 

 
    $json_body='{ 
 
    "payer_id": "'.$_POST['payerID'].'"; 
 
    }'; 
 

 
    $obj_payment=get_obj_json($url_payment,$header_rest_call,$json_body,'POST'); 
 

 
    echo json_encode($obj_payment); 
 

 

 
?>

私はPayPalのログインフォームが正しく購入データが表示されますPayPalのボタンをクリックすると、私は資格情報を入力し、最後に、私は上をクリックし、次のようにTE-payment.phpです「今すぐ支払う」 ボタン。お支払いは正常に行われたようですが、サンドボックスアカウント - >アクティビティ - >トランジション/ペイメントのトレースはありません。

+0

はあなたの本当の 'clientId'と' secret'私はwouldnものであり、働きます!?'それらを公開する... –

+0

急いで撮影..今私は、アプリケーションを削除しましたありがとう –

答えて

0

問題は、支払い/実行依頼の不正なjsonにありました。

$json_body='{ 
"payer_id": "'.$_POST['payerID'].'"; 

} ';

私が誤って後に入力セミコロンがあった - 。> $ _POST [ 'payerIDは'] '」

今では

+0

私は私のウェブサイトに同じものを統合したいconfig.phpに何があるのか​​教えてください。エラーが表示されますUncaught Error:未定義関数を呼び出すget_obj_json() –

関連する問題