The Community Forum is not available for new posts or responses; previous posts remain available to review. For comprehensive support options, please visit PayPal.com/HelpCenter
Merchant Technical Support: For technical support and related questions, please visit our Technical Support Help Center or Developer Central
If you want to report illegal content under the EU Digital Services Act, please do so here
Hello there. Everything in my system was in good condition, but since yesterday I get an error like this I could not understand why?
Do not pass PAY-XXX or PAYID-XXX directly into createOrder. Pass the EC-XXX token instead
My smart buttons script like that:
<script>
paypal.Buttons({
style: {
layout: 'vertical',
color: 'black',
shape: 'rect',
label: 'paypal',
tagline: false,
size: 'responsive',
},
createOrder: function() {
// Now return the `token` to the client
var SETEC_URL = '/api/create-payment';
var checkBox = document.getElementById("ship_to_different");
var note = $("#ordernote").val();
if (checkBox.checked == true){
var body = $("#checkoutt, #data").serializeArray();
}else{
$('input[name=note]').val(note);
var body = $("#data").serializeArray();
}
$("#wait").show();
return fetch(SETEC_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
body:body
})
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.id;
});
},
commit: false,
onApprove: function(data) {
var EXECUTE_URL = '/api/execute-payment';
return fetch(EXECUTE_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
paymentID: data.paymentID,
payerID: data.payerID,
})
}).then(function(response) {
console.log(response);
if(response.statusText == 'OK'){
var checkBox = document.getElementById("ship_to_different");
var note = $("#ordernote").val();
if (checkBox.checked == true){
var xdata = $("#checkoutt, #data").serialize();
}else{
$('input[name=note]').val(note);
var xdata = $("#data").serialize();
}
$.ajax({
type:'post',
url:'check-data',
data:xdata,
success:function () {
$("#wait").hide();
$("#success").show();
},
error:function(request){
json = $.parseJSON(request.responseText);
$.each(json.errors, function(key, value){
$('#error'+key).html('');
$('#error'+key).append('<p class="erro">'+value+'</p>');
});
}
});
}
})
}, onError: function (err) {
console.log(err);
}
}).render('#paypal-button-container');
</script>
And server side
Create-Payment
public function createorder(Request $request){
$body = json_decode(json_encode($request['body']),true);
foreach($body as $valpay){
if($valpay['name'] == '_token'){
unset($valpay);
}elseif($valpay['name'] == 'title[]'){
$titlepay[] = $valpay['value'];
}elseif($valpay['name'] == 'product_id[]'){
$product_idpay[] = $valpay['value'];
}elseif($valpay['name'] == 'price[]'){
$pricepay[] = $valpay['value'];
}elseif($valpay['name'] == 'quantity[]'){
$quantitypay[] = $valpay['value'];
}elseif($valpay['name'] == 'ssh'){
$shippingpay = $valpay['value'];
}elseif($valpay['name'] == 'total'){
$totalpay = $valpay['value'];
}elseif($valpay['name'] == 'subtotal'){
$subtotalpay = $valpay['value'];
}elseif($valpay['name'] == 'tax'){
$taxpay = $valpay['value'];
}elseif($valpay['name'] == 'city'){
$city = $valpay['value'];
}elseif($valpay['name'] == 'country'){
$country = $valpay['value'];
}elseif($valpay['name'] == 'state'){
$state = $valpay['value'];
}elseif($valpay['name'] == 'street'){
$street = $valpay['value'];
}elseif($valpay['name'] == 'zip'){
$zip = $valpay['value'];
}elseif($valpay['name'] == 'coupon'){
$coupon = $valpay['value'];
}elseif($valpay['name'] == 'discount'){
$discount = $valpay['value'];
}elseif($valpay['name'] == 'data'){
$data = $valpay['value'];
}elseif($valpay['name'] == 'x1'){
$gift = $valpay['value'];
}elseif($valpay['name'] == 'cost'){
$cost = $valpay['value'];
}
}
$apiContext = new ApiContext(
new OAuthTokenCredential(
'clientID',
'ClientSecret'
));
$payer = new Payer();
$payer->setPaymentMethod("paypal");
if(isset($gift)){
$item = new Item();
$item->setName('Gift Coupon')
->setCurrency('USD')
->setQuantity('1')
->setPrice($cost);
$items[] = $item;
$subtotalpay = $cost;
$totalpay = $cost;
}else{
foreach ($product_idpay as $key => $p_id){
$item[$key] = new Item();
$item[$key]->setName($titlepay[$key])
->setCurrency('USD')
->setQuantity($quantitypay[$key])
->setSku("123123") // Similar to `item_number` in Classic API
->setPrice($pricepay[$key]);
$items[] = $item[$key];
}
}
if(isset($coupon)){
$subtotalpay = $coupon;
$item[$key+1] = new Item();
$item[$key+1]->setName('Coupon')
->setCurrency('USD')
->setQuantity("1")
->setSku("test") // Similar to `item_number` in Classic API
->setPrice('-'.$discount);
$items[] = $item[$key+1];
}
if($taxpay == '1'){
$tax = round($subtotalpay * 8.625/100,2);
}else{
$tax = 0;
}
$itemList = new ItemList();
$itemList->setItems($items);
$details = new Details();
$details->setShipping($shippingpay)
->setTax($tax)
->setSubtotal($subtotalpay);
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal($totalpay)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://homee.test/checkout")
->setCancelUrl("http://homee.test/checkout");
$inputFields = new InputFields();
$inputFields->setNoShipping(1);
$webProfile = new WebProfile();
$webProfile->setName('test'. uniqid())->setInputFields($inputFields);
$webProfileId = $webProfile->create($apiContext)->getId();
$payment = new Payment();
$payment->setExperienceProfileId($webProfileId);
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (PayPalConnectionException $ex) {
echo $ex->getCode(); // Prints the Error Code
echo $ex->getData(); // Prints the detailed error message
die($ex);
} catch (Exception $ex) {
die($ex);
}
$approvalUrl = $payment->getApprovalLink();
return $payment;
}