Magento: Getting the transaction ID via soap - c#

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;
}
}
}

Related

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.

XERO API, Update payment amount

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

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;

Batch update using PUT - wcf data services / odata

I have a java odata service which uses PUT to update data. Client is in dotnet.
I have an object (order) which has an attribute "list object" (order details).
Is it possible to send Order object in one short with order details list using below command
Order orderObj = new Order
OrderDetail oDetailObj = new OrderDetail
context.AttachTo(Orders, orderObj);
Code to set properties of orderObj
for loop to add orders details
{
Code to set properties of oDetailObj
context.AddRelatedObject(orderObj, "OrderDetailsList", oDetailObj);
}
DataServiceResponse response = context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
While running this code, only last order detail infomration is submitting to server. I have verified that using fidller
if you have any alternative please suggest.

CrmService.Update method does not work for certain attribute

This is my problem:
all I want to do is update a "contact" entity in Crm 4 using the webservice.
This is my code:
CrmService eatupCrmService = CrmInteraction.InitializeCrmService();
contact updatedDelegate = new contact();
CeatupCrmService.Key contactPrimaryKey = new CeatupCrmService.Key();
contactPrimaryKey.Value = delegateId;
updatedDelegate.contactid = contactPrimaryKey;
updatedDelegate.address2_postalcode = delegateDetails.ContactDetailsPhysicalAddressCode;
eatupCrmService.Update(updatedDelegate);
I use the InitializeCrmService() to also retrieve and it works.
When updating the address2_postalcode attribute, I get the following error:
"Server was unable to process request."
with the exception Detail\InnerText :
"0x80040216 An unexpected error occurred. Platform".
If I change the code to update another attribute, say I try to update the mobilephone attribute
instead of address2_postalcode it works without any exceptions thrown.
As soon as I try to update address2_postalcode then I get that error. The address2_postalcode data type in Crm is nvarchar, and the value it is being assigned (delegateDetails.ContactDetailsPhysicalAddressCode) is of c#'s string type.
Anyone have any idea why this could be happening?
This same error and situation happened to me because I did an SSIS dts to load contacts in CRM from a flat file, in unsopported way, and I forgot to fill the CustomerAddressBase table. After filling this table "correctly" (two rows for each contact) the attributes of the View CustomerAddress(address1_addressid and address2_addressid) became not null. If you don't know how to fill this table (CustomerAddressBase) just create one new contact directly with address fields filled in CRM and then go to SQL Server management studio and by query you can see and know how the fields are filled.
Hope it helps somebody,
Alex
After many attempts at trying to understand why this error was occurring, I finally succeeded.
When I started working on this project, the client instructed me to test using only a specific contact, because we were working directly on the production environment. (the client does not have a development environment yet)
After doing some database queries to compare this contact to others (updates were failing only for the test contact) I noticed that my contact's address2_addressid attribute was NULL.
I then went to CRM under Customization\Customize Entities and opened up the contact entity. Under attributes, I ordered by type and saw that the contact has 3 primarykey attributes: contactid, address1_addressid and address2_addressid.
The test contact's address1_addressid and address2_addressid fields were NULL and this caused the CRM web service to throw the 0x80040216 An unexpected error occurred. Platform error upon me trying to update any of the address fields.
I don't know why this contact had those IDs set to NULL, I asked and the person that created the contact had no explanation of how this could have happened. I guess this will remain a mystery, but at least I now have an answer to the error I was getting and I can cater for this in my code.
I don´t know ho it can work...
I think you have to do CrmService.Create(contact) and then with the returned Guid you can perform updates...
Update is not going to work since the record with the Id you are setting on your contact entity doesn´t exist in the db...
contact updatedDelegate = new contact();
CeatupCrmService.Key contactPrimaryKey = new CeatupCrmService.Key();
You could do something like:
crmService eatupCrmService = CrmInteraction.InitializeCrmService();
contact updatedDelegate = new contact();
updatedDelegate.address2_postalcode = delegateDetails.ContactDetailsPhysicalAddressCode;
Guid cId = eatupCrmService.Create(updatedDelegate);
updatedDelegate.contactid = new Key(cId);
//set more fields if you want
eatupCrmService.Update(updatedDelegate);//update record
Wish I have helped you.

Categories