Incorporate online payment in a shiny application


#1

Is there any way to incorporate online payment in a shiny application? I mean after hitting the ‘action button’, users are directed to the payment page and after the payment is successful they will see the results. Should it be done through coding in inside the shiny app?


#2

No experience with that, but it should be possible to incorporate payments. You want to use a payment gateway? This article might be a good start to read.

Here's a very simple paypal integration, based on the article

library(shiny)
ui <- fluidPage(tags$script(src = "https://www.paypalobjects.com/api/checkout.js"),
                tags$script("paypal.Button.render({
                            // Configure environment
                            env: 'sandbox',
                            client: {
                            sandbox: 'demo_sandbox_client_id',
                            production: 'demo_production_client_id'
                            },
                            // Customize button (optional)
                            locale: 'en_US',
                            style: {
                            size: 'small',
                            color: 'gold',
                            shape: 'pill',
                            },
                            // Set up a payment
                            payment: function (data, actions) {
                            return actions.payment.create({
                            transactions: [{
                            amount: {
                            total: '0.01',
                            currency: 'USD'
                            }
                            }]
                            });
                            },
                            // Execute the payment
                            onAuthorize: function (data, actions) {
                            return actions.payment.execute()
                            .then(function () {
                            // Show a confirmation message to the buyer
                            window.alert('Thank you for your purchase!');
                            });
                            }
                            }, '#paypal-button');"),
                tags$div(id = "paypal-button"))
server <- function(input, output) {}
shinyApp(ui, server)

#3

Thank you so much for your answer.
I’ve added the following codes to my app. It worked, and PayPal button showed up on the action button inside the app. Likewise, I wanted to connect this app to the bank account of my home country. I asked the bank for the payment processing web APIs and they replied that for this language (Rshiny), I myself should write custom codes to process payments using their documents on https://github.com/ZarinPal-Lab/Android-sample-code and https://github.com/ZarinPal-Lab/zarinpal-ios-payment . I worked on them for several days but unfortunately did not find how to change these codes in order to be able to connect my app to their payment processing. Would you please let me know if it is possible to do the same thing (as I have done for PayPal) for this new payment method using the documents as they directed?

actionButton("Calculate", label = ui <- fluidPage(tags$script(src = "https://www.paypalobjects.com/api/checkout.js"),
tags$script("paypal.Button.render({
// Configure environment
env: 'sandbox',
client: {
sandbox: 'demo_sandbox_client_id',
production: 'demo_production_client_id'
},
// Customize button (optional)
locale: 'en_US',
style: {
size: 'small',
color: 'gold',
shape: 'pill',
},
// Set up a payment
payment: function (data, actions) {
return actions.payment.create({
transactions: [{
amount: {
total: '0.01',
currency: 'USD'
}
}]
});
},
// Execute the payment
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
// Show a confirmation message to the buyer
window.alert('Thank you for your purchase!');
});
}
}, '#Calculate');"),
tags$div(id = "Calculate")))


#4

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.