Skip to content

Commit

Permalink
Bug fix: ChargeAPI RequestDTos missing fields #12
Browse files Browse the repository at this point in the history
  • Loading branch information
adebisi-fa committed Apr 2, 2019
1 parent 093bcf1 commit 3a2fea1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
14 changes: 11 additions & 3 deletions src/main/Apis/Charge/Charge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ public class Bank
public string AccountNumber { get; set; }
}

public class BankChargeRequest : RequestMetadataExtender
public class ChargeRequest : RequestMetadataExtender
{
public string Reference { get; set; }

[JsonProperty("device_id")]
public string DeviceId { get; set; }
}

public class BankChargeRequest : ChargeRequest
{
[JsonProperty("email")]
public string Email { get; set; }
Expand Down Expand Up @@ -173,7 +181,7 @@ public class Card
public string ExpiryYear { get; set; }
}

public class CardChargeRequest : RequestMetadataExtender
public class CardChargeRequest : ChargeRequest
{

[JsonProperty("email")]
Expand All @@ -189,7 +197,7 @@ public class CardChargeRequest : RequestMetadataExtender
public string Pin { get; set; }
}

public class AuthorizationCodeChargeRequest : RequestMetadataExtender
public class AuthorizationCodeChargeRequest : ChargeRequest
{

[JsonProperty("email")]
Expand Down
48 changes: 34 additions & 14 deletions src/main/Apis/Charge/ChargeApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ public ChargeApi(PayStackApi api)
this._api = api;
}

public ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin) =>
public ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin, string reference = null, bool makeReferenceUnique = false) =>
ChargeAuthorizationCode(
new AuthorizationCodeChargeRequest
{
Email = email,
Amount = amount,
AuthorizationCode = authorizationCode,
Pin = pin
}
Pin = pin,
Reference = makeReferenceUnique && reference != null ?
$"{reference}-{Guid.NewGuid().ToString().Substring(0, 8)}" : reference
},
makeReferenceUnique
);

public ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request) =>
_api.Post<ChargeResponse, AuthorizationCodeChargeRequest>("charge", request);
public ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request, bool makeReferenceUnique = false)
{
if (makeReferenceUnique && request.Reference != null)
request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}";
return _api.Post<ChargeResponse, AuthorizationCodeChargeRequest>("charge", request);
}

public ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber) =>
public ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber, string reference = null, bool makeReferenceUnique = false) =>
ChargeBank(
new BankChargeRequest
{
Expand All @@ -35,14 +42,21 @@ public ChargeResponse ChargeBank(string email, string amount, string bankCode, s
{
Code = bankCode,
AccountNumber = bankAccountNumber
}
}
},
Reference = reference
},
makeReferenceUnique
);

public ChargeResponse ChargeBank(BankChargeRequest request) =>
_api.Post<ChargeResponse, BankChargeRequest>("charge", request);
public ChargeResponse ChargeBank(BankChargeRequest request, bool makeReferenceUnique = false)
{
if (makeReferenceUnique && request.Reference != null)
request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}";

public ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin) =>
return _api.Post<ChargeResponse, BankChargeRequest>("charge", request);
}

public ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin, string reference = null, bool makeReferenceUnique = false) =>
ChargeCard(
new CardChargeRequest
{
Expand All @@ -55,12 +69,18 @@ public ChargeResponse ChargeCard(string email, string amount, string cardNumber,
ExpiryMonth = cardExpiryMonth,
ExpiryYear = cardExpiryYear
},
Pin = pin
Pin = pin,
Reference = reference
}
);

public ChargeResponse ChargeCard(CardChargeRequest request) =>
_api.Post<ChargeResponse, CardChargeRequest>("charge", request);
public ChargeResponse ChargeCard(CardChargeRequest request, bool makeReferenceUnique = false)
{
if (makeReferenceUnique && request.Reference != null)
request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}";

return _api.Post<ChargeResponse, CardChargeRequest>("charge", request);
}

public ChargeResponse CheckPendingCharge(string reference) =>
_api.Get<ChargeResponse>($"charge/{reference}");
Expand Down
14 changes: 7 additions & 7 deletions src/main/Apis/Charge/IChargeApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ public interface IChargeApi
{
ChargeTokenizeResponse Tokenize(string email, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear);

ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber);
ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber, string reference = null, bool makeReferenceUnique = false);

ChargeResponse ChargeBank(BankChargeRequest request);
ChargeResponse ChargeBank(BankChargeRequest request, bool makeReferenceUnique = false);

ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin);
ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin, string reference = null, bool makeReferenceUnique = false);

ChargeResponse ChargeCard(CardChargeRequest request);
ChargeResponse ChargeCard(CardChargeRequest request, bool makeReferenceUnique = false);

ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin);
ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin, string reference = null, bool makeReferenceUnique = false);

ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request);
ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request, bool makeReferenceUnique = false);

ChargeResponse SubmitPIN(string reference, string pin);

Expand All @@ -28,6 +28,6 @@ public interface IChargeApi
ChargeResponse SubmitBirthday(string reference, DateTime birthday);

ChargeResponse CheckPendingCharge(string reference);

}
}
4 changes: 2 additions & 2 deletions src/main/Apis/Transactions/TransactionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ChargeAuthorizationResponse ChargeAuthorization(string authorizationCode,
AuthorizationCode = authorizationCode,
Email = email,
AmountInKobo = amountInKobo
});
}, makeReferenceUnique);

public ChargeAuthorizationResponse ChargeAuthorization(ChargeAuthorizationRequest request, bool makeReferenceUnique = false)
{
Expand All @@ -71,7 +71,7 @@ public ReAuthorizationResponse RequestReAuthorization(string authorizationCode,
Email = email,
AmountInKobo = amountInKobo,
Reference = reference
});
}, makeReferenceUnique);

public ReAuthorizationResponse RequestReAuthorization(ReAuthorizationRequest request, bool makeReferenceUnique = false)
{
Expand Down
6 changes: 5 additions & 1 deletion src/main/main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageId>Paystack.Net</PackageId>
<Title>PayStack API for .Net</Title>
<Version>0.7.3</Version>
<Version>0.7.4</Version>
<Authors>Adebisi Foluso A.</Authors>
<Company />
<Product>PayStack.Net</Product>
Expand All @@ -14,6 +14,10 @@
<PackageProjectUrl>https://github.com/adebisi-fa/paystack-dotnet</PackageProjectUrl>
<PackageIconUrl>https://cdn-images-1.medium.com/fit/c/100/100/1*We_5HSqJAUVETQ7xgcJNQQ.png</PackageIconUrl>
<PackageReleaseNotes>
-- v0.7.4 --
* Bug fix. Adds ChargeApi missing request DTOs properties: Reference and DeviceId - (#12)
* Minor bug fixes.

-- v0.7.3 --
* Bug fix. Transaction's ChargeAuthorization method included (big thanks to Aghogho Bernard - @teghoz)
* Transaction's CheckAuthorization and RequestReauthorization methods now included.
Expand Down

0 comments on commit 3a2fea1

Please sign in to comment.