简体   繁体   中英

How to get with paypal C# sdk, the transactionid of a directpayment method

Im using the c# sdk to do a direct payment to paypal.

Everything works great, however im not getting the transactionId because the sdk's "Payment" object does not have a transactionId nor does the http response.

the code is very simple.

Payment pymnt = new Payment();
        pymnt.intent = "sale";
        pymnt.payer = payr;
        pymnt.transactions = transactions;


Payment createdPayment = pymnt.Create(apiContext);

Pymnt Create method, creates and Executes the payment and retrieves back the properties by converting them from json.

I am getting back payid.I checked documentation but couldnt find any on how to get transactionId via payid.

Another part of my application that is created with paypal standard gets the paypal transaction id via the "txn_id" query parameter in the IPN method and saved it in the database.

Thus we need save the transactionid in the database to be consistent.

Please help.

(A similar question was asked on GitHub .)

The transaction ID for a payment can be found via the related_resources property of each transaction associated with a payment.

For example, if you make a sale payment, the transaction ID can be retrieved via the following:

var payment = Payment.Get(apiContext, "PAY-89W644977H834061FKTDRCCY");
var transactionId = payment.transactions[0].related_resources[0].sale.id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM