//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>This operation allows to query for the current status of an already initiated purchase /// (i.e. payment transaction).</summary> /// <param name="transactionId">The id of the transaction wich status is going to be retrieved.</param> /// <returns>A PaymentResult.</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public PaymentStatus GetPaymentStatus(String transactionId) { if (string.IsNullOrEmpty(transactionId)) { throw new BlueviaException("Null or Empty transactionId when requesting a payment status." , ExceptionCode.InvalidArgumentException); } //Building the object wich will be serialized to serve as body GetPaymentStatusParamsType paymentStatusParams = new GetPaymentStatusParamsType(); paymentStatusParams.transactionId = transactionId; MethodCallType1 mct1 = new Schemas.MethodCallType1(); mct1.id = HttpTools.generateRPCId(); mct1.version = Core.Constants.blueviaRPCAccessVersion; mct1.method = MethodType.GET_PAYMENT_STATUS; mct1.@params = new MethodCallTypeParams(); [email protected] = paymentStatusParams; //Selecting the apropiate parser/serializer for the operation: serializer = xmlSerializer; parser = xmlParser; //The Bluevia´s complex response object, as result of the call: MethodResponseType1 response = BaseCreate<MethodResponseType1, MethodCallType1>( string.Format(paymentUrl, Constants.PaymentGetPaymentStatus) , CreateParameters() , mct1 , CreateHeaders(HttpTools.ContetTypeXML)); return PaymentSimplifiers.SimplifyPaymentStatusResultType((GetPaymentStatusResultType)response.result.Item); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Cancels the previous AccesToken requested, before making the payment.</summary> /// <remarks> 2012/03/29. </remarks> //////////////////////////////////////////////////////////////////////////////////////////////////// public bool CancelAuthorization() { MethodCallType1 mct1 = new Schemas.MethodCallType1(); mct1.id = HttpTools.generateRPCId(); mct1.version = Core.Constants.blueviaRPCAccessVersion; mct1.method = Schemas.MethodType.CANCEL_AUTHORIZATION; //Selecting the apropiate parser/serializer for the operation: serializer = xmlSerializer; parser = null; //No complex response object expected, as result of the call: BaseCreate<bool, MethodCallType1>( string.Format(paymentUrl, Constants.PaymentCancelAuthorization) , CreateParameters() , mct1 , CreateHeaders(HttpTools.ContetTypeXML)); return true; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>This operation allows to request a charge in the account indicated by the end user identifier, /// with information about the purchase, such as economic units, the currency employed, /// optional information about additional taxes that could apply, /// generic code and a suggested reference code which uniquely identifies the current payment event. /// </summary> /// <param name="amount">Unsigned int whith the amount (without decimals), of the desired payment.</param> /// <param name="currency">String with the currency of the payment.</param> /// <param name="endpoint"> Optional: String which contains the endpoint where status notifications will be sent.</param> /// <param name="correlator">Optional, Mandatory if Notifications: The correlator for the status notifications.</param> /// <returns>A PaymentResult Object.</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public PaymentResult Payment(uint amount, String currency, String endpoint = null, String correlator = null) { if(string.IsNullOrWhiteSpace(connector.GetToken())) { throw new BlueviaException("Null or empty Tokens when making a Payment." , ExceptionCode.InvalidArgumentException); } if (amount < 0 || string.IsNullOrEmpty(currency)) { throw new BlueviaException("Wrong mandatory parameters when making a Payment." , ExceptionCode.InvalidArgumentException); } PaymentParamsType paymentParams = new PaymentParamsType(); paymentParams.paymentInfo = new PaymentInfoType(); paymentParams.paymentInfo.amountSpecified = true; paymentParams.paymentInfo.amount = amount; paymentParams.paymentInfo.currency = currency; double seconds = Convert.ToInt64(HttpTools.GenerateTimeStamp()); DateTime date = new DateTime(1970, 1, 1, 0, 0, 0); date = date.AddSeconds(seconds); paymentParams.timestamp = date; //OPtional fields if (!string.IsNullOrEmpty(endpoint) && !string.IsNullOrEmpty(correlator))//Both endpoint and correlator arent null nor empty { paymentParams.receiptRequest = new SimpleReferenceType() { endpoint = endpoint, correlator = correlator }; } else if (!(string.IsNullOrEmpty(endpoint) && string.IsNullOrEmpty(correlator)))//One of enpoint or correlator is null or empty { throw new BlueviaException("Both endpoint and correlator parameters,are mandatory when making payment with status notifications." , ExceptionCode.InvalidArgumentException); } //Building the object wich will be serialized to serve as body MethodCallType1 mct1 = new Schemas.MethodCallType1(); mct1.id = HttpTools.generateRPCId(); mct1.version = Core.Constants.blueviaRPCAccessVersion; mct1.method = Schemas.MethodType.PAYMENT; mct1.@params = new Schemas.MethodCallTypeParams(); [email protected] = paymentParams; //As the timestamp of the payment must be the same as the Oauth: Dictionary<string, string> oauthExtra = new Dictionary<string, string>(); oauthExtra.Add(OAuthConstants.OAuthTimestampKey, seconds.ToString()); connector.SetOAuthParams(oauthExtra); //Selecting the apropiate parser/serializer for the operation: serializer = xmlSerializer; parser = xmlParser; //The Bluevia´s complex response object, as result of the call: MethodResponseType1 response = BaseCreate<MethodResponseType1, MethodCallType1>( string.Format(paymentUrl, Constants.PaymentPayment) , CreateParameters() , mct1 , CreateHeaders(HttpTools.ContetTypeXML)); return PaymentSimplifiers.SimplifyPaymentResultType((PaymentResultType)response.result.Item); }