2015-05-07 104 views
1

這是我如何創建PayPal付款。貝寶Rest信用卡付款方式

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?我錯過了什麼嗎?

+1

假設我明白了你的問題,上面是'信用卡'銷售'請求,你應該已經從'Create'得到了結果。 IINM'Execute'用於'paypal'付款。 – EdSF

+0

謝謝。 @EdsF – Tonny

回答

0

請參閱貝寶的親API。我認爲這對你有好處,併爲你提供更好的知識。

2

當你用信用卡付款時,你不需要做payment.Execute(...)

在創建付款...

Payment createdPayment = payment.Create(apiContext); 

...,只需撥打createdPayment.id獲得支付ID。

如果想通過支付寶方式支付您 需要payment.Create(...),然後payment.Execute(...)(之後由買受人已批准通過重定向到貝寶支付)。

關於付款人ID

當您付PayPal的方法,你做payment.Create(...),然後重定向買家到PayPal。買家批准付款後,貝寶將重定向到您的網址,並會在查詢字符串中爲您提供PayerID。然後,您將執行付款是這樣的:

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