Exemplo n.º 1
0
 public RedirectInformationSOAP(int requestId, Status status, RedirectRequest request, List <TransactionSOAP> payment, SubscriptionInfomationSOAP subscription)
 {
     this.requestId    = requestId;
     this.status       = status;
     this.request      = request;
     this.payment      = payment;
     this.subscription = subscription;
 }
Exemplo n.º 2
0
        public override RedirectInformation Collect(CollectRequest collectRequest)
        {
            try
            {
                this._action = "/collect";

                string request = Serializer.JsonSerializer.SerializeObject(collectRequest);

                var node = JsonConvert.DeserializeXmlNode(request, "payload");

                XElement collect = new XElement(p2p + "collect", XElement.Parse(node.OuterXml));

                string response = this.CallWebService(collect);

                response = Regex.Replace(response, @"(\s*)""@(.*)"":", @"$1""$2"":", RegexOptions.IgnoreCase);
                JObject res = JObject.Parse(response);

                if (res["ns1:collectResponse"]["collectResult"]["payment"] != null)
                {
                    var transaction = res["ns1:collectResponse"]["collectResult"]["payment"]["transaction"];
                    res["ns1:collectResponse"]["collectResult"]["payment"] = null;
                    var data = res["ns1:collectResponse"]["collectResult"];
                    RedirectInformationSOAP redirectInformationSOAP = JsonConvert.DeserializeObject <RedirectInformationSOAP>(data.ToString(), Serializer.JsonSerializer.Settings);

                    if (transaction.Type.ToString() == "Object")
                    {
                        List <TransactionSOAP> transactions    = new List <TransactionSOAP>();
                        TransactionSOAP        transactionSOAP = JsonConvert.DeserializeObject <TransactionSOAP>(transaction.ToString());
                        transactions.Add(transactionSOAP);
                        redirectInformationSOAP.Payment = transactions;
                    }
                    else
                    {
                        List <TransactionSOAP> transactions = new List <TransactionSOAP>();
                        TransactionSOAP        transactionSOAP;
                        foreach (var item in transaction.Children())
                        {
                            transactionSOAP = JsonConvert.DeserializeObject <TransactionSOAP>(item.ToString());
                            transactions.Add(transactionSOAP);
                        }
                        redirectInformationSOAP.Payment = transactions;
                    }

                    List <Transaction> paymentTransaction = new List <Transaction>();
                    foreach (var tSOAP in redirectInformationSOAP.Payment)
                    {
                        Transaction T = new Transaction(tSOAP.Status, tSOAP.Reference, tSOAP.InternalReference, tSOAP.PaymentMethod, tSOAP.PaymentMethodName, tSOAP.IssuerName, tSOAP.Amount, tSOAP.Authorization, tSOAP.Receipt, tSOAP.Franchise, tSOAP.Refunded, tSOAP.ProcessorFields.item);
                        paymentTransaction.Add(T);
                    }

                    RedirectInformation redirectInformation = new RedirectInformation(redirectInformationSOAP.RequestId, redirectInformationSOAP.Status, redirectInformationSOAP.Request, paymentTransaction, null);

                    return(redirectInformation);
                }
                else if (res["ns1:collectResponse"]["collectResult"]["subscription"] != null)
                {
                    var data = res["ns1:getRequestInformationResponse"]["getRequestInformationResult"];
                    RedirectInformationSOAP    redirectInformationSOAP    = JsonConvert.DeserializeObject <RedirectInformationSOAP>(data.ToString());
                    SubscriptionInfomationSOAP subscriptionInfomationSOAP = redirectInformationSOAP.Subscription;
                    SubscriptionInformation    subscriptionInformation    = new SubscriptionInformation(subscriptionInfomationSOAP.Type, subscriptionInfomationSOAP.Status, subscriptionInfomationSOAP.Instrument.item);
                    RedirectInformation        redirectInformation        = new RedirectInformation(redirectInformationSOAP.RequestId, redirectInformationSOAP.Status, redirectInformationSOAP.Request, null, subscriptionInformation);

                    return(redirectInformation);
                }
                else
                {
                    var data = res["ns1:collectResponse"]["collectResult"];
                    return(JsonConvert.DeserializeObject <RedirectInformation>(data.ToString()));
                }
            }
            catch (Exception ex)
            {
                Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"));
                RedirectInformation redirectInformation = new RedirectInformation(0, status, null, null, null);

                return(redirectInformation);
            }
        }