i am integrating express checkout in my asp.net mvc application. everything works ok even, response is success but when i try to call "GetExpressCheckoutDetailsResponseDetails" i am getting null in "PayerID". The field below is "requestDetails.PayerID"
public ActionResult PayPalExpressCheckout()
{
PaymentDetailsType paymentDetail = new PaymentDetailsType();
CurrencyCodeType currency = (CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType));
List<PaymentDetailsItemType> paymentItems = new List<PaymentDetailsItemType>();
var AppCart = GetAppCart();
foreach(var item in AppCart.Items)
{
PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();
paymentItem.Name = item.Name;
paymentItem.Description = item.Description;
double itemAmount = Convert.ToDouble(item.Price);
paymentItem.Amount = new BasicAmountType(CurrencyCodeType.GBP, itemAmount.ToString());
paymentItem.Quantity = 1;
paymentItems.Add(paymentItem);
}
paymentDetail.PaymentDetailsItem = paymentItems;
paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType));
paymentDetail.OrderTotal = new BasicAmountType(CurrencyCodeType.GBP, (AppCart.TotalPrice).ToString());
List<PaymentDetailsType> paymentDetails = new List<PaymentDetailsType>();
paymentDetails.Add(paymentDetail);
SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();
ecDetails.ReturnURL = "http://Orchard.Club/Purchase/PayPalExpressCheckoutAuthorisedSuccess";
ecDetails.CancelURL = "http://Orchard.Club/Purchase/CancelPayPalTransaction";
ecDetails.PaymentDetails = paymentDetails;
SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();
ecDetails.FundingSourceDetails = new FundingSourceDetailsType();
//request.Version = "104.0";
ecDetails.LandingPage = LandingPageType.BILLING;
ecDetails.SolutionType = SolutionTypeType.SOLE;
ecDetails.FundingSourceDetails.UserSelectedFundingSource = UserSelectedFundingSourceType.CREDITCARD;
request.SetExpressCheckoutRequestDetails = ecDetails;
SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();
wrapper.SetExpressCheckoutRequest = request;
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
sdkConfig.Add("account1.apiUsername", "mrhammad-facilitator_api1.hotmail.com");
sdkConfig.Add("account1.apiPassword", "1369812511");
sdkConfig.Add("account1.apiSignature", "AJxdrs7c7cXRinyNUS5p1V4s1m4uAGR.wOJ7KzgkewEYmTOOtHrPgSxR");
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper);
if (setECResponse.Ack.Equals(AckCodeType.SUCCESS))
{
GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();
// (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
// Character length and limitations: 20 single-byte characters
getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(setECResponse.Token);
// # API call
// Invoke the GetExpressCheckoutDetails method in service wrapper object
GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);
// Create request object
DoExpressCheckoutPaymentRequestType expressrequest = new DoExpressCheckoutPaymentRequestType();
DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
expressrequest.DoExpressCheckoutPaymentRequestDetails = requestDetails;
requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
// (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
requestDetails.Token = setECResponse.Token;
// (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
requestDetails.PayerID = requestDetails.PayerID;
// (Required) How you want to obtain payment. It is one of the following values:
// * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
// * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
// * Sale – This is a final sale for which you are requesting payment.
// Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
requestDetails.PaymentAction = (PaymentActionCodeType)
Enum.Parse(typeof(PaymentActionCodeType), "SALE");
// Invoke the API
DoExpressCheckoutPaymentReq expresswrapper = new DoExpressCheckoutPaymentReq();
expresswrapper.DoExpressCheckoutPaymentRequest = expressrequest;
// # API call
// Invoke the DoExpressCheckoutPayment method in service wrapper object
DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(expresswrapper);
// Check for API return status
if (doECResponse.Ack.Equals(AckCodeType.FAILURE) ||
(doECResponse.Errors != null && doECResponse.Errors.Count > 0))
{
return RedirectToAction("PostPaymentFailure");
}
else
{
TempData["TransactionResult"] = "Transaction ID:" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID + Environment.NewLine + "Payment status" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus.Value.ToString();
return RedirectToAction("SaveCustomer", "SignupOrLogin");
}
}
else
{
return RedirectToAction("Error", "Purchase");
}
}
As #geewiz mentioned, you're missing the step of redirecting the customer to PayPal to approve the payment.
Refer to How to Create One-Time Payments Using Express Checkout guide on PayPal Developer that outlines the steps involved with Express Checkout.
In your code, you will want to retrieve the EC token to use for the redirect from the setECResponse object and then redirect the customer to the PayPal site using that token:
SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper);
// Note: Add appropriate logic for targeting live URL based on your config settings
var redirectUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + setECResponse.Token;
Related
I have an api that returns values from the database to populate our footer dynamically. These footer values are stored as keys in Redis at the endpoint and then in the main application I'm getting the url of the current page and creating a Hash with the key being the current url and the 5 returned redis key/values from the api as HashEntries. I've shown the code below and right where the HashSet is (at the end) is where the error starts, but if I remove the cache.Hashset, the code runs fine. Do I need to prepopulate the hash or am I missing something obvious here?
//Get relative url after .com/
var url = HttpContext.Current.Request.Url.ToString();
var urlSplit = url.Split(new string[] { ".com/" }, StringSplitOptions.None);
var finalUrl = urlSplit[1];
//TODO: If url isn't in Redis, want to hit endpoint and load it into Redis
//in the background with worker service/async call.
var cache = RedisHelper.Connection.GetDatabase();
var hashExists = cache.HashExists(finalUrl, "footer:recent-content");
if (hashExists)
{
recentContent = cache.HashGet(finalUrl, "footer:recent-content");
topPages = cache.HashGet(finalUrl, "footer:top-pages");
featuredContent = cache.HashGet(finalUrl, "footer:featured-content");
topIntegrations = cache.HashGet(finalUrl, "footer:top-integrations");
featuredIntegrations = cache.HashGet(finalUrl, "footer:featured-integrations");
}
else
{
recentContent = cache.StringGet("footer:general:recent-content");
topPages = cache.StringGet("footer:general:top-pages");
featuredContent = cache.StringGet("footer:general:featured-content");
topIntegrations = cache.StringGet("footer:general:top-integrations");
featuredIntegrations = cache.StringGet("footer:general:featured-integrations");
HashEntry[] redisFooterHash =
{
new HashEntry("footer:recent-content", recentContent),
new HashEntry("footer:top-pages", topPages),
new HashEntry("footer:featured-content", featuredContent),
new HashEntry("footer:top-integrations", topIntegrations),
new HashEntry("footer:featured-integrations", featuredIntegrations)
};
cache.HashSet(finalUrl, redisFooterHash);
}
Also, the reason the keys are footer:recent-content and footer:general... is that in the future we want each page to have a dynamic footer based on it's content.
I'm using previews of the botbuilder adaptive dialog to gather some user info. I want to store this information in SQL. So my question is how can I gather the info from the "Property" in the textinput?
new TextInput
{
Prompt = new ActivityTemplate(question.Text),
Property = "user.userProfile" + question.Id
}
Use CodeAction or HttpRequest to call your api to store the information
Use this to make HTTP requests to any endpoint.
new HttpRequest()
{
// Set response from the http request to turn.httpResponse property in memory.
ResultProperty = "turn.httpResponse",
Method = HttpRequest.HttpMethod.POST,
Headers = new Dictionary<string,string> (), /* request header */
Body = JToken.FromObject(new
{
data = "#{user.userProfile" + question.Id + "}",
another = "#{user.another}"
}) /* request body */
});
Code Action
private async Task<DialogTurnResult> CodeActionSampleFn(DialogContext dc, System.Object options)
{
var userState = JObject.FromObject(dc.GetState().FirstOrDefault(x => x.Key == "user").Value);
//Get your data here
var data = userState.Value<JObject>("userProfile" + question.Id);
// call your API by HttpClient
//...
return dc.ContinueDialogAsync();
}
Check out more detail here
https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/adaptive-dialog/docs/recognizers-rules-steps-reference.md#HttpRequest
You can see examples of how to access state properties all over this page:
new SendActivity("Hello, #{user.name}")
I want to implement Authorize .net payment gateway in my website using asp.net. I am a beginner in this. Can someone give me a sample code from where I can be redirected to the Authorize.net page to complete payment process.
I have created a sandbox account.
Redirection URL - https://test.authorize.net/gateway/transact.dll but I get an error
(13) The merchant login ID or password is invalid or the account is inactive.
My account is active and in test mode.
My Code:
protected void Button_pay_Click(object sender, EventArgs e)
{
string value = TextBox_amt.Text;
decimal d = decimal.Parse(value);
Run("abc", "abcq234", d);
}
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
{
Console.WriteLine("Create an Accept Payment Transaction Sample");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,
};
var opaqueData = new opaqueDataType
{
dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT",
dataValue = "119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"
};
var billingAddress = new customerAddressType
{
firstName = "John",
lastName = "Doe",
address = "123 My St",
city = "OurTown",
zip = "98004"
};
//standard api call to retrieve response
var paymentType = new paymentType { Item = opaqueData };
// Add line Items
var lineItems = new lineItemType[2];
lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) };
lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card
amount = amount,
payment = paymentType,
billTo = billingAddress,
lineItems = lineItems
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the contoller that will call the service
var controller = new createTransactionController(request);
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
//validate
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.transactionResponse.messages != null)
{
Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
}
else
{
Console.WriteLine("Failed Transaction.");
if (response.transactionResponse.errors != null)
{
Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
}
}
}
else
{
Console.WriteLine("Failed Transaction.");
if (response.transactionResponse != null && response.transactionResponse.errors != null)
{
Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
}
else
{
Console.WriteLine("Error Code: " + response.messages.message[0].code);
Console.WriteLine("Error message: " + response.messages.message[0].text);
}
}
}
else
{
Console.WriteLine("Null Response.");
}
return response;
}
Aparajita you must check with the API credentials for sandbox in Authorize.Net account
This comes up often and the reasons are always the same:
You are using your production credentials but hitting the sandbox endpoints
You are using your sandbox credentials but are hitting the production endpoints
The credentials you are using are incorrect
Verifying which endpoint you are actually hitting.
If you are testing against the production environment, verify that the URL you have in your code is the actual production URL (or if you are using a framework, the configuration is set to production).
The correct URL for production is https://api2.authorize.net/xml/v1/request.api.
The correct URL for testing is https://apitest.authorize.net/xml/v1/request.api
Verify your credentials
If you are sure that you are hitting the correct endpoint you then need to verify that you are using the correct credentials for that environment.
Make sure you are using the API login and transaction key and not the console login and password. They are not the same thing. Only the API login and transaction key will work when accessing the APIs. You can get these after logging in to the console.
Double check that the API login is correct in the console.
If the API login is correct, from within the customer console generate a new transaction key to verify that you have the correct one.
Make sure that the credentials are not accidentally entered incorrectly in your code. Make sure all of the characters are there. Also, the credentials are case sensitive. Make sure you did not capitalize or lowercase those values.
If you need to verify your login credentials work set up a MVCE that hits the endpoint you are trying to reach with your API credentials. It should be a simple script that makes a basic API call. This will make it easy to debug why you are getting this error.
Test mode is not the sandbox
It is common to confuse test mode with the sandbox environment. Test mode in production uses the production environment and production credentials. Using the sandbox credentials or URLs will not work.
I used this sample project to solve my problem. This is in TEST Mode.
https://github.com/AuthorizeNet/sdk-dotnet/tree/master/CoffeeShopWebApp
I have an account ID and also a template ID, but I am getting null in text custom and list fields. I am using DocuSign's REST api for getting custom fields and listed fields.
configureApiClient("https://demo.docusign.net/restapi");
// Step 1: Login()
// call the Login() API which sets the user's baseUrl and returns their accountId
AccountId = loginApi(username, password);
TemplatesApi envelopesApi2 = new TemplatesApi();
CustomFields cfe = envelopesApi2.ListCustomFields(AccountId, templateId);
Console.WriteLine("Get Custom Fields Information:\n{0}",
JsonConvert.SerializeObject(cfe));
Could you please help me to solve my problem?
Thanks in advance
I see that you are adding the custom fields to an envelope and not template. You should use the EnvelopesApi to retrieve the CustomFields. You are incorrectly using the TemplateId.
Use the following code and pass the envelopeId that is returned from the envelopesApi.CreateEnvelope() call
var envelopesApi2 = new EnvelopesApi();
CustomFields cfe = envelopesApi2.ListCustomFields(AccountId, envelopeId);
Console.WriteLine("Get Custom Fields Information:\n{0}",
JsonConvert.SerializeObject(cfe));
Please see my below code to create custom field in templates.
public EnvelopeSummary requestSignatureFromTemplateTest(DocuSignData data)
{
// instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
configureApiClient("https://demo.docusign.net/restapi");
//===========================================================
// Step 1: Login()
//===========================================================
// call the Login() API which sets the user's baseUrl and returns their accountId
AccountId = loginApi(username, password);
//===========================================================
// Step 2: Signature Request from Template
//===========================================================
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "Please sign this sample template document11111111111";
// assign recipient to template role by setting name, email, and role name. Note that the
// template role name must match the placeholder role name saved in your account template.
TemplateRole tRole = new TemplateRole();
tRole.Email = recipientEmail;
tRole.Name = recipientName;
tRole.RoleName = templateRoleName;
List<TemplateRole> rolesList = new List<TemplateRole>() { tRole };
// add the role to the envelope and assign valid templateId from your account
envDef.TemplateRoles = rolesList;
envDef.TemplateId = templateId;
// set envelope status to "sent" to immediately send the signature request
envDef.Status = "sent";
List<TextCustomField> customFieldsTextList = new List<TextCustomField>();
if (data.CustomFieldsText != null)
{
//custom text fields
foreach (DocuSignCustomField customField in data.CustomFieldsText)
{
TextCustomField newField = new TextCustomField();
newField.Name = customField.Name;
newField.Value = customField.Value;
newField.Show = customField.Show;
newField.Required = customField.Required;
customFieldsTextList.Add(newField);
}
}
CustomFields customFields = new CustomFields();
customFields.TextCustomFields = customFieldsTextList;
envDef.CustomFields = customFields;
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(AccountId, envDef);
// print the JSON response
//Console.WriteLine("Envelope Template Summary:\n{0}", JsonConvert.SerializeObject(envelopeSummary));
return envelopeSummary;
} // end requestSignatureFromTemplateTest()
this code for getting custom fields from template
configureApiClient("https://demo.docusign.net/restapi");
// Step 1: Login()
// call the Login() API which sets the user's baseUrl and returns their accountId
AccountId = loginApi(username, password);
TemplatesApi envelopesApi2 = new TemplatesApi();
CustomFields cfe = envelopesApi2.ListCustomFields(AccountId, templateId);
Console.WriteLine("Get Custom Fields Information:\n{0}",
JsonConvert.SerializeObject(cfe));
Using .NET c# I need to programmatically manage / add subscribers to my lists in aWeber using the API. The process that I am tasked with will be a Windows Service that runs x # of times a day and updates the subscribers at aWeber and the lists that they are in.
So .. all of my research using the aWeber API with .NET has shown me that a signon page at aWeber must be completed in order to receive the oauth_verifier back in the callback URL.
So in summary here are my questions:
Any recommendations on how to accomplish this task using an unattended service?
Has anyone does this?
Any help is greatly appreciated.
Thanks
Emma
1) How to use Aweber .NET SDK to connect with Aweber account [Regular Account - (i.e.) Not the developer's one].
Download .NET SDK for Aweber from https://aweber.codeplex.com/
Ans :- 1) Create a developer account - Visit https://labs.aweber.com/
2) As you have successfully created the account you would see ConsumerKey, ConsumerSecret, & an AppId in your Application.
3) Then for the fist time add the following code.
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
api.CallbackUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Authorize/Index";
api.get_request_token();
Response.Cookies["oauth_token"].Value = api.OAuthToken;
Response.Cookies["oauth_token_secret"].Value = api.OAuthTokenSecret;
api.authorize();
**Now create An Authorize controller in case of MVC or Authorize.aspx**
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
API api = new API(ConsumerKey, ConsumerSecret);
api.OAuthVerifier = Request["oauth_verifier"];
Response.Cookies["access_token"].Value = api.get_access_token();
Account account = api.getAccount();
**Now you can apply your code to create, delete... subscribers to/from the list**
When you run this code first the authorize page will appear where you need to add your Aweber regular account credentials.
Once it's verified then you'll get access to the aweber's(Customer) account.
**But you would not like the authorize page appear always whenever you run your application so you can omit it by doing the following steps.**
1. Use the PHP script provided in http://stackoverflow.com/questions/15378034/how-to-create-an-app-in-aweber
2. Run the above PHP script & you'll get the pair of accesskey & accesssecret.Copy them to your C# code (these are the permanent keys).
3. Initialize the API with this code:
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret = ConfigurationManager.AppSettings["AWeberConsumerSecret"];
string accessKey = ConfigurationManager.AppSettings["accessKey"];
string accessSecret = ConfigurationManager.AppSettings["accessSecret"];
Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
api.OAuthToken = accessKey;
api.OAuthTokenSecret = accessSecret;
Account account = api.getAccount();
**Now we'll code to create subscriber to a particular list**
int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
foreach (List list in account.lists().entries)
{
if (list.id == listid) Your List's ID **(Mylist - xxxxxxx)**
{
foreach (Subscriber subscriber in list.subscribers().entries)
{
if (subscriber.email.Equals(objRegModel.EmailID))
{
flag = false;
break;
**Checks whether the similar subscriber exists on the list**
}
else
{
flag = true;
}
}
if (flag == true)
{
BaseCollection<Subscriber> target = list.subscribers();
SortedList<string, object> parameters = new SortedList<string, object>();
parameters.Add("email", objRegModel.EmailID);
parameters.Add("name", objRegModel.FirstName + " " + objRegModel.LastName);
Subscriber subscriber = target.create(parameters);
**This will add the subscriber to the specified list only if does not exist on that list.**
}
}
}
**To Delete a particluar subscriber from the list**
Apply the same logic till Account account = api.getAccount();
To get the EmailID,IP Address etc of the subscribers on the
list.Refer to this link https://labs.aweber.com/docs/permissions
int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
foreach (List list in account.lists().entries)
{
if (list.id == listid)
{
foreach (Subscriber subscriber in list.subscribers().entries)
{
We Perform the check whether the email of the subscriber exists on the list or not & accordingly delete it from the list.
if (subscriber.email == eid && subscriber.status != "unconfirmed")
{
try
{
if (subscriber.delete())
{
//Response.Write("Subscriber Successfully Deleted");
}
}
catch (Exception ex)
{
}
}
}
}
}
}