SDK Programming Guide
  • 4.1.1 Sample merchant app using normal payment sheet
  • The normal payment sheet provides billing/shipping address and purchase amount information. The screen shots that follow illustrate this type of payment sheet as displayed on a merchant app’s screen.
  • The sample code below showcases how a merchant app can use the Samsung Pay SDK to:
    • Construct the SamsungPay class for checking the status of Samsung Pay
    • Check the registered card information in Samsung Pay (optional)
    • Request payment with Samsung Pay
    • Add the Samsung Pay button in accordance with Samsung branding guidelines.
  • public class NormalSheetFragment extends Fragment implements View.OnClickListener {
    
    // ......
        private ImageView samsungPayButton;
    // ......
        private void initView() {
    // ......
        samsungPayButton = (ImageView) fragmentView.findViewById(R.id.samsungpaybutton);
    
        // SDK Method Test Buttons Listeners
        // ......
        samsungPayButton.setOnClickListener(this);
    
        // SDK Method Test Buttons
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                //......
                case R.id.samsungpaybutton:
                    samsungPayButton.setVisibility(View.GONE);
                    startInAppPay();
                      break;
                //......
            }
        }
    
        private void checkSamsungPayStatus() {
            Bundle bundle = new Bundle();
            bundle.putString(SamsungPay.PARTNER_SERVICE_TYPE,
    SamsungPay.ServiceType.INAPP_PAYMENT.toString());
            PartnerInfo partnerInfo = new PartnerInfo(serviceId, bundle);
            SamsungPay samsungPay = new SamsungPay(context, partnerInfo);
            try { 
                samsungPay.getSamsungPayStatus(new StatusListener() {
                    @Override
                    public void onSuccess(int status, Bundle bundle) {
                        switch (status) {
                            case SamsungPay.SPAY_NOT_SUPPORTED:
                                // Samsung Pay is not supported
                                samsungPayButton.setVisibility(View.INVISIBLE);
                                break;
                            case SamsungPay.SPAY_NOT_READY:
                                // Activate Samsung Pay or update Samsung Pay, if needed
                                samsungPayButton.setVisibility(View.INVISIBLE);
                                break;
                            case SamsungPay.SPAY_READY:
                                // Samsung Pay is ready
                                samsungPayButton.setVisibility(View.VISIBLE);
                                break;
                            default:
                                // Not expected result
                                samsungPayButton.setVisibility(View.INVISIBLE);
                                break;
                        }
                    }
    
                    @Override
                    public void onFail(int errorCode, Bundle bundle) {
                        samsungPayButton.setVisibility(View.INVISIBLE);
                        Log.d(TAG, "checkSamsungPayStatus onFail() : " + errorCode);
                    }
                });
    
                /*
                 * Thrown if the callback passed is null.
                 */
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
    
    //......
    
  • Configuring the Payment Sheet UI
  • Specify the cards supported
  • Your merchant app can specify which card brands it will accept.
  • ArrayList<PaymentManager.Brand> brandList = new ArrayList<>();
    // If the supported brand is not specified, all card brands in Samsung Pay are
    // listed in the Payment Sheet.
    brandList.add(PaymentManager.Brand.MASTERCARD);
    brandList.add(PaymentManager.Brand.VISA);
    brandList.add(PaymentManager.Brand.AMERICANEXPRESS);
    
  • Only the list of accepted card brands enrolled in Samsung Pay is then displayed. If supported brands are not specified, all card brands in Samsung Pay are listed in the payment sheet.

  • For instance, if the merchant supports only MasterCard and the user has enrolled a VISA card in Samsung Pay but not a MasterCard, the following screen is displayed.
  • Here, however, given the option shown at the bottom of the screen, the user can click and follow the onscreen instructions to add a card.
  • Address in Payment Sheet option
  • Each option presents a scenario for displaying shipping and billing addresses on the Payment Sheet.
  • PaymentInfo paymentInfo = new PaymentInfo.Builder()
    	// ......
    	// Merchant requires billing address from Samsung Pay and sends the shipping address to 
    	//Samsung Pay.
    	// Show both billing and shipping address on the payment sheet.
    	.setAddressInPaymentSheet(PaymentInfo.AddressInPaymentSheet.NEED_BILLING_SEND_SHIPPING)
    	// Option is either SEND_SHIPPING or NEED_BILLING_SEND_SHIPPING, shipping address should be set
    	// from merchant app
    	.setShippingAddress(shippingAddress)
    	// ......
    	.build();
    
  • PaymentInfo.AddressInPaymentSheet.DO_NOT_SHOW: No address is displayed on the payment sheet; typically reserved for digital items, such as music, software, and so forth.
  • PaymentInfo.AddressInPaymentSheet.NEED_BILLING_SPAY: Displays the billing address on file in Samsung Pay.
  • PaymentInfo.AddressInPaymentSheet.NEED_SHIPPING_SPAY: Displays only shipping address on file in Samsung Pay.
  • PaymentInfo.AddressInPaymentSheet.SEND_SHIPPING: Displays the shipping address sent by the merchant app only.
  • PaymentInfo.AddressInPaymentSheet.NEED_BILLING_SEND_SHIPPING: Displays billing address from Samsung Pay and shipping address sent by this merchant.
  • PaymentInfo.AddressInPaymentSheet.NEED_BILLING_AND_SHIPPING: Displays both shipping address and billing address on the Payment Sheet from Samsung Pay.
  • Address error handling
  • Users are alerted to address errors according to the respective error code as follows:
  • ERROR_SHIPPING_ADDRESS_INVALID: Merchant requests the shipping address from Samsung Pay but the address received is invalid.
  • ERROR_SHIPPING_ADDRESS_UNABLE_TO_SHIP: Merchant requests the shipping address from Samsung Pay but the address received is out of delivery range.
  • ERROR_SHIPPING_ADDRESS_NOT_EXIST: Merchant requests the shipping address from Samsung Pay. The received address does not exist.