Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ public async Task<OperatorResponse> ProcessSaleMessage(Guid transactionId,
throw new Exception("CustomerAccountNumber is a required field for this transaction type");
}

String requestUrl = this.BuildRequest(transactionDateTime, transactionReference, customerMsisdn, transactionAmount);
// Multiply amount before sending
// Covert the transaction amount to Decimal and remove decimal places
if (Decimal.TryParse(transactionAmount, out Decimal amountAsDecimal) == false)
{
throw new Exception("Transaction Amount is not a valid decimal value");
}

Decimal operatorTransactionAmount = amountAsDecimal * 100;

String requestUrl = this.BuildRequest(transactionDateTime, transactionReference, customerMsisdn, operatorTransactionAmount);

// Concatenate the request message
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(requestUrl));
Expand Down Expand Up @@ -115,18 +124,12 @@ public async Task<OperatorResponse> ProcessSaleMessage(Guid transactionId,
private String BuildRequest(DateTime transactionDateTime,
String externalReference,
String customerMsisdn,
String transactionAmount)
Decimal transactionAmount)
{
String requestUrl = $"{this.SafaricomConfiguration.Url}?VENDOR={this.SafaricomConfiguration.LoginId}&REQTYPE=EXRCTRFREQ&DATA=";

StringBuilder xmlData = new StringBuilder();

// Covert the transaction amount to Decimal and remove decimal places
if (Decimal.TryParse(transactionAmount, out Decimal amountAsDecimal) == false)
{
throw new Exception("Transaction Amount is not a valid decimal value");
}


// Now build up the XML part of the message
xmlData.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xmlData.Append("<ns0:COMMAND xmlns:ns0=\"http://safaricom.co.ke/Pinless/keyaccounts/\">");
Expand All @@ -140,7 +143,7 @@ private String BuildRequest(DateTime transactionDateTime,
xmlData.Append($"<ns0:EXTCODE>{this.SafaricomConfiguration.ExtCode}</ns0:EXTCODE>");
xmlData.Append($"<ns0:EXTREFNUM>{externalReference}</ns0:EXTREFNUM>");
xmlData.Append($"<ns0:MSISDN2>{customerMsisdn}</ns0:MSISDN2>");
xmlData.Append($"<ns0:AMOUNT>{amountAsDecimal:G0}</ns0:AMOUNT>");
xmlData.Append($"<ns0:AMOUNT>{transactionAmount:G0}</ns0:AMOUNT>");
xmlData.Append("<ns0:LANGUAGE1>0</ns0:LANGUAGE1>");
xmlData.Append("<ns0:LANGUAGE2>0</ns0:LANGUAGE2>");
xmlData.Append("<ns0:SELECTOR>0</ns0:SELECTOR>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ Background:

Given I make the following manual merchant deposits
| Reference | Amount | DateTime | MerchantName | EstateName |
| Deposit1 | 2000.00 | Today | Test Merchant 1 | Test Estate 1 |
| Deposit1 | 1000.00 | Today | Test Merchant 2 | Test Estate 1 |
| Deposit1 | 1000.00 | Today | Test Merchant 3 | Test Estate 2 |
| Deposit1 | 200.00 | Today | Test Merchant 1 | Test Estate 1 |
| Deposit1 | 100.00 | Today | Test Merchant 2 | Test Estate 1 |
| Deposit1 | 100.00 | Today | Test Merchant 3 | Test Estate 2 |

@PRTest
Scenario: Sale Transactions

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 1000.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 2 | Sale | Test Merchant 2 | 123456781 | Test Estate 1 | Safaricom | 1000.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 3 | Sale | Test Merchant 3 | 123456782 | Test Estate 2 | Safaricom | 1000.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 4 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 1000.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 100.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 2 | Sale | Test Merchant 2 | 123456781 | Test Estate 1 | Safaricom | 100.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 3 | Sale | Test Merchant 3 | 123456782 | Test Estate 2 | Safaricom | 100.00 | 123456789 | | Safaricom Contract | Variable Topup |
| Today | 4 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 100.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
Expand All @@ -87,7 +87,7 @@ Scenario: Sale Transaction with Invalid Device

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName |
| Today | 1 | Sale | Test Merchant 1 | 123456781 | Test Estate 1 | Safaricom | 1000.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |
| Today | 1 | Sale | Test Merchant 1 | 123456781 | Test Estate 1 | Safaricom | 100.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
Expand All @@ -97,7 +97,7 @@ Scenario: Sale Transaction with Invalid Estate

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | InvalidEstate | Safaricom | 1000.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | InvalidEstate | Safaricom | 100.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
Expand All @@ -107,7 +107,7 @@ Scenario: Sale Transaction with Invalid Merchant

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName |
| Today | 1 | Sale | InvalidMerchant | 123456780 | Test Estate 1 | Safaricom | 1000.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |
| Today | 1 | Sale | InvalidMerchant | 123456780 | Test Estate 1 | Safaricom | 100.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
Expand All @@ -118,9 +118,9 @@ Scenario: Sale Transaction with Not Enough Credit Available

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 3000.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |
| Today | 1 | Sale | Test Merchant 1 | 123456780 | Test Estate 1 | Safaricom | 300.00 | 123456789 | testcustomer@customer.co.uk | Safaricom Contract | Variable Topup |


Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| Test Estate 1 | Test Merchant 1 | 1 | 1009 | Merchant [Test Merchant 1] does not have enough credit available [2000.0] to perform transaction amount [3000.00] |
| Test Estate 1 | Test Merchant 1 | 1 | 1009 | Merchant [Test Merchant 1] does not have enough credit available [200.0] to perform transaction amount [300.00] |
Loading