Suretax changes

This commit is contained in:
DanB
2015-10-26 10:58:24 +01:00
parent 4ee1200c64
commit 63385160b7
3 changed files with 16 additions and 17 deletions

View File

@@ -26,7 +26,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"
@@ -130,17 +129,6 @@ type STRequestItem struct {
TaxExemptionCodeList []string // Required. Tax Exemption to be applied to this item only.
}
// Converts the request into the format SureTax expects
func (self *SureTaxRequest) AsHttpForm() (url.Values, error) {
jsnContent, err := json.Marshal(self)
if err != nil {
return nil, err
}
v := url.Values{}
v.Set("request", string(jsnContent))
return v, nil
}
// SureTax Response type
type SureTaxResponse struct {
Successful string // Response will be either Y' or N' : Y = Success / Success with Item error N = Failure
@@ -190,13 +178,13 @@ func SureTaxProcessCdr(cdr *StoredCdr) error {
if err != nil {
return err
}
body, err := json.Marshal(req)
jsnContent, err := json.Marshal(req)
if err != nil {
return err
}
utils.Logger.Debug(fmt.Sprintf("###SureTax NewSureTaxRequest: %+v, ItemList: %+v\n", req, req.ItemList[0]))
resp, err := sureTaxClient.Post(stCfg.Url, "application/json", bytes.NewBuffer(body))
utils.Logger.Debug(fmt.Sprintf("###SureTax NewSureTaxRequest to: %s, body: %+v, ItemList: %+v\n", stCfg.Url, req, req.ItemList[0]))
body := append([]byte("request="), jsnContent...)
resp, err := sureTaxClient.Post(stCfg.Url, "application/x-www-form-urlencoded", bytes.NewBuffer(body))
if err != nil {
return err
}

View File

@@ -137,7 +137,7 @@ func TestSTIProcessExternalCdr(t *testing.T) {
AccId: "teststicdr1", CdrHost: "192.168.1.1", CdrSource: "STI_TEST", ReqType: utils.META_RATED, Direction: utils.OUT,
Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "+14082342500", Destination: "+16268412300", Supplier: "SUPPL1",
SetupTime: "2015-10-18T13:00:00Z", AnswerTime: "2015-10-18T13:00:00Z",
Usage: "15s", Pdd: "7.0", ExtraFields: map[string]string{"ClientNumber": "000000534", "": "valextr2"},
Usage: "15s", Pdd: "7.0", ExtraFields: map[string]string{"CustomerNumber": "000000534", "ZipCode": ""},
}
var reply string
if err := stiRpc.Call("CdrsV2.ProcessExternalCdr", cdr, &reply); err != nil {

View File

@@ -221,3 +221,14 @@ func TestRSRFieldsId(t *testing.T) {
t.Errorf("Received id: %s", idRcv)
}
}
func TestRSRCostDetails(t *testing.T) {
fieldsStr1 := `{"Direction":"*out","Category":"default_route","Tenant":"demo.cgrates.org","Subject":"voxbeam_premium","Account":"6335820713","Destination":"15143606781","TOR":"*voice","Cost":0.0007,"Timespans":[{"TimeStart":"2015-08-30T21:46:54Z","TimeEnd":"2015-08-30T21:47:06Z","Cost":0.00072,"RateInterval":{"Timing":{"Years":[],"Months":[],"MonthDays":[],"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"RoundingMethod":"*middle","RoundingDecimals":5,"MaxCost":0,"MaxCostStrategy":"0","Rates":[{"GroupIntervalStart":0,"Value":0.0036,"RateIncrement":6000000000,"RateUnit":60000000000}]},"Weight":10},"DurationIndex":12000000000,"Increments":[{"Duration":6000000000,"Cost":0.00036,"BalanceInfo":{"UnitBalanceUuid":"","MoneyBalanceUuid":"40adda88-25d3-4009-b928-f39d61590439","AccountId":"*out:demo.cgrates.org:6335820713"},"BalanceRateInterval":null,"UnitInfo":null,"CompressFactor":2}],"MatchedSubject":"*out:demo.cgrates.org:default_route:voxbeam_premium","MatchedPrefix":"1514","MatchedDestId":"Canada","RatingPlanId":"RP_VOXBEAM_PREMIUM"}]}`
rsrField, err := NewRSRField(`~cost_details:s/"MatchedDestId":"(\w+)"/${1}/`)
if err != nil {
t.Error(err)
}
if parsedVal := rsrField.ParseValue(fieldsStr1); parsedVal != "Canada" {
t.Errorf("Expecting: Canada, received: %s", parsedVal)
}
}