Bhavin
Bhavin

Reputation: 789

Paypal Rest API With Credit Cart Payment Method

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?

Upvotes: 1

Views: 1227

Answers (2)

Vishal Kiri
Vishal Kiri

Reputation: 1306

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

Upvotes: -1

Ken Johnson
Ken Johnson

Reputation: 425

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);

Upvotes: 3

Related Questions