public async Task LogTransaction_Order_LoggedProperly() { using var c = CreateContext(); var contactId = await c.OntraObjects.GetObjectIdByEmailAsync(ApiObjectType.Contact, "*****@*****.**"); var offer = new ApiTransactionOffer() .AddProduct(1, 2, 100); var result = await c.Ontra.LogTransactionAsync(contactId.Value, offer); Assert.NotEqual(0, result); }
public async Task LogTransaction_Order_LoggedProperly() { var api = SetupApi(); var apiObj = SetupObjectsApi(); var contactId = await apiObj.GetObjectIdByEmailAsync(ApiObjectType.Contact, "*****@*****.**"); var offer = new ApiTransactionOffer() .AddProduct(1, 2, 100); var result = await api.LogTransactionAsync(contactId.Value, offer); Assert.NotEqual(0, result); }
/// <summary> /// Far less data is needed to simply log a transaction than to manually process one. The gateway, payer, and billing details are unnecessary /// in this case. The mandatory information in this case include a contact ID, the "chargeLog" designation, and product and pricing details. /// </summary> /// <param name="contactId">The ID of the contact for whom a transaction should be created.</param> /// <param name="offer">The product and pricing offer for the transaction.</param> /// <param name="externalOrderId">Optional external order id that you can save within the generated transaction.</param> /// <param name="transactionDate">The date and time of the transaction.</param> /// <param name="invoiceTemplate">The ID of the invoice template to use for this transaction. The default invoice ID is 1.</param> /// <returns>The invoice ID.</returns> public async Task <int> LogTransactionAsync(int contactId, ApiTransactionOffer offer, string?externalOrderId = null, DateTimeOffset?transactionDate = null, int invoiceTemplate = 1) { var query = new Dictionary <string, object?> { { "contact_id", contactId }, { "chargeNow", "chargeLog" }, { "invoice_template", invoiceTemplate }, { "offer", offer } } .AddIfHasValue("external_order_id", externalOrderId) .AddIfHasValue("trans_date", new JsonConverterDateTime(true).Format(transactionDate)); var json = await ApiRequest.PostAsync <JObject>( "transaction/processManual", query).ConfigureAwait(false); return(JsonData(json)["invoice_id"]?.Value <int>() ?? 0); }
/// <summary> /// Far less data is needed to simply log a transaction than to manually process one. The gateway, payer, and billing details are unnecessary /// in this case. The mandatory information in this case include a contact ID, the "chargeLog" designation, and product and pricing details. /// </summary> /// <param name="contactId">The ID of the contact for whom a transaction should be created.</param> /// <param name="offer">The product and pricing offer for the transaction.</param> /// <param name="externalOrderId">Optional external order id that you can save within the generated transaction.</param> /// <param name="transactionDate">The date and time of the transaction.</param> /// <param name="invoiceTemplate">The ID of the invoice template to use for this transaction. The default invoice ID is 1.</param> /// <returns>The invoice ID.</returns> public async Task <int> LogTransactionAsync(int contactId, ApiTransactionOffer offer, string?externalOrderId = null, DateTimeOffset?transactionDate = null, int invoiceTemplate = 1, CancellationToken cancellationToken = default) { offer.CheckNotNull(nameof(offer)); var query = new Dictionary <string, object?> { { "contact_id", contactId }, { "chargeNow", "chargeLog" }, { "invoice_template", invoiceTemplate }, { "offer", offer } } .AddIfHasValue("external_order_id", externalOrderId) .AddIfHasValue("trans_date", new JsonConverterDateTime(true).Format(transactionDate)); var json = await ApiRequest.PostJsonAsync( "transaction/processManual", query, cancellationToken).ConfigureAwait(false); return(await json.RunStructAndCatchAsync(x => json.JsonData().JsonChild("invoice_id").GetInt32()).ConfigureAwait(false)); }
/// <summary> /// Processes a transaction for a contact. Please note that this request requires valid parameters for all associated members of the transaction or the request will fail. /// </summary> /// <param name="contactId">The ID of the contact for whom a transaction should be created.</param> /// <param name="gatewayId">The ID of the gateway to use for this transaction. Note that this is the ID of the gateway object itself and not the external_id of the gateway.</param> /// <param name="offer">The product and pricing offer for the transaction.</param> /// <param name="billingAddress">The complete billing address information for this transaction. Only required if not already on file for this contact.</param> /// <param name="payer">The credit card information for this transaction. Only required if not already on file for this contact.</param> /// <param name="creditCardId">The existing credit card to use for this transaction, when not specifying payer. Leave both payer and creditCardId null to use the default care on file.</param> /// <param name="externalOrderId">Optional external order id that you can save within the generated transaction.</param> /// <param name="transactionDate">The date and time of the transaction.</param> /// <param name="invoiceTemplate">The ID of the invoice template to use for this transaction. The default invoice ID is 1.</param> /// <returns>The transaction result.</returns> public async Task <ApiTransactionResult> ProcessManualAsync(int contactId, int gatewayId, ApiTransactionOffer offer, ApiTransactionAddress?billingAddress = null, ApiTransactionPayer?payer = null, int?creditCardId = null, string?externalOrderId = null, DateTimeOffset?transactionDate = null, int invoiceTemplate = 1) { var query = new Dictionary <string, object?> { { "contact_id", contactId }, { "chargeNow", "chargeNow" }, { "invoice_template", invoiceTemplate }, { "gateway_id", gatewayId }, { "offer", offer } } .AddIfHasValue("external_order_id", externalOrderId) .AddIfHasValue("trans_date", new JsonConverterDateTime(true).Format(transactionDate)) .AddIfHasValue("billing_address", billingAddress) .AddIfHasValue("payer", payer) .AddIfHasValue("cc_id", creditCardId); return(await ApiRequest.PostAsync <ApiTransactionResult>( "transaction/processManual", query).ConfigureAwait(false)); }