XERO API, Update payment amount - c#

I need to create note for an invoice on XERO using XERO API, however, it seems that this functionality is not yet available. So my next solution is to set the amount of a payment into $0.00. My problem is that xero api returns a validation error but no additional detail.
if (payment != null && payment.Status != PaymentStatus.Deleted)
{
api.Payments.Update(new Payment { Id = payment.Id, Amount = 0 });
}
It seems that only payment that you want to delete is being updated.
api.Payments.Update(new Payment { Id = payment.Id, Status = PaymentStatus.Deleted });
any suggestions or advise?

Payments in Xero can't be updated. You can only delete them and redo them.
This is true in both the web app and the API.
If you're trying to add a note I'd recommend adding a description--only line item to the invoice

Related

How do you attach a Payment Method to a Payment Intent using the Stripe API

I've read a lot of documentation on "why" my Stripe payment intents are left in a status of "The Customer has not entered a payment method" and that "We recommend that you explicitly provide the payment_method going forward" however I can't tell how do that (provide the payment_method).
When I initialise the Payment Intent object I have "AutomaticPaymentMethods" enabled. I only have 1 payment method enabled in my Stripe Dashboard (cards).
(Also, I'm using Blazor with JS interop for this - if that is relevant...)
string customerId = await getCustomer(); // fetch existing customer from Stripe API based on current user or create a new one
Stripe.PaymentMethodService pms = new PaymentMethodService();
Stripe.PaymentIntentCreateOptions options = new PaymentIntentCreateOptions
{
Amount = p.UnitAmount,
Currency = p.Currency,
Customer = customerId,
ReceiptEmail = "test#malinator.com",
Description = "Test Purchase",
StatementDescriptor = "Test Purchase",
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},
};
Stripe.PaymentIntentService pis = new Stripe.PaymentIntentService();
Stripe.PaymentIntent pi = pis.Create(options);
return pi;
The Payment Method is null on the resulting Payment Intent object.
It is still null after the payment details have been completed in the "payment-element" on my HTML form.
Is the payment_method something I can set up as the Payment Intent object is created (as I only wish to use "cards" at the moment anyway), or is it something I need to set in the confirm_payment JS call? (Either way, how to I obtain that Payment Method?)
Your code creates a PaymentIntent server-side for say $10 USD. This represents the "state machine" of an overall payment for the customer. They might never pay, or they might try to pay once and get a decline or a success, or they might get declined, try another card and see a success. Each "payment attempt" is represented in the API as a Charge object and the corresponding payment method details associated with that are represented as a PaymentMethod.
Now all of that "payment attempt" happens client-side where you collect payment method details and you use those to "confirm the PaymentIntent".
You mentioned you are using PaymentElement which is Stripe's newer UI library component to collect payment method details and accept a payment client-side. Since you only accept card payments, the PaymentElement would get initialized with your PaymentIntent's client_secret and render the card form to collect those card details.
What you need to do here is have a button to "pay" and when it's clicked, your Javascript code should call the confirmPayment() method from Stripe.js. Doing that will use the card details entered by the customer and attempt to confirm the PaymentIntent that is for a specific amount and currency. This payment might succeed, in which case the customer is redirected to your return_url, or it might be declined in which case the promise completes with error details you can handle to surface an error.
What you need to do here is look into your client-side code, ensure that you call confirmPayment() as expected and debug the response you get back to help narrow it down.
After the PaymentIntent is confirmed successfully and has status: 'succeeded' then it will have payment_method: 'pm_123' that is the id of the PaymentMethod object associated with the successful confirmation. All the information about that card would be on the successful Charge object associated with it inside payment_method_details.

Stripe / Stripe.net invoice.payment_succeeded does not include Subscription details

I am conducting a simple localhost test using stripe CLI.
When I execute the command:
stripe trigger invoice.payment_succeeded
My local webhook picks everything up perfectly and the test data they generate is sent to me. The only issue I have is when the code is deserialized:
if (stripeEvent.Type == "invoice.payment_succeeded")
{
Invoice successInvoice = (Invoice)stripeEvent.Data.Object;
...
The object stripeEvent (of type Invoice) does not have a subscription value for it, or a subscription id, for me to map back to what subscription the customer is under.
Sure, I can see the invoice amount, but I'd like to know more details now on this item.
I was reading something about how Stripe will send over a successful invoice charge but may not initially include subscription details on it, but that concerns me since I want to know the associated subscription.
Any ideas? Am I looking at the wrong webhook event?
Luckily I just figured it out - if you are testing using the CLI, you need to first create a subscription i.e.
stripe trigger customer.subscription.created
and then once you do this, if you then execute your payment
stripe trigger invoice.payment_succeeded
Doing it in this order will then ensure the ID comes in (but not the whole subscription object). but that's ok - you can fetch the whole subscription using the ID like so:
if (successInvoice.SubscriptionId != null)
{
var service = new SubscriptionService();
var subscription = service.Get(successInvoice.SubscriptionId);
if (subscription != null)
{
var plan = subscription.Plan; //do stuff with plan
}
}
The Invoice object definitely has a reference to the Subscription: https://stripe.com/docs/api/invoices/object?lang=dotnet#invoice_object-subscription
It's true that the webhook event that describes the Invoice won't contain many details on the Subscription, but you can then either retrieve the Subscription by using the aforementioned ID or retrieve the Invoice from the API whilst expanding the Subscription.

How to get with paypal C# sdk, the transactionid of a directpayment method

Im using the c# sdk to do a direct payment to paypal.
Everything works great, however im not getting the transactionId because the sdk's "Payment" object does not have a transactionId nor does the http response.
the code is very simple.
Payment pymnt = new Payment();
pymnt.intent = "sale";
pymnt.payer = payr;
pymnt.transactions = transactions;
Payment createdPayment = pymnt.Create(apiContext);
Pymnt Create method, creates and Executes the payment and retrieves back the properties by converting them from json.
I am getting back payid.I checked documentation but couldnt find any on how to get transactionId via payid.
Another part of my application that is created with paypal standard gets the paypal transaction id via the "txn_id" query parameter in the IPN method and saved it in the database.
Thus we need save the transactionid in the database to be consistent.
Please help.
(A similar question was asked on GitHub.)
The transaction ID for a payment can be found via the related_resources property of each transaction associated with a payment.
For example, if you make a sale payment, the transaction ID can be retrieved via the following:
var payment = Payment.Get(apiContext, "PAY-89W644977H834061FKTDRCCY");
var transactionId = payment.transactions[0].related_resources[0].sale.id;

How to check payment status with any PayPal sdk

I am currently working with PayPal's Merchant SDK and I am wondering how can I check a payment status? That's especially useful for pending payment or delayed. All I keep in database is the Payer ID.
I want a method to check the payment status so that I can proceed with the payment once is it approved, or canceled, using PayPal's Merchant SDK.
Here's an example:
GetExpressCheckoutDetailsRequestType req = new GetExpressCheckoutDetailsRequestType
{
Token = token
};
GetExpressCheckoutDetailsReq detailsReq = new GetExpressCheckoutDetailsReq
{
GetExpressCheckoutDetailsRequest = req
};
GetExpressCheckoutDetailsResponseType response = service.GetExpressCheckoutDetails(detailsReq);
However in this current example I do not have the token, which is a value returned when I first create the payment, and I am not sure if I will get the payment status.
What should I do to achieve what I want? Or do I need to proceed with another SDK, or the REST Api?
Try the getAck() method per this documentation
It will return an AckCodeType (which can be one of the values here). You'll want to proceed if that value is Success and potentially SuccessWithWarning.

Magento: Getting the transaction ID via soap

i recently tried to connect to a magento webshop via magentos SOAPv2 adapter.
Sharpdevelop did generate some c# wrappers getting the WSDL.
I could login and query orders, but when it comes to payment methods I was wondering why there's no way to get the transaction ID.
Here's what I tried:
salesOrderEntity ent = ms.salesOrderInfo(mlogin,"<my_order_id>");
The salesOrderEntity class contains a salesOrderPaymentEntity which should contain an attribute last_trans_id, but it doesn't.
Does anyone have an idea where to get the transaction ID from payment information? I didn't even find a reference to last_trans_id in the proxy code generated by sharpdevelop.
Thanks in advance for any suggestions.
-chris-
After some time i took up this question again and found a solution in my case.
A salesOrderEntity contains a list of salesOrderStatusHistoryEntity objects.
And those contain a field named 'comment' where in my case the Transaction IDs can by found in a textual way like
Transaction ID:"800736757864..."
This helped me.
Chris the OP has answered the question, but just to add some extra value to this Q&A here's the code I've got working.
As some background, the reason I am using Transaction IDs at all is because they are used by Paypal. I'm writing a cron job that pulls the Paypal orders from the Paypal API for the previous 24 hours, then we pull all orders from Magento via SOAP for the previous 24 hours, get the transaction IDs and match them to the Paypal list. It's to make sure there are no Paypal orders which are not on Magento, occasionally we get an IPN failure which prevents Magento quotes being converted to orders and the customer gets billed by Paypal but no product is shipped to them as the order is never created. If there's a mismatch an email alert is sent to customer services.
$startDate = gmdate('Y-m-d H:i:s', strtotime('-1 day', time()));
$complex_params =array(
array('key'=>'created_at','value'=>array('key' =>'from','value' => $startDate))
);
$result = $client_v2->salesOrderList($session_id, array('complex_filter' => $complex_params));
// We've got all the orders, now we need to run through them and get the transaction id from the order info
// We create an array just to hold the transaction Ids
$ikoTransactionIds = array();
foreach ($result as $invoice) {
$invoiceInfo = $client_v2->salesOrderInfo($session_id, $invoice->increment_id);
$history = $invoiceInfo->status_history;
$comments = $history[0]->comment;
// Only the Paypal based records have transaction Ids in the comments, orders placed via credit card do not. In these cases $comments are null
if ($comments) {
// Check if the text 'Transaction ID:' exists at all
if ((strpos($comments, "Transaction ID:")) !== FALSE) {
list($before, $transactionId) = explode('Transaction ID: ', $comments);
// Remove the trailing period
$transactionId = rtrim($transactionId ,".");
// Remove the quotes
$transactionId = str_replace('"', '', $transactionId);
// We add the id to our array of ids for this Magento install
$ikoTransactionIds[] = $transactionId;
}
}
}

Categories