When I process a payment via the REST API (using the PayPal REST SDK for .NET) I first create a payment
Payment payment = ...
Payment createdPayment = payment.Create(apiContext);
I store the ID of the created payment for later use. Then I redirect to the provided payment page. In the page that PayPal calls after the user approved tha payment I want to get information about the payment.
I call
Payment payment = Payment.Get(apiContext, paymentID);
using the stored payment ID.
I expected the state of the payment beeing 'approved' here but it is still 'created'.
What could be wrong? When or how do I get the 'approved' state?
You need to
construct a payment object with payment id and use the payer id returned from PayPal and make the API call using the access token.
That is the query params returned from the SuccesUrl you provided when redirecting to paypal. e.g
http://yourserver.com/payment/paypal/success.asp?payerid=EC-43242423&token=FS321-DFSD-3123DFS-3G243
Then
Execute a payment:
Payment payment = new Payment("");
PaymentExecution pymntExecution = new PaymentExecution();
pymntExecution.payer_id = ("");
Payment executedPayment = pymnt.Execute(apiContext,pymntExecution);
See step 4 / 5 from paypal tutorial:
https://devtools-paypal.com/guide/pay_paypal/dotnet?interactive=OFF&env=sandbox
Edit by Jürgen Bayer
I accept this answer but I just add a few things I found out with the help of the PayPal support:
created
results after a payment was created. It is still the state after the payer authorized the payment (that was my error in reasoning: approved
does not mean "approved by the payer" but "approved by PayPal". There is no state for "authorized").pending
, approved
, failed
, cancelled
or expired
pending
means that PyPal has to perform some security checks or that the payment is a bank transfer. In the latter PayPal must wait until the bank transfer was completed.approved
means that the payment was approved by PayPal. This state can result with credit card payments.failed
: According to https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/#id091EB04C0HS this state results if the payment is a bank transfer that could not be completed, for example because the bank account had not enough funds.cancelled
: The payment was canceled (question is though, by whom?)expired
: The payment authorization has expired and could not be captured.for node.js...
You need to call execute to update the status to approve
var execute_payment_json = {
"payer_id": "Appended to redirect url",
"transactions": [{
"amount": {
"currency": "USD",
"total": "1.00"
}
}]
};
var paymentId = 'PAYMENT id created in previous step';
paypal.payment.execute(paymentId, execute_payment_json, function (error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
console.log("Get Payment Response");
console.log(JSON.stringify(payment));
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With