Throwing an exception when I trying to create sales order in VTiger version 6.15.7.6
Sending the following entity
for Sales order creation
VTigerListItem[] arrListItem = new VTigerListItem[1];
arrListItem[0] = new VTigerListItem() { productid = "25x405", listprice = "468.25", quantity = "1" };
VTigerSalesOrder[] arrListItem1 = new VTigerSalesOrder[1];
arrListItem1[0] = new VTigerSalesOrder()
{
start_period = "2015-01-01",
end_period = "2015-01-01",
subject = "Testing",
contact_id = "4x680",
sostatus = SoStatus.Created,
account_id = "3x679",
assigned_user_id = "19x11",
bill_street = "test bill street",
invoicestatus = Invoicestatus.Created,
productid = "25x405",
cf_1121 = "RDMS",
createdtime = "2015-01-01",
modifiedtime = "2015-01-01",
LineItems = arrListItem
};
var desc = vtigerApi.Create(arrListItem1[0]);
Please check the Contactid , Accountid and Productid.
Module ids are given wrong.
Contacts start with 12X,
Accounts start with 11X,
Products start with 14X,
assign_user_id if it is assigning to User then 19X, if it is assigning to Group then 20X. Also change contact_id to contactid,account_id to accountid.
Related
I try add payment method to my project where customer can buy product from other user. But i have problem because when i use it:
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
Mode = "payment",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 123,
},
};
var requestOptions = new RequestOptions
{
StripeAccount = "{{CONNECTED_ACCOUNT_ID}}",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);
PRICE_ID can't be price's on my main stripe account and i must create product and price on the connected account.
In the case of creating a product on the main account, I do it like this:
var options = new ProductCreateOptions
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
};
_productService.Create(options);
How create product and price on the connected account with my api?
The Stripe API has a Stripe-Account header where you can pass in the ID of one of your connected accounts to make the call as that account. In C# that would look like this:
{
Id = ProductId.ToString(),
Name = "Product_name",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" },
StripeAccount = "acct_123456789",
};
_productService.Create(options);
My problem as it is right now. It is that I must have made such that a customer can buy an item that is only paid once. Thus assigned Invoice id and PDf to the database.
As it is right now I only get hold of Invoice id while PDF is null.
I've read a little more about this.
Invoice Id return with null after change using Stripe
var options = new ProductCreateOptions
{
Name = "Starter Setup",
};
var service = new ProductService();
var product = service.Create(options);
var optionsA = new PriceCreateOptions
{
Product = product.Id,
UnitAmount = 2000,
Currency = "usd",
};
var serviceA = new PriceService();
var price = serviceA.Create(optionsA);
var optionsB = new CustomerCreateOptions
{
Email = model.Mail,
Name = model.FuldName,
Source = token
};
var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);
var optionsC = new InvoiceItemCreateOptions
{
Customer = customer.Id,
Price = price.Id,
};
var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);
var invoiceId = invoiceItem.Id;
var serviceE = new InvoiceService();
var f = serviceE.Get(invoiceId);
var pdf = f.InvoicePdf;// This here gives zero.
If I do it this way, I'll get this out of it. I get the Invoice ID that I want here but I get nothing on the invoice that shows that it is zero.
{
"id": "ii_1IR4UtFnB7TvDVRrzPwWo8ZW",
"object": "invoiceitem",
"amount": 2000,
"currency": "usd",
"customer": "cus_J3Aqpyt4PwqCcN",
"date": 1614815575,
"description": "Starter Setup",
"discountable": true,
"discounts": [
],
"invoice": null,
"livemode": false,
"metadata": {
},
....
}
With this, my thinking is whether I will in a way be able to make such that I make a membership which then stops immediately but that it says in the invoice that the purchase is only of a single item and not several months.
The way I have done it in relation to membership I have done like this.
var createCustomer = new CustomerCreateOptions
{
Source = token,
Name = model.FuldName,
Email = model.Mail
};
var addService = new CustomerService();
var customer = addService.Create(createCustomer);
var optionsProduct = new ProductCreateOptions
{
Name = $"Single buy - {DateTime.Now} - Kursus Id : {id}",
Type = "service",
};
var serviceProduct = new ProductService();
Product product = serviceProduct.Create(optionsProduct);
var optionsPlan = new PlanCreateOptions
{
Currency = "dkk",
Interval = Helpers.Stripe.interval,
Nickname =
$"Single buy - {DateTime.Now} - Kursus Id : {id}",
Amount = amount,
Product = product.Id,
IntervalCount = 1
};
var servicePlan = new PlanService();
Plan plan = servicePlan.Create(optionsPlan);
var items = new List<SubscriptionItemOptions>()
{
new SubscriptionItemOptions()
{
Plan = plan.Id,
Quantity = 1
},
};
var createSubscruptionA = new SubscriptionCreateOptions
{
Customer = customer.Id,
Items = items,
OffSession = true,
};
var addserviceA = new SubscriptionService();
Subscription subscription = addserviceA.Create(createSubscruptionA);
var invoiceId = subscription.LatestInvoiceId;
var service = new InvoiceService();
var pdf = service.Get(invoiceId).InvoicePdf;
That which I would like to achieve by this. It is that I can get hold of PDF and Invoice id as I will use it for my system in the future etc.
EDIT
var optionsB = new CustomerCreateOptions
{
Email = model.Mail,
Name = model.FuldName,
Source = token
};
var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);
var optionsC = new InvoiceItemCreateOptions
{
Customer = customer.Id,
Price = price.Id,
};
var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);
var invoiceId = invoiceItem.Id;
var invoiceOptions = new InvoiceCreateOptions
{
Customer = customer.Id,
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
For one-off Invoices you need to create Invoice Items for the Customer (as you've done), but importantly you then need to create an Invoice that will contain those Items.
This line is not correct for what you're trying to accomplish:
var invoiceId = invoiceItem.Id;
Instead, you need to create the invoice as shown in the docs linked above:
var invoiceOptions = new InvoiceCreateOptions
{
Customer = "cus_123",
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
The Invoice object will have an invoice_pdf URL (docs) after you finalize it.
var service = new InvoiceService();
service.FinalizeInvoice(
"in_123"
);
I am working to create a sales order with a single product added to the sales order detail and attach that to the sales order.
It is throwing me an error and I am wondering if there is a proper way to performing this action?
Thanks!
public void Create(CrmContextCore _crmContext, Guid productId, UserEntityModel currentuser)
{
var detail = new Entity("salesorderdetail");
{
detail["productid"] = new EntityReference("product", productId);
}
var salesorder = new Entity("salesorder");
{
salesorder["accountid"] = new EntityReference("account", currentuser.AccountId);
salesorder["contactid"] = new EntityReference("contact", currentuser.ContactId );
salesorder["emailaddress"] = currentuser.Email;
salesorder["name"] = "DealerPO123";
salesorder["salesorderdetail"] = detail;
}
_crmContext.ServiceContext.AddObject(salesorder);
_crmContext.ServiceContext.SaveChanges();
}
Sample: Set negative prices in opportunities, quotes, and sales orders.
// Create the sales order.
SalesOrder order = new SalesOrder()
{
Name = "Faux Order",
DateFulfilled = new DateTime(2010, 8, 1),
PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName,
_priceListId),
CustomerId = new EntityReference(Account.EntityLogicalName,
_accountId),
FreightAmount = new Money(20.0M)
};
_orderId = _serviceProxy.Create(order);
order.Id = _orderId;
// Add the product to the order with the price overriden with a
// negative value.
SalesOrderDetail orderDetail = new SalesOrderDetail()
{
ProductId = new EntityReference(Product.EntityLogicalName,
_product1Id),
Quantity = 4,
SalesOrderId = order.ToEntityReference(),
IsPriceOverridden = true,
PricePerUnit = new Money(-40.0M),
UoMId = new EntityReference(UoM.EntityLogicalName,
_defaultUnitId)
};
_orderDetailId = _serviceProxy.Create(orderDetail);
Here's my code :
public partial class ActivityService
{
public SearchActivityOutput GetActivityFromDbByName(SearchActivityInput input)
{
using (var conn = DbService.GetInstance().GetOpenConnection())
{
var savedActivities = GetSearchResultByNameQuery.GetInstance()
.Execute(conn, new { Name = input.Name });
var activityList = savedActivities.Select(a => new ActivityDetail()
{
Name = a.Name,
City = a.City,
Country = a.Country,
Description = a.Description,
OperationTime = a.OperationTime,
Price = a.Price
}).ToList();
var output = new SearchActivityOutput
{
ActivityList = activityList
};
return output;
}
}
}
How can i create unit test from that class?
my sample unit test for that class:
[TestMethod()]
public void GetActivityFromDbByNameTest()
{
Initializer.Init();
var input = new SearchActivityInput { Name = "Marjan" };
var ActList1 = new ActivityDetail()
{ Name = "Marjan", City = "Bandung", Country = "Indonesia", Description = "coba", OperationTime = "24 Jam", Price = 2000};
var ActList2 = new ActivityDetail()
{ Name = "Marjan", City = "Bandung", Country = "Indonesia", Description = "coba", OperationTime = "24 Jam", Price = 3500 };
var ActList3 = new ActivityDetail()
{ Name = "Marjan aja", City = "Jakarta", Country = "Indonesia", Description = "apapun", OperationTime = "2 Hari", Price = 4500 };
var ActList4 = new ActivityDetail()
{ Name = "Marjan", City = "Stockholm", Country = "Swedia", Description = "123coba", OperationTime = "3 Jam", Price = 3500 };
var ActList5 = new ActivityDetail()
{ Name = "Marjan", City = "Stockholm", Country = "Swedia", Description = "123coba", OperationTime = "3 Jam", Price = 4500 };
var ActList6 = new ActivityDetail()
{ Name = "Marjan aja", City = "Jakarta", Country = "Indonesia", Description = "apapun", OperationTime = "2 Hari", Price = 2000 };
var ActList7 = new ActivityDetail()
{ Name = "Marjan", City = "Stockholm", Country = "Swedia", Description = "123coba", OperationTime = "3 Jam", Price = 3500 };
var ActList8 = new ActivityDetail()
{ Name = "Marjan", City = "Stockholm", Country = "Swedia", Description = "123coba", OperationTime = "3 Jam", Price = 2000 };
var ActList9 = new ActivityDetail()
{ Name = "Marjan", City = "Stockholm", Country = "Swedia", Description = "123coba", OperationTime = "3 Jam", Price = 2000 };
var ActList = new List<ActivityDetail>();
ActList.Add(ActList1);
ActList.Add(ActList2);
ActList.Add(ActList3);
ActList.Add(ActList4);
ActList.Add(ActList5);
ActList.Add(ActList6);
ActList.Add(ActList7);
ActList.Add(ActList8);
ActList.Add(ActList9);
var expectedResult = new SearchActivityOutput
{
ActivityList = ActList
};
using (var conn = DbService.GetInstance().GetOpenConnection())
{
var actualResult = ActivityService.GetInstance().GetActivityFromDbByName(input);
Assert.AreEqual(expectedResult, actualResult);
}
}
but, when i run the unit test, there give some error message :
Test Name: GetActivityFromDbByNameTest Test
Result StackTrace: at
xxxx.ActivityServiceTests.GetActivityFromDbByNameTest()
in
70 Result Message: Assert.AreEqual failed.
Expected:(xxx.yyy.zzz.Model.SearchActivityOutput).
Actual:(xxx.yyy.zzz.Model.SearchActivityOutput).
You should not use the database while your unittesting.
Wikipedia says: A common example of this is classes that depend on a database: in order to test the class, the tester often writes code that interacts with the database. This is a mistake, because a unit test should usually not go outside of its own class boundary, and especially should not cross such process/network boundaries because this can introduce unacceptable performance problems to the unit test-suite.
Use testdata or a dummy class that represent your Database.
https://softwareengineering.stackexchange.com/questions/119367/should-service-test-classes-connect-to-the-database
https://softwareengineering.stackexchange.com/questions/138238/unit-testing-database-coupled-app/138257#138257
You cannot unit test a class that performs any I/O-related tasks. Even if your tests seem to run fine on your development machine, they will likely fail on your colleague's machine or CI server.
In order for your piece of code to be testable, it should be a either a pure function, or it should be reducible to a pure function using some abstraction techniques like IoC / higher order functions / etc.
Learn to write testable code first. This article will give you some advise - https://www.toptal.com/resume/sergey-kolodiy (I'm the author of it).
I completely agree with the other statements about not using the database in your unit tests, but the answer to the failure that you're currently receiving is that you should be using methods of the CollectionAssert class to compare the contents of two collections instead of the Assert class that you're using. If you just want to ensure that the returned List contains the same elements regardless of ordering, you can use
CollectionAssert.AreEquivalent(expectedResult, actualResult);
If sequencing order is important, you should use
CollectionAssert.AreEqual(expectedResult, actualResult);
I am trying to send data to this web service.
With the following code I have how can I adjust what I have to send the CorrelationId in C#?
www.SyncroWebService ws = new www.SyncroWebService();
ws.addNewProduct(new www.AddProductRequest(){
Products = new www.Product[]
{
new www.Product() { categoryName = "Cat_Rory", departmentName = "Dept_Rory", productName = "Product_Rory", productPrice = 100, productQty = 1000},
new www.Product() { categoryName = "Cat_Test", departmentName = "Dept_Test", productName = "Product_Test", productPrice = 100, productQty = 1000 }
}
});
Thanks
Use:
ws.addNewProduct(new www.AddProductRequest {
CorrelationId = "id here",
Products = ...