예제 #1
0
        static void Main(string[] args)
        {
            /* CHARGES */
            CreateCharge.Execute();
            //CreateChargeHistory.Execute();
            //DetailCharge.Execute();
            //ResendBillet.Execute();
            //UpdateBillet.Execute();
            //UpdateCarnetMetadata.Execute();
            //CancelCharge.Execute();
            //SettleCharge.Execute();

            //CreateBilletPayment.Execute();
            //CreateCardPayment.Execute();

            /* SUBSCRIPTIONS */
            //CreatePlan.Execute();
            //GetPlans.Execute();
            //DeletePlan.Execute();
            //CreateSubscription.Execute();
            //CreateSubscriptionPayment.Execute();
            //DetailSubscription.Execute();
            //UpdateSubscriptionMetadata.Execute();
            //CancelSubscription.Execute();

            /* CARNETS */
            //CreateCarnet.Execute();
            //CreateCarnetHistory.Execute();
            //DetailCarnet.Execute();
            //ResendCarnet.Execute();
            //ResendParcel.Execute();
            //SettleCarnetParcel.Execute();

            //UpdateCarnetMetadata.Execute();
            //UpdateParcel.Execute();

            /* NOTIFICATIONS */
            //GetNotification.Execute();

            /* OTHER */
            //GetInstallments.Execute();

            //AllInOne.Execute();
        }
        public async Task create_a_charge()
        {
            //Something that identifies
            //the customer on your system with
            //the payment the customer is about to make.
            var customerId = Guid.NewGuid();

            var charge = new CreateCharge
            {
                Name        = "Candy Bar",
                Description = "Sweet Tasting Chocolate",
                PricingType = PricingType.FixedPrice,
                LocalPrice  = new Money {
                    Amount = 1.00m, Currency = "USD"
                },
                Metadata =
                {
                    { "customerId", customerId }
                },
            };

            var response = await commerceApi.CreateChargeAsync(charge);

            response.Dump();
            response.HasError().Should().Be(false);
            response.HasWarnings().Should().Be(false);
            response.Data.Should().NotBeNull();
            response.Data.HostedUrl.Should().StartWith("https://commerce.coinbase.com/charges/");

            //Redirect the user to the checkout URL:
            if (response.HasError())
            {
                //The server says something is wrong
                //log and report back to the user an
                //error has occurred.
                Console.WriteLine(response.Error.Message);
                return;
            }
            //else, the carge creation was successful,
            //send the user to the hosted checkout page
            //at coinbase.
            //Server.Redirect(response.Data.HostedUrl);
            Console.WriteLine(response.Data.HostedUrl);
        }
예제 #3
0
        public IApiResult Create(CreateCharge operation)
        {
            var result = operation.ExecuteAsync().Result;

            if (result is ValidationsOutput)
            {
                return(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                });
            }
            else
            {
                return(new ApiResult <object>()
                {
                    Status = ApiResult <object> .ApiStatus.Success
                });
            }
        }
예제 #4
0
        public async Task can_create_a_charge()
        {
            var metadata = @"{
       ""customer_id"": ""id_1005"",
      ""customer_name"": ""Satoshi Nakamoto""
}";

            SetupServerSingleResponse(ChargeData.ChargeWithMetadata(metadata));


            var newCharge = new CreateCharge
            {
                Name        = "The Sovereign Individual",
                Description = "Mastering the Transition to the Information Age",
                LocalPrice  = new Money {
                    Amount = 100.00m, Currency = "USD"
                },
                PricingType = PricingType.FixedPrice,
                Metadata    = new JObject
                {
                    { "customer_id", "id_1005" },
                    { "customer_name", "Satoshi Nakamoto" }
                }
            };

            var charge = await api.CreateChargeAsync(newCharge);


            var truth = new Response <Charge>
            {
                Data = ChargeData.ChargeModel
            };

            truth.Data.Metadata = newCharge.Metadata;


            charge.Should().BeEquivalentTo(truth);

            server.ShouldHaveCalled("https://api.commerce.coinbase.com/charges")
            .WithVerb(HttpMethod.Post);
        }
예제 #5
0
 /// <summary>
 /// To get paid in cryptocurrency, you need to create a charge object
 /// and provide the user with a cryptocurrency address to
 /// which they must send cryptocurrency. Once a charge is
 /// created a customer must broadcast a payment to the
 /// blockchain before the charge expires.
 /// </summary>
 /// <param name="charge">The <seealso cref="CreateCharge"/> object.</param>
 public virtual Task <Response <Charge> > CreateChargeAsync(CreateCharge charge, CancellationToken cancellationToken = default)
 {
     return(ChargesEndpoint
            .PostJsonAsync(charge, cancellationToken)
            .ReceiveJson <Response <Charge> >());
 }