Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plus Transaction Refund (2) #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions Transbank/WebpayRest/Common/CardDetail.cs
@@ -0,0 +1,16 @@
using System;
using Newtonsoft.Json;

namespace Transbank.Webpay.Common
{
public class CardDetail
{
[JsonProperty("card_number")]
public string CardNumber { get; set; }

public override string ToString()
{
return $"CardNumber={CardNumber}";
}
}
}
11 changes: 11 additions & 0 deletions Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs
@@ -0,0 +1,11 @@
using System;
using System.Net.Http;
using Transbank.Webpay.Common;
namespace Transbank.Webpay.WebpayPlus.Requests
{
internal class CommitRequest : BaseRequest
{
internal CommitRequest(string token)
: base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) {}
}
}
24 changes: 24 additions & 0 deletions Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs
@@ -0,0 +1,24 @@
using System;
using Transbank.Webpay.Common;
using Newtonsoft.Json;
using System.Net.Http;

namespace Transbank.Webpay.WebpayPlus.Requests
{
internal class RefundRequest : BaseRequest
{
[JsonProperty("amount")]
public decimal Amount { get; set; }

public override string ToString()
{
return $"Amount={Amount}";
}

internal RefundRequest(string token, decimal amount)
: base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post)
{
Amount = amount;
}
}
}
52 changes: 52 additions & 0 deletions Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;
using Transbank.Webpay.Common;

namespace Transbank.Webpay.WebpayPlus.Responses
{
public class CommitResponse
{
[JsonProperty("vci")]
public string Vci { get; set; }
[JsonProperty("amount")]
public decimal Amount { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("buy_order")]
public string BuyOrder { get; set; }
[JsonProperty("session_id")]
public string SessionId { get; set; }
[JsonProperty("card_detail")]
public CardDetail CardDetail { get; set; }
[JsonProperty("accounting_date")]
public string AccountingDate { get; set; }
[JsonProperty("transaction_date")]
public DateTime TransactionDate { get; set; }
[JsonProperty("authorization_code")]
public string AuthorizationCode { get; set; }
[JsonProperty("payment_type_code")]
public string PaymentTypeCode { get; set; }
[JsonProperty("response_code")]
public int ResponseCode { get; set; }
[JsonProperty("installments_amount")]
public int InstallmentsAmount { get; set; }
[JsonProperty("installments_number")]
public int InstallmentsNumber { get; set; }
[JsonProperty("balance")]
public decimal Balance { get; set; }

public override string ToString()
{
var properties = new List<string>();
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this))
{
string name = descriptor.Name;
object value = descriptor.GetValue(this);
properties.Add($"{name}={value}");
}
return String.Join(", ", properties);
}
}
}
35 changes: 35 additions & 0 deletions Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json;

namespace Transbank.Webpay.WebpayPlus.Responses
{
public class RefundResponse
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("authorization_code")]
public string AuthorizationCode { get; set; }
[JsonProperty("authorization_date")]
public DateTime AuthorizationDate { get; set; }
[JsonProperty("nullified_amount")]
public decimal NullifiedAmount { get; set; }
[JsonProperty("balance")]
public decimal Balance { get; set; }
[JsonProperty("response_code")]
public int ResponseCode { get; set; }

public override string ToString()
{
var properties = new List<string>();
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this))
{
string name = descriptor.Name;
object value = descriptor.GetValue(this);
properties.Add($"{name}={value}");
}
return String.Join(", ", properties);
}
}
}
26 changes: 26 additions & 0 deletions Transbank/WebpayRest/WebpayPlus/Transaction.cs
Expand Up @@ -22,5 +22,31 @@ public static class Transaction

return JsonConvert.DeserializeObject<CreateResponse>(response);
}

public static CommitResponse Commit(string token)
{
return Commit(token, WebpayPlus.DefaultOptions());
}

public static CommitResponse Commit(string token, Options options)
{
var commitRequest = new CommitRequest(token);
var response = RequestService.Perform(commitRequest, options);

return JsonConvert.DeserializeObject<CommitResponse>(response);
}

public static RefundResponse Refund(string token, decimal amount)
{
return Refund(token, amount, WebpayPlus.DefaultOptions());
}

public static RefundResponse Refund(string token, decimal amount, Options options)
{
var refundRequest = new RefundRequest(token, amount);
var response = RequestService.Perform(refundRequest, options);

return JsonConvert.DeserializeObject<RefundResponse>(response);
}
}
}