sc_applepay 0.0.2 copy "sc_applepay: ^0.0.2" to clipboard
sc_applepay: ^0.0.2 copied to clipboard

SkipCash ApplePay Flutter Plugin

sc_applepay #

SkipCash ApplePay Flutter Plugin; The plugin facilitates SkipCash Apple Pay integration within your Flutter app.

Getting Started #

  1. Add sc_applepay to your pubspec.yaml file:
dependencies:
  sc_applepay: ^1.0.0

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sc_applepay/payment_response_class.dart';
import 'package:sc_applepay/sc_applepay.dart';

final _newPayment = ScApplepay(
    merchantIdentifier: "merchant.com.skipcash.appay", // Replace with your merchantIdentifier
    createPaymentLinkEndPoint: "https://paymentsimulation-4f296ff7747c.herokuapp.com/api/createPaymentLink/" /*
      you have to create end point in your backend server to accept the payment generated by this plugin, Which
      will contain the customer data (firstName, lastName, amount, phone, email), after that you should POST the data
      you receive from this plugin to https://api.skipcash.app/api/v1/payments. 
      Please refer to https://dev.skipcash.app/doc/api-integration/ for further explanation 
      and then return the json response you receive from https://api.skipcash.app/api/v1/payments to the plugin request
      to proceed with the payment. 
    */
);

StreamSubscription<dynamic>? _applePayResponseSubscription;

void _setupApplePayResponseListener() {
  _applePayResponseSubscription = _newPayment.applePayResponseStream.listen((response) {
    PaymentResponse paymentResponse = PaymentResponse.fromJson(response);
    // Handle payment response here...
    // you can get the payment details using the payment id after successful payment request.
    // send a GET request to SkipCash server /api/v1/payments/${paymentResponse.paymentId} and include your merchant
    // client id in the authorization header request to get the payment details.
    // for more details please refer to https://dev.skipcash.app/doc/api-integration/ 
  });
}

@override
void initState() {
  super.initState();
  _setupApplePayResponseListener();
}

@override
void dispose() {
  _applePayResponseSubscription?.cancel();
  super.dispose();
}

void _startPayment() async {
  bool hasCards;
  try {
    hasCards = await _newPayment.isWalletHasCards() ?? false;
    if (hasCards) {
      // Setup payment details
      // Set first name, last name, email, phone, amount, etc.
      _newPayment.setFirstName(_firstNameController.text); // mandatory
      _newPayment.setLastName(_lastNameController.text); // mandatory
      _newPayment.setEmail(_emailController.text); // mandatory
      _newPayment.setPhone(_phoneController.text); // mandatory
      _newPayment.setAmount(_amountController.text); // mandatory
      // Add payment summary items
      _newPayment.addPaymentSummaryItem("Tax", "0.0");
      _newPayment.addPaymentSummaryItem("Total", _amountController.text);
      // Start the payment process
      _newPayment.startPayment();
    } else {
      // If no cards found, prompt user to setup new card
      _newPayment.setupNewCard();
    }
  } on PlatformException {
    hasCards = false;
  }
}

1
likes
0
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

SkipCash ApplePay Flutter Plugin

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on sc_applepay

Packages that implement sc_applepay