我正在沙盒模式下为我的项目使用PayPal API,现在我试图在创建授权付款后获取“批准”链接,问题是,一旦创建付款,状态为已经批准,我不知道是什么原因造成的,据此:https://developer.paypal.com/docs/integration/direct/payments/authorize-and-capture-payments/#authorize-the-payment包含“链接”,其中包含 approval_url 和 execute 链接,但是就我而言,我只得到rel的1个链接:'self',@method:'GET'
代码如下:
public ResponsePayDirect AuthorizePaymentViaStoredCard(string CreditCardid, decimal total, Cart cartPreorder)
{
ResponsePayDirect response = new ResponsePayDirect();
CreditCardToken credCardToken = new CreditCardToken
{
credit_card_id = CreditCardid,
};
FundingInstrument fundInstrument = new FundingInstrument
{
credit_card_token = credCardToken,
};
List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>
{
fundInstrument
};
ItemList list = new ItemList();
list.items = new List<Item>();
for (int i = 0; i < cartPreorder.items.Count; i++)
{
var article = new Item()
{
name = cartPreorder.items[i].Descripcion,
currency = "USD",
price = cartPreorder.items[i].price.ToString(),
quantity = cartPreorder.items[i].quantity.ToString(),
sku = cartPreorder.items[i].itemSku
};
list.items.Add(article);
}
Payer payr = new Payer
{
funding_instruments = fundingInstrumentList,
payment_method = "credit_card"
};
Amount amnt = new Amount
{
currency = "USD",
total = utility.PriceTwoDecimalString(total)
};
Transaction tran = new Transaction();
tran.amount = amnt;
tran.description = "This is the recurring payment transaction";
PaymentOptions paymentOptions = new PaymentOptions();
paymentOptions.allowed_payment_method = "INSTANT_FUNDING_SOURCE";
tran.payment_options = paymentOptions;
tran.item_list = list;
List<Transaction> transactions = new List<Transaction>
{
tran
};
Payment pymnt = new Payment
{
intent = "authorize",
payer = payr,
transactions = transactions
};
APIContext apiContext = ConfigurationPaypal.GetAPIContext();
Payment createdPayment = pymnt.Create(apiContext);
var state = createdPayment.state; // already approved
var links = createdPayment.links.GetEnumerator(); //doesn't have approve_url, just one link
/*
*
I should redirect the user for approving the authorization payment
*/
}
我将不胜感激,第一次进行这样的检查。 谢谢你。