コード例 #1
0
 private static void CloseMetangaClient(MetangaClient client)
 {
     try
       {
     client.Close();
       }
       catch (MetangaException e)
       {
     Console.WriteLine("An error has occurred while closing connection to Metanga: Id={0}, Message={1}", e.ErrorId, e.Message);
       }
 }
コード例 #2
0
        private static void EnrollmentExample(MetangaClient client)
        {
            var externalAccountId = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);
              var externalSubscriptionId = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);

              var account = CreateAccount(externalAccountId);
              var subscription = CreateSubscription(externalAccountId, externalSubscriptionId);
              var creditCardToken = CreateCreditCardInPaymentBroker(account);

              account.PaymentInstruments = new[] { new CreditCardMasked { InstrumentId = creditCardToken } }; // add the payment instrument id returned by payment broker to the account

              bool enrollmentSucceeded;
              Invoice invoice = null;
              try
              {
            invoice = client.Enroll(subscription, account, InvoiceAction.InvoiceNow);
            enrollmentSucceeded = true;
              }
              catch (MetangaException e)
              {
            Console.WriteLine("An error has occurred during enrollment: Id={0}, Message={1}", e.ErrorId, e.Message);
            enrollmentSucceeded = false;
              }

              if (!enrollmentSucceeded) return;

              Console.WriteLine("Account has been successfully enrolled. Account Id: {0}", externalAccountId);
              if (invoice != null)
              {
            Console.WriteLine("An invoice has been created for {0} {1}", invoice.InvoiceCurrency,
                          invoice.InvoiceSalesAmount + invoice.InvoiceTaxAmount);
            foreach (var charge in invoice.Charges)
            {
              if (!charge.Product.EntityId.HasValue)
            throw new InvalidOperationException("Product in Charge element has no EntityId"); // should not happen!
              var product = client.RetrieveEntity<Product>(charge.Product.EntityId.Value);
              Console.WriteLine("  - {0}: {1} {2}", product.Name["en-us"], invoice.InvoiceCurrency, charge.ChargeAmount);
            }
              }
        }