以下是来自.Net的PayPal样本的一些代码,其中正在删除发票。我是从https://github.com/paypal/PayPal-NET-SDK/tree/master/Samples/Source下载的。删除发票的代码通过进行以下调用createdInvoice.Delete
来执行此操作,该调用将返回空白。
问题:由于此方法返回void,如何知道删除成功?
使用NET SDK for PayPal删除已创建发票的PayPal代码
// ^ Ignore workflow code segment
#region Track Workflow
this.flow.AddNewRequest("Create the invoice", invoice);
#endregion
// Create the invoice
var createdInvoice = invoice.Create(apiContext);
// ^ Ignore workflow code segment
#region Track Workflow
this.flow.RecordResponse(createdInvoice);
this.flow.AddNewRequest("Delete the invoice");
#endregion
createdInvoice.Delete(apiContext);//This method returns a void, so how we
//know it succeeded?????
// ^ Ignore workflow code segment
#region Track Workflow
this.flow.RecordActionSuccess("Invoice deleted successfully.");
#endregion
答案 0 :(得分:0)
经过大量研究后,我发现如果删除失败,Delete
方法会抛出异常。因此,可以安全地假设,如果在调用var conn = new jsforce.Connection({
oauth2 : salesforce_credential.oauth2
});
var username = salesforce_credential.username;
var password = salesforce_credential.password;
// I want to avoid this login on every router
conn.login(username, password, function(err, userInfo) {
if (err) {
return console.error(err);
}
conn.query("SELECT id FROM Sourcing__c WHERE id = 'req.session.ref'",function(err, result) {
if (err) {
return console.error(err);
}
if(result.records.length === 0){
req.session.ref = "";
}
var body = {
"Auth__c": req.user.id,
"Stus__c": "Pending - New Hire",
"Record": "012lvIAC",
"Sourcing__c": req.session.ref
};
conn.sobject("SFDC_Employee__c").create(body, function(err, ret) {
if (err || !ret.success) {
return console.error(err, ret);
}
console.log("Created record id : " + ret.id);
// ...
});
});
});
方法时没有抛出异常,则删除发票成功。