1

This is how I create PayPal payment.

 var apiContext = GetApiContext(clientId, clientSecret); CreditCard creditCard = new CreditCard(); creditCard.number = "4877274905927862"; creditCard.type = "visa"; creditCard.expire_month = 11; creditCard.expire_year = 2018; creditCard.cvv2 = "874"; creditCard.first_name = firstName; creditCard.last_name = lastName; Amount amount = new Amount(); amount.total = "7.47"; amount.currency = "USD"; Transaction transaction = new Transaction(); transaction.amount = amount; transaction.description = "This is the payment transaction description."; List<Transaction> transactions = new List<Transaction>(); transactions.Add(transaction); FundingInstrument fundingInstrument = new FundingInstrument(); fundingInstrument.credit_card = creditCard; List<FundingInstrument> fundingInstruments = new List<FundingInstrument>(); fundingInstruments.Add(fundingInstrument); Payer payer = new Payer(); payer.funding_instruments = fundingInstruments; payer.payment_method = "credit_card"; Payment payment = new Payment(); payment.intent = "sale"; payment.payer = payer; payment.transactions = transactions; Payment createdPayment = payment.Create(apiContext); 

For payment.execute I need Payment Id and Payer Id. But payer id getting null Can you please tell me, How can I get payer Id? am I missing something?

1
  • 1
    Assuming I understood your question, the above is a credit card sale request, you should already get a result from Create. IINM Execute is for paypal payments. Commented May 7, 2015 at 15:05

2 Answers 2

3

You don't need to do payment.Execute(...) when you pay by credit card.

After you create the payment...

Payment createdPayment = payment.Create(apiContext); 

..., just call createdPayment.id to get the payment ID.

If want to pay by the paypal method you would need to payment.Create(...), then payment.Execute(...) (after the buyer has approved the payment via a redirect to PayPal).

About the Payer ID

When you pay by the paypal method, you do payment.Create(...) and then redirect the buyer to PayPal. After the buyer approved the payment, PayPal redirects to your url and will give you a PayerID in the query string. You will then execute the payment something like this:

var execution = new PaymentExecution { payer_id = Request.Params["PayerID"] }; payment.Execute(apiContext, execution); 
Sign up to request clarification or add additional context in comments.

6 Comments

I got an error int the line Payment createdPayment = payment.Create(apiContext); Error Message is {"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error occurred.","information_link":"developer.paypal.com/docs/api/payments/…"}
This is usually something going on with the PayPal server being down or you configured something wrong. It shouldn't have anything to do with the code. PayPal used to have a website you could go to, to check the status of the servers. You may want to look into that. It is a frustrating message, I know. If you have not already done so, you may want to take this opportunity implement your error handling when you get this type of error message. You could display a message like "Our servers are down right now, try again later."
first of all I want to say thank you for taking care of this. Actually this was my issue i supplied some "test cards" available in internet (That cards work with some other payment gateway like PayU Money). That is not wrks with Paypal , after some research in the Paypal console I fond Generate Card option in the developer console. I used the generated cars it works fine atleast for me.
But still I have another doubt , How we will recieve the Enter OTP Page while transacting. I couldn't see any redirection while paying with Credit Card in Paypal. Is I missed anythig?
@Biju, I wrapped my payment create call in a try/catch block. If there was an exception, my catch block would redirect it to an exception handler function. If there was no exception, I would save the payer id, and redirect to the next page.
|
-1

Please refer Paypal pro API. I think that is good for you and provide better knowledge for you.

1 Comment

This is not an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.