|
| 1 | +using CyberSource.Api; |
| 2 | +using CyberSource.Client; |
| 3 | +using CyberSource.Model; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | + |
| 10 | +namespace Cybersource_rest_samples_dotnet.Samples.Payments |
| 11 | +{ |
| 12 | + public class ParallelAuth |
| 13 | + { |
| 14 | + public static async Task Run() |
| 15 | + { |
| 16 | + var task1 = Task.Run(() => AuthPayment()); |
| 17 | + var task2 = Task.Run(() => AuthPayment()); |
| 18 | + var task3 = Task.Run(() => AuthPayment()); |
| 19 | + var task4 = Task.Run(() => AuthPayment()); |
| 20 | + var task5 = Task.Run(() => AuthPayment()); |
| 21 | + var task6 = Task.Run(() => AuthPayment()); |
| 22 | + |
| 23 | + await task1; |
| 24 | + await task2; |
| 25 | + await task3; |
| 26 | + await task4; |
| 27 | + await task5; |
| 28 | + await task6; |
| 29 | + |
| 30 | + Console.WriteLine("COMPLETE"); |
| 31 | + } |
| 32 | + |
| 33 | + public static PtsV2PaymentsPost201Response AuthPayment() |
| 34 | + { |
| 35 | + string clientReferenceInformationCode = "TC50171_3"; |
| 36 | + Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation( |
| 37 | + Code: clientReferenceInformationCode |
| 38 | + ); |
| 39 | + |
| 40 | + bool processingInformationCapture = false; |
| 41 | + |
| 42 | + Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation( |
| 43 | + Capture: processingInformationCapture |
| 44 | + ); |
| 45 | + |
| 46 | + string paymentInformationCardNumber = "4111111111111111"; |
| 47 | + string paymentInformationCardExpirationMonth = "12"; |
| 48 | + string paymentInformationCardExpirationYear = "2031"; |
| 49 | + Ptsv2paymentsPaymentInformationCard paymentInformationCard = new Ptsv2paymentsPaymentInformationCard( |
| 50 | + Number: paymentInformationCardNumber, |
| 51 | + ExpirationMonth: paymentInformationCardExpirationMonth, |
| 52 | + ExpirationYear: paymentInformationCardExpirationYear |
| 53 | + ); |
| 54 | + |
| 55 | + Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation( |
| 56 | + Card: paymentInformationCard |
| 57 | + ); |
| 58 | + |
| 59 | + string orderInformationAmountDetailsTotalAmount = new Random().Next(100, 1000).ToString(); |
| 60 | + string orderInformationAmountDetailsCurrency = "USD"; |
| 61 | + Ptsv2paymentsOrderInformationAmountDetails orderInformationAmountDetails = new Ptsv2paymentsOrderInformationAmountDetails( |
| 62 | + TotalAmount: orderInformationAmountDetailsTotalAmount, |
| 63 | + Currency: orderInformationAmountDetailsCurrency |
| 64 | + ); |
| 65 | + |
| 66 | + Ptsv2paymentsOrderInformation orderInformation = new Ptsv2paymentsOrderInformation( |
| 67 | + AmountDetails: orderInformationAmountDetails |
| 68 | + ); |
| 69 | + |
| 70 | + var requestObj = new CreatePaymentRequest( |
| 71 | + ClientReferenceInformation: clientReferenceInformation, |
| 72 | + ProcessingInformation: processingInformation, |
| 73 | + PaymentInformation: paymentInformation, |
| 74 | + OrderInformation: orderInformation |
| 75 | + ); |
| 76 | + |
| 77 | + try |
| 78 | + { |
| 79 | + var configDictionary = new Configuration().GetConfiguration(); |
| 80 | + var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); |
| 81 | + |
| 82 | + var apiInstance = new PaymentsApi(clientConfig); |
| 83 | + PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj); |
| 84 | + Console.WriteLine(result); |
| 85 | + return result; |
| 86 | + } |
| 87 | + catch (ApiException err) |
| 88 | + { |
| 89 | + Console.WriteLine("Error Code: " + err.ErrorCode); |
| 90 | + Console.WriteLine("Error Message: " + err.Message); |
| 91 | + return null; |
| 92 | + } |
| 93 | + catch (Exception e) |
| 94 | + { |
| 95 | + Console.WriteLine("Exception on calling the API : " + e.Message); |
| 96 | + return null; |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments