Samsung Pay SDK Flutter Plugin
3 2 samsung pay sdk flutter plugin 3 2 1 flutter plugin overview the samsung pay sdk flutter plugin allows developers to integrate select features of samsung wallet into flutter-based android apps running on samsung devices it acts as a bridge between the flutter environment and the native samsung pay sdk, enabling secure and seamless payments through samsung pay purpose the primary aim of this plugin is to bring samsung pay sdk functionality into the flutter ecosystem—making it easier for developers to integrate mobile wallet capabilities without deep native android coding supported operations the samsung pay sdk flutter plugin supports the following major operations in-app payment lets users pay for goods and services within a partner app using samsung wallet push provisioning enables users to add bank cards directly to samsung wallet from the issuer’s app by providing required card details what’s included in the plugin package to support seamless integration, the flutter plugin package typically includes samsung pay sdk flutter plugin dart interface, platform channel code, and native android sdk wrappers java/kotlin contains all classes, interfaces, and native libraries needed to communicate with samsung pay services api reference documentation detailed descriptions of each supported api method and parameters usage guidance for implementing features like getsamsungpaystatus , activatesamsungpay , and transaction callbacks sample merchant & issuer apps complete working examples of how to accept in-app payments push provision a card into samsung wallet handle callback responses and errors demonstrates full implementation using flutter ui and platform logic benefits of using the flutter plugin cross-platform development with native payment features faster time to market by avoiding full native sdk integration pre-built sample apps and apis to accelerate onboarding seamless integration with samsung’s trusted payment environment 3 2 2 samsung pay sdk flutter plugin architecture the following diagram illustrates the high-level architecture and core interactions between the samsung pay sdk flutter plugin and a partner app at this level, the plugin enables partner apps to leverage samsung pay for key operations such as push provisioning for issuers and in-app payments for merchants key components and roles partner app - a flutter-based app developed by a merchant or issuer it integrates samsung pay features to support in-app or online payments merchants push provisioning and management issuers samsung pay sdk flutter plugin - the plugin layer embedded in the partner app it enables direct communication between the flutter app and samsung pay services on the device by bridging native sdk apis samsung pay app - the native samsung pay samsung wallet application on the user’s device it securely handles payment authorization, tokenization, card management, and transaction ui financial network - the back-end payment ecosystem, including payment gateways pgs acquirers and issuers card associations e g , visa, mastercard these entities work together to process transactions initiated through samsung pay under merchant agreements 3 2 3 setting up flutter plugin environment establishing a stable and well-configured development environment is essential for the successful integration of the samsung pay sdk flutter plugin into your partner app the following prerequisites and recommendations will help ensure a smooth setup and implementation prerequisites & requirements platform compatibility ensure your app is targeting android devices that support samsung pay for detailed android system requirements, refer to the [samsung pay android sdk overview] service registration to use the plugin, merchants and issuers must first register a service through the samsung pay developer portal this includes obtaining a valid service id sid and service type required for integration refer to the [service registration guide] for step-by-step instructions download the flutter plugin obtain the official samsung pay sdk flutter plugin package, which includes plugin libraries and dependencies api documentation sample flutter apps for merchant and issuer use cases the plugin has the following directory structure folder contents docs api reference documentation libs samsungpaysdkflutter_v1 03 00 flutter plugin – contains the samsung pay apis to be used by your partner app samples sample apps 3 2 4 integrate samsung pay sdk flutter plugin be sure to do the following before attempting to use the plugin if not already part of your environment, download and install an ide android studio is recommended download the samsung pay sdk flutter plugin configure your ide to integrate the samsung pay sdk flutter plugin with your partner app go to pubspec yaml and enter the following dependency dependencies samsung_pay_sdk_flutter path plugin_directory_path\ [note] if your plugin path is c \users\username\downloads, the dependency will be like below dependencies samsung_pay_sdk_flutter path c \users\username\downloads\ for android proguard rules and dexguard, please check the android sdk overview 3 2 5 common flow once the setup is complete, you're ready to start integrating samsung pay features into your partner app using the samsung pay sdk flutter plugin the plugin provides apis for the following core functionalities supported operations via apis check samsung wallet status activate the samsung wallet app update the samsung wallet app checking samsung wallet status the first step is to create a samsungpaysdkflutter instance this instance checks whether samsung wallet is supported and ready to use on the user’s device based on the result, your app will determine whether to display the samsung pay button for both merchant payments and issuer push provisioning important the partner app must initialize partnerinfo, passing the serviceid and servicetype these are assigned in the samsung pay developers portal and are used for partner verification blocked list checking version control between the plugin and the samsung wallet app string serviceid; map<string,dynamic> data; static final samsungpaysdkflutterplugin = samsungpaysdkflutter partnerinfo serviceid 'partner_app_service_id', data {spaysdk partner_service_type servicetype app2app name tostring } ; after setting partnerinfo, your partner app can now call getsamsungpaystatus this method of the samsungpay class must be called before using any other feature in the samsung pay sdk flutter plugin future<void> getsamsungpaystatus statuslistener? statuslistener the result is delivered to statuslistener and provides onsucccess and onfail events check the android sdk common flow for more details the following sample code shows how to use the getsamsungpaystatus api method myhomepage samsungpaysdkflutterplugin getsamsungpaystatus statuslistener onsuccess status, bundle async { showstatus status, bundle ; }, onfail errorcode, bundle { showerror errorcode, bundle ; } ; activating the samsung wallet app the samsungpaysdkflutter class provides the following api method to activate the samsung wallet app on a device future<void> activatesamsungpay activatesamsungpay is called to activate the samsung wallet app on the same device on which the partner app is running first, the partner app must check the samsung wallet status with a getsamsungpaystatus call if the status is spay_not_ready and extra_error_reason is error_spay_setup_not_complete, the partner app needs to display an appropriate message to user, then call activatesamsungpay to launch the samsung wallet app so the user can sign in here’s an example of how to code this samsungpaysdkflutterplugin activatesamsungpay ; updating the samsung wallet app the samsungpaysdkflutter class provides the following api method to update the samsung wallet app on the device future<void> gotoupdatepage gotoupdatepage is called to update samsung wallet app on the same device on which the partner app is running as with all api calls, the partner app must first check the samsung wallet status with getsamsungpaystatus if this returns spay_not_ready and extra_error_reason is error_spay_app_need_to_update, then the partner app needs to display an appropriate message to the user and call gotoupdatepage , which launches the samsung wallet update page the following code sample reflects how to update samsung wallet samsungpaysdkflutterplugin gotoupdatepage ; 3 2 6 in-app online merchant applications can initiate secure in-app payments by interacting with the samsung pay sdk flutter plugin this process allows apps to display a custom payment sheet, retrieve card information, and handle payment requests smoothly within the app the following functionalities are ready to perform a variety of payment operations checking registered/enrolled card information before displaying the samsung pay button, a partner app can query card brand information for the user’s currently enrolled payment cards in samsung wallet to determine if payment is supported with the enrolled card to query the card brand, use the requestcardinfo api method of the samsungpaysdkflutter class the merchant app does not need to set a value for it now however, before calling this method, cardinfolistener must be registered so its listener can provide onresult and onfailure events the following snippet shows how to retrieve the list of supported card brands from samsung wallet samsungpaysdkflutterplugin requestcardinfo cardinfolistener {onresult paymentcardinfo showcardlist paymentcardinfo ; }, onfailure errorcode, bundle { showerror errorcode, bundle ; } ; creating a transaction request upon successful initialization of the samsungpaysdkflutter class, the merchant app needs to create a transaction request with payment information using the custom payment sheet to initiate a payment transaction with samsung wallet’s custom payment sheet, your merchant app must populate the following mandatory fields in customsheetpaymentinfo merchant name - as it will appear in samsung wallet’s payment sheet, as well as the user's card account statement customsheet - is called when the user changes card on the custom payment sheet in samsung wallet optionally, the following fields can be added to the payment information merchant id - can be used for the merchant’s own designated purpose at its discretion unless the merchant uses an indirect pg like stripe or braintree if an indirect pg is used, this field must be set to the merchant’s payment gateway id fetched from the samsung pay developers portal order number - usually created by the merchant app via interaction with a pg this number is required for refunds and chargebacks in the case of visa cards, the value is mandatory the allowed characters are [a-z][a-z][0-9,-] and the length of the value can be up to 36 characters address - the user’s billing and/or shipping address allowed card brands - specifies card brands accepted by the merchant if no brand is specified, all brands are accepted by default if at least one brand is specified, all other card brands not specified are set to "card not supported’ on the payment sheet here’s the 'customsheetpaymentinfo' structure string? merchantid; string merchantname; string? ordernumber; addressinpaymentsheet? addressinpaymentsheet; list<brand>? allowedcardbrand; paymentcardinfo? cardinfo; bool? iscardholdernamerequired; bool? isrecurring; string? merchantcountrycode; customsheet customsheet; map<string,dynamic>? extrapaymentinfo; your merchant app sends this customsheetpaymentinfo to samsung wallet via the applicable samsung pay sdk flutter plugin api methods upon successful user authentication in direct mode, samsung wallet returns the above "payment info" structure and a result string the result string is forwarded to the pg by your merchant app to complete the transaction it will vary based on the pg you’re using the following example demonstrates how to populate customsheet in the customsheetpaymentinfo class list<brand> brandlist = []; brandlist add brand visa ; brandlist add brand mastercard ; brandlist add brand americanexpress ; customsheetpaymentinfo customsheetpaymentinfo= customsheetpaymentinfo merchantname "merchantname", customsheet customsheet ; customsheetpaymentinfo setmerchantid "123456" ; customsheetpaymentinfo setmerchantname "sample merchant" ; customsheetpaymentinfo setaddressinpaymentsheet addressinpaymentsheet need_billing_send_shipping ; customsheetpaymentinfo setcardholdernameenabled true ; customsheetpaymentinfo setrecrringenabled false ; customsheetpaymentinfo setcustomsheet customsheet ; customsheetpaymentinfo allowedcardbrand = brandlist; return customsheetpaymentinfo; requesting payment with a custom payment sheet the startinapppaywithcustomsheet method of the samsungpaysdkflutter class is applied to request payment using a custom payment sheet in samsung wallet the two methods are defined as follows startinapppaywithcustomsheet - initiates the payment request with a custom payment sheet the payment sheet persists for 5 minutes after the api is called if the time limit expires, the transaction fails updatesheet - updates the custom payment sheet if any values on the sheet are changed as of api level 1 5, a merchant app can update the custom sheet with a custom error message refer to updating sheet with custom error message when you call the startinapppaywithcustomsheet method, a custom payment sheet is displayed on the merchant app screen from it, the user can select a registered card for payment and change the billing and shipping addresses, as necessary the result is delivered to customsheettransactioninfolistener, which provides the following events onsuccess - called when samsung wallet confirms payment it provides the customsheetpaymentinfo object and the paymentcredential json string customsheetpaymentinfo is used for the current transaction it contains amount, shippingaddress, merchantid, merchantname, ordernumber api methods exclusively available in the onsuccess callback comprise getpaymentcardlast4dpan – returns the last 4 digits of the user's digitized personal/primary identification number dpan getpaymentcardlast4fpan – returns the last 4 digits of the user's funding personal/primary identification number fpan getpaymentcardbrand – returns the brand of the card used for the transaction getpaymentcurrencycode – returns the iso currency code in which the transaction is valued getpaymentshippingaddress – returns the shipping/delivery address for the transaction getpaymentshippingmethod – returns the shipping method for the transaction for pgs using the direct model network tokens , the paymentcredential is a json object containing encrypted cryptogram which can be passed to the pg pgs using the indirect model gateway tokens like stripe, it is a json object containing reference card reference – a token id generated by the pg and status i e , authorized, pending, charged, or refunded refer to payment credential sample for details oncardinfoupdated - called when the user changes the payment card in this callback, updatesheet method must be called to update current payment sheet onfailure - called when the transaction fails, returns the error code and errordata bundle for the failure here’s how to call the startinapppaywithcustomsheet method of the samsungpaysdkflutter class class customsheettransactioninfolistener{ function paymentcardinfo paymentcardinfo, customsheet customsheet oncardinfoupdated; function customsheetpaymentinfo customsheetpaymentinfo, string paymentcredential, map<string, dynamic>? extrapaymentdata onsuccess; function string errorcode, map<string, dynamic> bundle onfail; customsheettransactioninfolistener {required this oncardinfoupdated, required this onsuccess, required this onfail} ; } void oncardinfoupdated cardinfo selectedcardinfo, customsheet customsheet { amountboxcontrol amountboxcontrol = customsheet getsheetcontrol amount_control_id as amountboxcontrol; amountboxcontrol updatevalue product_item_id, 1000 ; amountboxcontrol updatevalue product_tax_id, 50 ; amountboxcontrol updatevalue product_shipping_id, 10 ; amountboxcontrol updatevalue product_fuel_id, 0, "pending" ; amountboxcontrol setamounttotal 1060, amountconstants format_total_price_only ; customsheet updatecontrol amountboxcontrol ; } } void startinapppaywithcustomsheet customsheetpaymentinfo customsheetpaymentinfo,customsheettransactioninfolistener? customsheettransactioninfolistener { try{ methodchannelsamsungpaysdkflutter? startinapppaywithcustomsheet customsheetpaymentinfo, customsheettransactioninfolistener ; }on platformexception catch e { print e ; } } override fun onsuccess response customsheetpaymentinfo, paymentcredential string, extrapaymentdata bundle {} override fun onfailure errorcode int, errordata bundle? {} 3 2 7 push provisioning the app-to-app service, also known as push provisioning, allows issuer apps to seamlessly add payment cards to the samsung wallet on a user’s samsung device—directly from within the app—using the samsung pay sdk flutter plugin this integration enhances the user experience by eliminating the need to manually launch samsung wallet or scan physical cards requesting registered card list in the samsung wallet the getallcards method of the cardmanager class is used to request a list of all cards currently registered/enrolled in samsung wallet on the same device running the issuer’s app to succeed, the issuer app must pass valid partnerinfo to 'cardmanager' for caller verification 'cardfilter' narrows the card list returned by samsung wallet to the issuername specified please be noted that getsamsungpaystatus must be called before getallcards getallcards could not return a cards list when getsamsungpaystatus responds with a code other than spay_ready as of api level sdk version 1 4, cardfilter retrieves this information from the samsung pay developers portal certain issuers may need to register multiple issuer name s with the portal, depending on their app and/or the requirements of their token service provider tsp the getallcards parameter cardfilter matches the issuer name s specified with those registered in the portal only complete matches are returned this method is typically called when your partner app wants to check the card status it does not need to be called every time the partner app resumes therefore, you should create the card list with the 'oncreate ' method, rather than the 'onresume ' method the result of a getallcards call is delivered to getcardlistener, which provides the following events onsuccess - called when the operation succeeds; provides the list of all filtered cards and their status card information includes cardid, cardstatus, and extra cardinfo data onfail - called when the operation fails here’s an example of how to use the 'getallcards ' api method in your issuer app samsungpaysdkflutterplugin getallcards getcardlistener onsuccess list { showcardlist list ; }, onfail errorcode, bundle { showerror errorcode, bundle ; } ; getting wallet information the samsungpay class provides the getwalletinfo api method, which is called to request wallet information from the samsung wallet app prior to calling the addcard api, when you want to avoid duplicate provisioning your issuer app uses this information to uniquely identify the user and the samsung wallet app on a particular device wallet device management id, device id, and wallet user id void getwalletinfo statuslistener? statuslistener the following example demonstrates how to use it string serviceid; spaysdk partner_service_type servicetype app2app name tostring samsungpaysdkflutter partnerinfo serviceid "", data {} ; samsungpay=samsungpay context,partnerinfo val keys = arraylist<string> keys add samsungpay wallet_dm_id keys add samsungpay device_id keys add samsungpay wallet_user_id samsungpaysdkflutterplugin getwalletinfo statuslistener onsuccess status, bundle async { val deviceid string? = walletdata getstring samsungpay device_id val walletuserid string? = walletdata getstring samsungpay wallet_user_id }, onfail errorcode, bundle { util showerror context, errorcode, bundle ; } ; adding a card to samsung wallet your issuer app calls the addcard api method of cardmanager to add a card to samsung wallet by providing the required card details, your app can make it convenient and easy for users to add their bank-issued debit/credit cards to samsung wallet directly from your app without additional steps, like switching between apps for most issuers, getwalletinfo suffices for requesting current wallet information the response from samsung wallet tells the issuer app whether or not the user’s card has already been added to samsung wallet or is ineligible for provisioning it is therefore recommended that you call getwalletinfo before displaying the add to samsung pay button if the card is eligible, display the “add” button and, if the user taps it, call addcard the addcard result is delivered to addcardlistener, which provides the following events onsuccess - called when the operation succeeds; provides information and status regarding the added card onfail - called when the operation fails; returns the error code and extra bundle data such as extra_error_reason or extra_request_id if provided onprogress - called to indicate the current progress of the 'addcard ' operation; can be used to show a progress bar to the user in the issuer app this callback is supported for tsm solution issuers in china and spain here’s an example of how to use the addcard api method in your issuer app string cardtype = walletcard card_type_credit_debit; string tokenprovider = addcardinfo provider_abcd; string testpayload = "testpayloadcardinfoforflutterplugin"; map<string, dynamic> carddetail = {}; carddetail[addcardinfo extra_provision_payload] = testpayload; var addcardinfo = addcardinfo cardtype, tokenprovider,carddetail ; myapp samsungpaysdkflutterplugin addcard addcardinfo, addcardlistener onsuccess status, card { print "success $status / data $card" ; },onfail errorcode, bundle { util showerror context, errorcode, bundle ; print "error $errorcode / data $bundle" ; },on-progress currentcount, totalcount, bundle { print "currentcount $currentcount / totalcount $totalcount / data $bundle" ; } ; adding a co-badge card to samsung pay co-badge payment cards include two payment brands or networks when adding a co-badge card using push provisioning, you need to supply the card details for both networks one as the primary and the other as the secondary issuer app calls the addcobadgecard api method of cardmanager to add a co-badge card to samsung pay in most cases, calling getwalletinfo will suffice to request current wallet information the response from samsung pay indicates whether the user's co-badge card has already been added to samsung pay or is ineligible for provisioning therefore, it is advisable to call getwalletinfo before displaying the add to samsung pay button if the co-badge card is eligible, display the "add" button and, upon user tapping, call addcobadgecard important please remember to refer to the relevant issuer implementation guide s and specifications provided by each card network and ensure that your partner app and server adhere to their specific requirements the addcobadgecard result is delivered to addcardlistener, which provides the following events onsuccess - called when the operation succeeds; provides information and status regarding the added card onfail - called when the operation fails; returns the error code and extra bundle data such as extra_error_reason or extra_request_id if provided onprogress - called to indicate the current progress of the 'addcard ' operation; can be used to show a progress bar to the user in the issuer app this callback is supported for tsm solution issuers in china and spain here’s an example of how to use the addcobadgecard api method in your issuer app note samsung pay does not provide detailed payload information; generate the provisioning payload in accordance with your card networks specifications string cardtype = walletcard card_type_credit_debit; string primarytokenprovider = addcardinfo provider_abcd; //provide your primary card network payload string testprimarypayload = "thisistestprimarypayloadcardinfo1234567890"; string secondarytokenprovider = addcardinfo provider_efgh; //provide your secondary card network payload string testsecondarypayload = "thisistestsecondarypayloadcardinfo1234567890"; map<string, dynamic> primarycarddetails={}; primarycarddetails[addcardinfo extra_provision_payload] = testprimarypayload; map<string, dynamic> secondarycarddetails={}; secondarycarddetails[addcardinfo extra_provision_payload] = testsecondarypayload; var primaryaddcardinfo = addcardinfo cardtype, primarytokenprovider, primarycarddetails ; var secondaryaddcardinfo = addcardinfo cardtype, secondarytokenprovider, secondarycarddetails ; myapp samsungpaysdkflutterplugin addcobadgecard primaryaddcardinfo, secondaryaddcardinfo, addcardlistener onsuccess status, card { print "success $status / data $card" ; },onfail errorcode, bundle { print "error $errorcode / data $bundle" ; },on-progress currentcount, totalcount, bundle { print "currentcount $currentcount / totalcount $totalcount / data $bundle" ; } ; 3 2 8 sample apps sample applications sample apps with ux strategies are included here to aid you in understanding the sdk and implementing it in your application sample source code and apks can be downloaded from download section sample merchant app the sample merchant app shows you how to implement the payment sheet’s dynamic controls to leverage additional customer order and payment data and/or create a more custom ui look and feel the following payment sheet controls are available addresscontrol plaintextcontrol amountboxcontrol spinnercontrol controls are applied to suit a particular purpose or need check this android sdk sample merchant app for details sample issuer app the samsung pay sdk flutter plugin also provides a sample issuer app to showcase samsung pay sdk features for more information, refer to the javadoc samsung pay sdk api reference and sample code