Paypal Rest API与信用卡付款方式

时间:2015-05-07 08:15:53

标签: c# asp.net paypal paypal-sandbox

这就是我创建PayPal付款的方式。

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

对于 payment.execute ,我需要付款ID和付款人ID。但是付款人ID变为空 你能告诉我,我怎样才能获得付款人ID?我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

当您使用信用卡付款时,您不需要payment.Execute(...)

创建付款后......

Payment createdPayment = payment.Create(apiContext);

...,只需致电createdPayment.id即可获取付款ID。

如果想通过paypal方法支付你 需要payment.Create(...),然后payment.Execute(...)(在买方通过重定向到PayPal批准付款后)。

关于付款人ID

当您使用paypal方法付款时,您执行payment.Create(...),然后将买方重定向到PayPal。在买家批准付款后,PayPal会重定向到您的网址,并会在查询字符串中显示PayerID。然后,您将执行以下付款:

var execution = new PaymentExecution { payer_id = Request.Params["PayerID"] };
payment.Execute(apiContext, execution);

答案 1 :(得分:0)

请参阅Paypal pro API。我认为这对你有好处,并为你提供更好的知识。