Problem when create order

alexis007_2
New Community Member

Hi there,

 

I have a problem when the script call a create a order in the page HTML/javascript.

 

In the console, I have an error "Expected a promise for a string order id to be passed to createOrder".

 

I give my code HTML/Javascript

 

<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="bouton-paypal"></div>

<script>
paypal.Buttons({
// Set up the transaction
createOrder: function() {
var SETEC_URL = 'http://localhost/paypalphp/paypalcreatepayment.php';

return fetch(SETEC_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.token;
});
}
}).render('#bouton-paypal');
</script>

</body>
</html>

 

I give my code PHP 

 

<?php
require_once "class/PayPalPayment.php";

$success = 0;
$msg = "an error";

$paypal_response = [];

$payer = new PayPalPayment();
$payer->setSandboxMode(1);
$payer->setClientID("myid");
$payer->setSecret("mysecretid");

$payment_data = [
"intent" => "sale",
"redirect_urls" => [
"return_url" => "http://localhost/",
"cancel_url" => "http://localhost/"
],
"payer" => [
"payment_method" => "paypal"
],
"transactions" => [
[
"amount" => [
"total" => "9.99",
"currency" => "EUR"
],
"item_list" => [
"items" => [
[
"sku" => "1PK5Z9",
"quantity" => "1",
"name" => "Un produit quelconque",
"price" => "9.99",
"currency" => "EUR"
]
]
],
"description" => "Description du paiement..."
]
]
];

$paypal_response = $payer->createPayment($payment_data);
$paypal_response = json_decode($paypal_response);

if (!empty($paypal_response->id)) {

$success = 1;
$msg = "";
}
} else {
$msg = "an big error";
}

echo json_encode(["success" => $success, "msg" => $msg, "paypal_response" => $paypal_response]);

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.