public static Dictionary <string, string> AuthorizeApiCall() { string uniqueReferenceId = GenerateRandomUniqueString(); AuthorizeOnBillingAgreementRequest authRequestParameters = new AuthorizeOnBillingAgreementRequest(); authRequestParameters.WithAmazonBillingAgreementId(HttpContext.Current.Session["amazonBillingAgreementId"].ToString()) // The below code can be used to get the amount from the session. the amount was added into session in the SetPaymentDetails.aspx //.WithAmount(decimal.Parse(Session["amount"].ToString())) //For example we will be authorizing amount value of 1.99 .WithAmount((decimal)1.99) .WithCurrencyCode(Regions.currencyCode.USD) .WithAuthorizationReferenceId(uniqueReferenceId) .WithTransactionTimeout(0) .WithCaptureNow(true) .WithSellerAuthorizationNote("Note"); AuthorizeResponse authResponse = client.AuthorizeOnBillingAgreement(authRequestParameters); apiResponse["authorizeOnBillingAgreementResponse"] = authResponse.GetJson(); if (!authResponse.GetSuccess()) { string errorCode = authResponse.GetErrorCode(); string errorMessage = authResponse.GetErrorMessage(); } else { // AuthorizeOnBillingAgreement was a success amazonAuthorizationId = authResponse.GetAuthorizationId(); // Check if the Capture Now was set to true captureNow = authResponse.GetCaptureNow(); // If captureNow was true then the capture has already happened. Get the Capture ID(s) from the List if (captureNow) { amazonCaptureIdList = authResponse.GetCaptureIdList(); } CaptureApiCall(); return(apiResponse); } return(apiResponse); }
public static Dictionary<string, string> AuthorizeApiCall() { string uniqueReferenceId = GenerateRandomUniqueString(); AuthorizeOnBillingAgreementRequest authRequestParameters = new AuthorizeOnBillingAgreementRequest(); authRequestParameters.WithAmazonBillingAgreementId(HttpContext.Current.Session["amazonBillingAgreementId"].ToString()) // The below code can be used to get the amount from the session. the amount was added into session in the SetPaymentDetails.aspx //.WithAmount(decimal.Parse(Session["amount"].ToString())) //For example we will be authorizing amount value of 1.99 .WithAmount((decimal)1.99) .WithCurrencyCode(Regions.currencyCode.USD) .WithAuthorizationReferenceId(uniqueReferenceId) .WithTransactionTimeout(0) .WithCaptureNow(true) .WithSellerAuthorizationNote("Note"); AuthorizeResponse authResponse = client.AuthorizeOnBillingAgreement(authRequestParameters); apiResponse["authorizeOnBillingAgreementResponse"] = authResponse.GetJson(); if (!authResponse.GetSuccess()) { string errorCode = authResponse.GetErrorCode(); string errorMessage = authResponse.GetErrorMessage(); } else { // AuthorizeOnBillingAgreement was a success amazonAuthorizationId = authResponse.GetAuthorizationId(); // Check if the Capture Now was set to true captureNow = authResponse.GetCaptureNow(); // If captureNow was true then the capture has already happened. Get the Capture ID(s) from the List if (captureNow) { amazonCaptureIdList = authResponse.GetCaptureIdList(); } CaptureApiCall(); return apiResponse; } return apiResponse; }
/// <summary> /// Sets the Amazon Order Reference ID / Amazon Billing Agreement ID /// </summary> /// <param name="amazon_reference_id"></param> /// <returns>ChargeRequest</returns> public ChargeRequest WithAmazonReferenceId(string amazon_reference_id) { if (!string.IsNullOrEmpty(amazon_reference_id)) { string switchChar = amazon_reference_id; switch (switchChar[0]) { case 'P': case 'S': chargeType = "OrderReference"; getOrderReferenceDetails.WithAmazonOrderReferenceId(amazon_reference_id); setOrderReferenceDetails.WithAmazonOrderReferenceId(amazon_reference_id); confirmOrderReference.WithAmazonOrderReferenceId(amazon_reference_id); authorizeOrderReference.WithAmazonOrderReferenceId(amazon_reference_id); break; case 'B': case 'C': chargeType = "BillingAgreement"; getBillingAgreementDetails.WithAmazonBillingAgreementId(amazon_reference_id); setBillingAgreementDetails.WithAmazonBillingAgreementId(amazon_reference_id); confirmBillingAgreement.WithAmazonBillingAgreementId(amazon_reference_id); authorizeOnBillingAgreement.WithAmazonBillingAgreementId(amazon_reference_id); break; default: throw new InvalidDataException("Invalid Amazon Reference ID"); } } else { throw new MissingFieldException("Amazon Reference ID is a required field and should be a Order Reference ID / Billing Agreement ID"); } return(this); }