botframeworkadaptive-cardspayment-request-api

Adaptive Cards: Payment Request


I am currently working on a bot project where i am trying to utilize Microsoft adaptive cards to try send a PaymentRequest to the user. I created a dummy paymentrequest object and inserted it into a Hero card like the documentation says.

var methodList = new List<PaymentMethodData>();
            var method = new PaymentMethodData()
                {Data = new {supportedNetworks = new[] { "visa", "mastercard", "amex", "discover", "diners", "jcb", "unionpay"} }, SupportedMethods = new[] { "https://bobpay.xyz/pay" } };
            methodList.Add(method);
            var details = new PaymentDetails {};

            var test = new PaymentRequest(null, methodList, details);



            var heroCard = new HeroCard
            {
                Title = "Bob",
                Subtitle = "The Builder",
                Text = "Kunnen wij het maken!",
                Images = new List<CardImage>
                {
                    new CardImage
                    {
                        Url = "https://m.media-amazon.com/images/M/MV5BNjRlYjgwMWMtNDFmMy00OWQ0LWFhMTMtNWE3MTU4ZjQ3MjgyXkEyXkFqcGdeQXVyNzU1NzE3NTg@._V1_CR0,45,480,270_AL_UX477_CR0,0,477,268_AL_.jpg"
                    }
                },
                Buttons = new List<CardAction>
                {
                    new CardAction
                    {
                        Title = "Buy",
                        Type = PaymentRequest.PaymentActionType,
                        Value = test,
                    }

                }
            };

            replyMessage.Attachments.Add(heroCard.ToAttachment());
            await context.PostAsync(replyMessage);

I took out a bunch of parameters from the PaymentRequest constructor because i was experimenting with trying to get some kind of feedback. With this i get back nothing but this url which crashed the browser when i try to run it.

"content": {
        "buttons": [
          {
            "title": "Buy",
            "type": "openUrl",
            "value": "payment://{\"methodData\":[{\"supportedMethods\":[\"https://bobpay.xyz/pay\"],\"data\":{}}],\"details\":{}}"
          }
        ],

I can't find any documentation on how to do this properly but it doesnt seem to say it is deprecated on the documention. I am using bot framework v3 if that helps. I feel like even without some parameters in the PaymentRequest it should still give me something when i click the button.


Solution

  • As stated in this documentation: bot-builder-dotnet-request-payment In order to use the Bot Builder Payments library, you must first:

    Create and activate a Stripe account if you don't have one already.

    Sign in to Seller Center with your Microsoft account.

    Within Seller Center, connect your account with Stripe.

    Within Seller Center, navigate to the Dashboard and copy the value of MerchantID.

    Update your bot's Web.config file to set MerchantId to the value that you copied from the Seller Center Dashboard.

    At this time, the Bot Framework SDK supports only Stripe payments directly. If you are using some other provider, you will need to add support for it manually.

    Also note: as of 2.25.2019, Bot Builder V4 sdk does not have payments support built in. The Bot Builder V3 sdk does: https://github.com/Microsoft/BotBuilder-Samples/tree/v3-sdk-samples/CSharp/sample-payments (Also, the Bot Framework Emulator V4 does not yet support payments: https://github.com/Microsoft/BotFramework-Emulator/issues/1324 The V3 emulator can be downloaded from here: https://github.com/Microsoft/BotFramework-Emulator/releases/tag/v3.5.37 )