Wie kann ich Express Checkout mit PHP integrieren? Paypal's Dokumentation ist sehr schlecht zu diesem Thema.Integrieren Sie PayPal Express Checkout mit PHP
1
A
Antwort
2
HTML-Datei - Stellen Sie sicher, dass die Händler-ID ersetzt wird. Ich habe auch useraction = commit hinzugefügt, so dass das Paypal Pop-up Pay statt eine Nachricht über die Rückkehr auf die Website zur Überprüfung der Zahlung angezeigt wird.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://www.paypalobjects.com/api/checkout.js" async></script>
<input id="amount">
<button id="paypal">Pay by PayPal</i></button>
<script>
window.paypalCheckoutReady = function() {
paypal.checkout.setup('REPLACE WITH MERCHANT ID', {
environment: 'sandbox', # or production
container: '#paypal'
})
$('#paypal').click(function() {
var amount = $('#amount').val()
if (amount) {
paypal.checkout.initXO();
var action = $.post('/paypal.php', {amount: amount});
action.done(function (data) {
paypal.checkout.startFlow('https://www.paypal.com/checkoutnow?useraction=commit&token='+data.TOKEN);
});
action.fail(function() {
paypal.checkout.closeFlow();
});
}
else
alert('Please enter an amount')
})
}
</script>
</body>
</html>
Class.php - das ist die Klasse, um die paypal api ruft
<?php
class PayPal
{
private $config;
private $urls = array(
"sandbox" => array(
"api" => "https://api-3t.sandbox.paypal.com/nvp",
"redirect" => "https://www.sandbox.paypal.com/webscr",
),
"live" => array(
"api" => "https://api-3t.paypal.com/nvp",
"redirect" => "https://www.paypal.com/webscr",
)
);
public function __construct($config)
{
$this->config = $config;
}
public function call($options = [])
{
$options = array_merge($options, $this->config);
return $this->_curl($this->api_url(), $options);
}
public function redirect($response)
{
$redirect_url = sprintf("%s?cmd=_express-checkout&token=%s", $this->redirect_url(), $response["TOKEN"]);
header("Location: $redirect_url");
}
private function redirect_url()
{
return $this->urls[$this->config["environment"]]["redirect"];
}
private function api_url()
{
return $this->urls[$this->config["environment"]]["api"];
}
private function _curl($url, $values)
{
$curl = curl_init($url);
$options = array(
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => http_build_query($values),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_TIMEOUT => 10,
//CURLOPT_SSL_VERIFYPEER => false //for dev
);
curl_setopt_array($curl, $options);
$rep = curl_exec($curl);
parse_str($rep, $response);
curl_close($curl);
return $response;
}
}
paypal.php laufen - stellen Sie sicher, Config mit paypal Kontodaten zu ersetzen. Auch das Beispiel enthält keinen Code zu handhaben cancel.php - die abgerufenen Datei, wenn der Benutzer das Popup schließt sich, ohne zu bezahlen
<?php
include('class.php');
$config = array(
"environment" => "sandbox", # or live
"user" => "REPLACE WITH PAYPAL USER",
"pwd" => "REPLACE WITH PAYPAL PASSWORD",
"signature" => "REPLACE WITH PAYPAL SIGNATURE",
"version" => 113
);
$paypal = new PayPal($config);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$result = $paypal->call(array(
'method' => 'SetExpressCheckout',
'paymentrequest_0_paymentaction' => 'sale',
'paymentrequest_0_amt' => $_POST['amount'],
'paymentrequest_0_currencycode' => 'USD',
'returnurl' => 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'paypal.php?amount=' . $_POST['amount'],
'cancelurl' => 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'cancel.php?amount=' . $_POST['amount']
));
if ($result['ACK'] == 'Success') {
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
echo json_encode($result);
} else {
echo 'Handle the payment creation failure <br>';
}
} else {
$result = $paypal->call(array(
'method' => 'DoExpressCheckoutPayment',
'token' => $_GET['token'],
'payerid' => $_GET['PayerID'],
'paymentrequest_0_paymentaction' => 'sale',
'paymentrequest_0_amt' => $_GET['amount'],
'paymentrequest_0_currencycode' => 'USD'
));
if ($result['PAYMENTINFO_0_PAYMENTSTATUS'] == 'Completed') {
$result = $paypal->call(array(
'method' => 'GetExpressCheckoutDetails',
'token' => $_GET['token'],
));
//$result now contains customer information
} else {
echo 'Payment error';
}
}
Viel Glück!
Verwandte Themen
- 1. PHP PayPal API Express CheckOut
- 2. Paypal Express Checkout mit AngularJS
- 3. paypal express checkout zahlungsbeschränkung
- 4. Paypal Express Checkout Implementierung
- 5. PayPal Express Checkout CREATE_PAYMENT_URL
- 6. Meteor: Paypal Express Checkout Integration
- 7. Paypal Express Checkout in CodeIgniter
- 8. PayPal Express Checkout ohne Einloggen
- 9. Paypal Express Checkout funktioniert nicht
- 10. Integrieren Sie Paypal Express-Option in OpenCart
- 11. Mehrere Berechtigungen mit PayPal Express Checkout
- 12. Probleme mit Paypal Express Checkout Integration (WEBREQUEST)
- 13. Android: Paypal Express Checkout Integration funktioniert nicht
- 14. Gast Checkout nicht verfügbar mit Paypal Express Checkout
- 15. PayPal Express Checkout MVC C# Beispielcode
- 16. Paypal Express Checkout - Fragezeichen in Zahlung Seite
- 17. Integrieren Paypal Kasse Laravel PHP
- 18. Versandadresse in PayPal Express Checkout deaktivieren
- 19. Paypal Express Kasse in PHP
- 20. Render Paypal Express Checkout in Unity 3D
- 21. Paypal Express Checkout: Systematische 10486 Fehler
- 22. Paypal Express Checkout: Keine Review Option
- 23. Alte Paypal Checkout-Layout auf Express-Kasse
- 24. Paypal Express Checkout: Fehler 10001 Timeout
- 25. Verwenden Sie PayPal Express Checkout in einem Online-Marktplatz
- 26. Paypal Express Checkout zeigt nur ein Element
- 27. Paypal Integration mit Express-Checkout und vor Ort
- 28. hinzufügen Versandkosten in Paypal-Express-Checkout-einfach
- 29. Paypal Checkout mit Umleitung?
- 30. Integration von Omnipay mit PayPal Express Checkout [symfony2]
Sie können die SDK und Beispiel hier finden: https://developer.paypal.com/docs/classic/api/nvpsoap-sdks/ – CCamilo