I have code to Create a Vendor Payment for aVendor Bill like this :
InitializeRecord ir = new InitializeRecord();
ir.type = InitializeType.vendorPayment;
InitializeRef iref = new InitializeRef();
iref.typeSpecified = true;
iref.type = InitializeRefType.vendorBill;
iref.internalId = vendorBillId;
ir.reference = iref;
Login();
ReadResponse getInitResp = _service.initialize(ir);
if (getInitResp.status.isSuccess)
{
Record rec = getInitResp.record;
((VendorPayment)rec).total = (double)amount; //I don't want to pall all, just pay a half or just an amount less than the total
((VendorPayment)rec).totalSpecified = true;
WriteResponse writeRes = _service.add(rec);
return writeRes.status;
}
That can create a payment but the total is not apply, the payment is pay all amount of vendor bill's total.
I don't know what I'm missing here.
While applying payments to bill you cannot change the body level amount field. you got to change the amount line level field on apply line item record. I am not sure on syntax in Suitetalk, but, that should work.
Related
We have one product with 4 different prices(basic, middle etc). Let's say user bought basic package (payment session is created after payment completion subscription created),but after a while, user decided to change his package and upgrade to advanced package. In that case should i use update subscription ?
This actually updates from X$ to the Y$ package
var service = new SubscriptionService();
Subscription subscription = service.Get("sub_49ty4767H20z6a");
var items = new List<SubscriptionItemOptions> {
new SubscriptionItemOptions {
Id = subscription.Items.Data[0].Id,
Price = "price_CBb6IXqvTLXp3f",
},
};
var options = new SubscriptionUpdateOptions {
CancelAtPeriodEnd = false,
ProrationBehavior = "create_prorations",
Items = items,
};
subscription = service.Update("sub_49ty4767H20z6a", options);
or just cancel current subscription and create new one ? Why am i asking this, because i chatted with support guys from Stripe, and got two different answers. One of them told me that i need to use update_subscripton, the another one told that i need to attach new subscription. I am confused.
The way that you've described this here, the update to upgrade the subscription makes more sense to me. Pay careful attention to the intended proration behaviour (do you want to credit the time left on the current plan) and whether you want to shift the billing period.
I'd also point out that you should consider switching to separate Products. A Product is a single good/service that you sell, while Prices represent different billing intervals and currencies. If you imagine some service with Silver, Gold and Platinum access levels, each of those is a different product -- they get more features! The Product is what gets shown on the invoice, too. So unless you use separate Products, the invoices would be indistinguishable aside from the rate paid.
Most of the time doing what you've done doesn't present any specific obsdtacles, but the Customer Portal enforces one price per product per interval. If you had two annual prices for the "same product" but different amount, why would anybody pay the higher price? It's because they're paying for something different, a different product.
Quick Answer
Upgrade (From Basic to Pro)
Remove Basic
Add Pro
Prorate (Do not change billing cycle)
// subscriptionId -> your subscription id
// additionalStripePriceIds -> stripe price id you are going to add
// removalStripePriceIds -> stripe price id you are going to remove
var getService = new SubscriptionService();
var getServiceResult = await getService.GetAsync(subscriptionId);
var items = new List<SubscriptionItemOptions>();
if (removalStripePriceIds != null && removalStripePriceIds.Any())
{
foreach (var removalStripePriceId in removalStripePriceIds)
{
var item = getServiceResult.Items.Data.FirstOrDefault(i => i.Price.Id == removalStripePriceId);
if (item != null)
{
var subscriptionItemOption = new SubscriptionItemOptions
{
Id = item.Id,
Deleted = true,
};
items.Add(subscriptionItemOption);
}
}
}
foreach (var additionalStripePriceId in additionalStripePriceIds)
{
var subscriptionItemOption = new SubscriptionItemOptions
{
Price = additionalStripePriceId,
};
items.Add(subscriptionItemOption);
}
var updateService = new SubscriptionService();
var updateOptions = new SubscriptionUpdateOptions
{
CancelAtPeriodEnd = false,
ProrationBehavior = "create_prorations",
Items = items,
};
await updateService.UpdateAsync(subscriptionId, updateOptions);
I'm using Visual Studio to design a software that uses IBKR API to buy stocks. It's working fine if I'm buying integer stocks but I'm not able to buy fractional stocks.
I have found the function order.CashQty but it's not working.. this is the code that I'm using to buy, and it's working when I'm trying to buy integer stocks. Do you have any suggestion?
public void send_order(string side)
{
IBApi.Contract contract = new IBApi.Contract();
contract.Symbol = Global_variable.stock_sel;
contract.SecType = "STK";
contract.Exchange = cbMarket.Text;
contract.PrimaryExch = "ISLAND";
contract.Currency = "USD";
IBApi.Order order = new IBApi.Order();
order.OrderId = order_id;
order.Action = side;
order.OrderType = cbOrderType.Text;
//order.CashQty = 33.5; <-- maybe is this the way to buy fractionale share?
order.TotalQuantity = 1;
if (cbOrderType.Text == "STP")
{
order.AuxPrice = Convert.ToDouble(numPrice.Value);
}
order.DisplaySize = Convert.ToInt32(tbVisible.Text);
order.OutsideRth = chkOutside.Checked;
ibClient.ClientSocket.placeOrder(order_id, contract, order);
order_id++;
tbValid_Id.Text = Convert.ToString(order_id);
}
Thank you very much!
that code of my program, I hope that will help you:
private void buyStock(string symbol)
{
// Create a new contract to specify the security we are searching for
IBApi.Contract contract = new IBApi.Contract();
// Set the underlying stock symbol from the cbSymbol combobox
contract.Symbol = symbol.ToUpper();
// Set the Security type to STK for a Stock
contract.SecType = "STK";
// Use "SMART" as the general exchange
contract.Exchange = "SMART";
// Set the primary exchange (sometimes called Listing exchange)
// Use either NYSE or ISLAND
contract.PrimaryExch = "ISLAND";
// Set the currency to USD
contract.Currency = "USD";
IBApi.Order order = new IBApi.Order();
// gets the next order id from the text box
order.OrderId = order_id;
// gets the side of the order (BUY, or SELL)
order.Action = "BUY";
// gets order type from combobox market or limit order(MKT, or LMT)
order.OrderType = "MKT";
// number of shares from Quantity
order.TotalQuantity = 400;
// Value from limit price
//order.LmtPrice = Convert.ToDouble(numPrice.Text);
//
//Visible shares to the market
// order.DisplaySize = Convert.ToInt32(tbVisible.Text);
//order.OutsideRth = cbOutsideRTH.Checked;
//order.OutsideRth = chkOutside.Checked;
// Place the order
ibClient.ClientSocket.placeOrder(order_id, contract, order);
// increase the order id value
order_id++;
}
After I charge for specific subscribed customer on stripe object return with Invoice Id null,Do you know how can I fix It ?
or how can I create invoice for specific payment ?
I know how to create invoice using API but I didn't find way to create invoice for one time payment using API.
If stripe not support creating invoices for this type why they return Invoice Id including in charge object after charging.
That's my code to charge :
var myCharge = new ChargeCreateOptions();
myCharge.Amount = (Int32)(amount * 100);
myCharge.Currency = "usd";
myCharge.ReceiptEmail = "email#domain.com";
myCharge.Description = "Upgrade client";
myCharge.CustomerId = customer.SubscripedClientId;
myCharge.Capture = true;
var chargeService = new ChargeService(stripesecretkey);
Charge stripeCharge = chargeService.Create(myCharge);
after charge done stripecharge object include invoice id with null value
To create an invoice for a one-time payment, you need to first create line items through the api and then create the invoice. The invoice will collect any open line items and attach them to itself.
I'm using Intuit's .NET SDK for QBO, and am attempting to get a list of purchases from my qbo account. Here's my C# code...
var qboCashPurchaseQuery = new Intuit.Ipp.Data.Qbo.CashPurchaseQuery();
qboCashPurchaseQuery.PageNumber = 1;
qboCashPurchaseQuery.ResultsPerPage = 100;
var results = qboCashPurchaseQuery.ExecuteQuery<Intuit.Ipp.Data.Qbo.CashPurchase(context).ToList();
grdQuickBooksCustomers.DataSource = results;
I get a table with the number of records matching the number of purchases I expect, but the actual data returned is not what I need.
This is the columns and the first row of data I get back: (sorry for the formatting)
SyncToken Synchronized IdsType
0 Intuit.Ipp.Data.Qbo
This bit of code returns the same kind of weird data for some other functions such as InvoiceQuery. What am I doing wrong here to get this data? How might I actually return the detailed purchase data I need?
string q = "Select * from Purchase Where PaymentType='Cash' STARTPOSITION 1 MAXRESULTS 100";
dynamic Purchaselist = purchaseQueryService.ExecuteIdsQuery(q);
CashPurchase cashpurchase = new CashPurchase();
foreach (CashPurchase oCash in Purchaselist) {
//do something
}
var purchase = new Purchase();
var purchases = ds.FindAll(purchase, 0, 500);
That's how we query our datasets. You have to repeat the query if you've got more than 500 items.
I have an Invoice table and a ClientPayments table in my database. I have code that confirms a payment has occurred and registers it against a selected invoice (the user selects an invoice in the view). I am trying to get the status of the Invoice to change to "Confirmed" once the total payment amount equals the invoice amount. There can be many payments against once invoice and if the payment amount is less than the invoice amount, the status changes to "Partly Paid". This is my code from the controller below:
public ActionResult Confirm(int id, long InvoiceAmount, string PaymentType, float? InvoiceCustomAmount)
{
var invoice = db.Invoice.Find(id);
//now validate that if the logged in user is authorized to select and confirm this invoice or not.
ClientPayments clientPayment = db.ClientPayments.FirstOrDefault(cp => cp.InvoiceNumberID == id);
clientPayment = new ClientPayments();
clientPayment.InvoiceNumberID = id;
var TotalPayments = (clientPayment.PaymentAmount + InvoiceAmount);
if (InvoiceAmount == 115)
{
clientPayment.PaymentAmount = (long)InvoiceCustomAmount;
}
else
{
clientPayment.PaymentAmount = InvoiceAmount;
}
clientPayment.PaymentType = PaymentType;
clientPayment.PaymentDate = DateTime.Now;
db.ClientPayments.Add(clientPayment);
if (TotalPayments != invoice.InvoiceAmount)
{
invoice.InvoiceStatus = "Partly Paid";
}
else
{
invoice.InvoiceStatus = "Confirmed";
}
// You donĀ“t need this, since "invoice" was retrieved earlier in the method the database context
// knows that changes have been made to this object when you call "SaveChanges".
// db.Entry(invoices).State = EntityState.Modified;
db.SaveChanges();
return View();
}
The problem I am having is that TotalPayments doesn't give my total payment amount - it doesn't add up the entries that have already be added to the database.
Thanks
Looks like your loading the clientPayment here
ClientPayments clientPayment = db.ClientPayments.FirstOrDefault(cp => cp.InvoiceNumberID == id);
Now you've set the reference to a new ClientPayments, no longer loaded
clientPayment = new ClientPayments();
Here your setting the InvoiceNumberID, but nothing else
clientPayment.InvoiceNumberID = id;
Now your setting TotalPayments to the InvoiceAmount (clientPayment.PaymentAmount is 0 or null)
var TotalPayments = (clientPayment.PaymentAmount + InvoiceAmount);
You then set the clientPayment.PaymentAmount later, but after you've already set the TotalPayment.
Am I missing something?
EDIT:
I think your close. I don't think you want FirstOrDefault when you get your payments from the database. I think you want a sum.
So, if your just getting the sum of payments, use something like this:
var totalPaid = ClientPayments.Where(cp => cp.InvoiceNumberID == id).Sum(cp => cp.PaymentAmount);
Now, you have your total from the database.
Also, what is this? InvoiceAmount == 115? 115 is what's referred to as a Magic Number. It doesn't mean anything to anyone reading your code. Consider using a Constant or an Enumeration.
For example,
const int totalInvoiceAmount = 115;
Then your code would read,
if (InvoiceAmount == totalAmountOwed){...}
Then I think you can go ahead and create your new ClientPayment as you've done. Then set the values accordingly.
It looks like you need to get the amount the user is paying and add that to the total we got earlier. You can then check this amount against the balance owed to determine if the invoice stauts should be 'Confirmed' or 'Paid in Full'