MpesaSDK - Swift SDK for the M-Pesa API (Mozambique)

Overview

Platform iOS | macOS | watchOS | tvOS GitHub

M-Pesa SDK

Swift package for M-Pesa API (Mozambique)

Ready Methods/APIs

  • C2B
  • B2B
  • B2C
  • TRANSACTION STATUS
  • REVERSAL

Requisites

  • API Key
  • Public Key

These keys will be used to generate your access token.

PS: You can get these keys getting an account on the Vodacom Mozambique M-Pesa website

Usage

Add a Swift package to your project:

  1. on Xcode, go to File -> Add Packages...
  2. paste the package repository URL (https://github.com/Algy-Jr12/MpesaSDK) into Search Bar
  3. Next next next :) and enjoy

Supported versions:

  • iOS 10.0
  • macOS 10.12
  • watchOS 3.0
  • tvOS 10.0

Import in your [iOS/macOS/watchOS/tvOS] or plain Swift app.

import MpesaSDK

Create an M-pesa service

let config = MpesaConfig(apiAddress: apiAddress, apiKey: apiKey, publicKey: publicKey)
let service = MpesaRepository(config: config)

C2B API Call

Create a payment request
let paymentRequest = PaymentRequest(
  transactionReference: "transactionReference",
  customerMSISDN: "25884*******",
  amount: "amount",
  thirdPartyReference: "thirdPartyReference",
  serviceProviderCode: "serviceProviderCode"
)
Perform the network call
service.c2bPayment(paymentRequest: paymentRequest) { result in
  // TODO handle response
}
Handle the response
service.c2bPayment(paymentRequest: paymentRequest) { result in
    switch result {
        case .success(let paymentResponse):
            let responseCode = paymentResponse.responseCode
            print(responseCode)
            // Do something depending on the response code

            print(paymentResponse.responseDesc)
        case .failure(let error):
            // Do something depending on the error
            switch error {
                case MpesaError.invalidToken:
                    print(MpesaError.invalidToken.rawValue)
                    // OR your message
                    print("API Key or Public Key incorrect")
                case MpesaError.invalidURL:
                    print(MpesaError.invalidURL.rawValue)
                    // OR your message
                    print("Invalid URL")
                default:
                    print("Request failed with error: \(error.localizedDescription)")
            }
    }
}

Example/Screenshots 📸

Make Payment

Make Payment Screen

Processing Payment

Processing Payment Screen

Payment Failure

Payment Failure Screen

Payment Success

Payment Success Screen

License

MIT License

Copyright (c) 2022 Algy Ali

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
 Official Appwrite Swift SDK 🦅🍎
Official Appwrite Swift SDK 🦅🍎

Appwrite Swift SDK This SDK is compatible with Appwrite server version 0.11.x. For older versions, please check previous releases. This is the Swift S

WalletConnect Swift SDK v2

Wallet Connect v.2 - Swift Swift implementation of WalletConnect v.2 protocol for native iOS applications. Requirements iOS 13 XCode 13 Swift 5 Usage

MetaWear-Swift-Combine-SDK - Build iOS and macOS apps controlling MetaWear Bluetooth Low Energy wearables without C++ or CoreBluetooth expertise
Federal Data SDK built in the Swift programming language. Follow the link for the documentation:

Swift-Federal-Data-SDK Federal Data SDK built in the Swift programming language Until the Swift language becomes more stable, consider this a beta rel

Swift SDK for Apache Kafka

SwiftKafka A swift implementation of Kafka for producing and consuming from event streams. This works by wrapping the librdkafka C library. Swift vers

A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud written in Swift.

Elastic Path Commerce Cloud iOS Swift SDK A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elasti

Sample project with local swift package linked NDI SDK.

NDISwiftPackage Sample project with local swift package linked NDI SDK. Preparation Install NDA SDK on your mac. Software Developer Kit Make package c

Stacksift App SDK

Stacksift SDK Capture and submit crashes to Stacksift. This library ties together Wells and Impact to provide a full crash capturing and submission sy

TelegramStickersImport — Telegram stickers importing SDK for iOS

TelegramStickersImport — Telegram stickers importing SDK for iOS TelegramStickersImport helps your users import third-party programaticaly created sti

Comments
  • getting crash

    getting crash

    Hi, I am getting crash on SecKeyCreateWithData method. key = SecKeyCreateWithData(keyData as CFData, keyDict as CFDictionary, &error)

    Error Log: [seckey] SecKeyCreate init(RSAPublicKey) failed: -50

    Please let me know if you any other information.

    Thanks

    opened by debabrataroy718 8
  • Add Reversal API Call

    Add Reversal API Call

    The Reversal API is used to reverse a successful transaction. Using the Transaction ID of a previously successful transaction, M-Pesa Payments Gateway will withdraw the funds from the recipient party’s mobile money wallet and revert the funds to the mobile money wallet of the initiating party of the original transaction.

    enhancement 
    opened by AlgyJr 0
  • Add B2B API Call

    Add B2B API Call

    The B2B API Call is used as a standard business-to-business transaction. Funds from the business’ mobile money wallet will be deducted and transferred to the mobile money wallet of the third party business.

    enhancement 
    opened by AlgyJr 0
  • Add B2C API Call

    Add B2C API Call

    The B2C API Call is used as a standard business-to-customer transaction. Funds from the business’ mobile money wallet will be deducted and transferred to the mobile money wallet of the third party customer.

    enhancement 
    opened by AlgyJr 0
Releases(v0.1.0)
Owner
Algy Ali
Software Developer
Algy Ali
Alter SDK is a cross-platform SDK consisting of a real-time 3D avatar system, facial motion capture, and an Avatar Designer component built from scratch for web3 interoperability and the open metaverse.

Alter SDK is a cross-platform SDK consisting of a real-time 3D avatar system, facial motion capture, and an Avatar Designer component built from scratch for web3 interoperability and the open metaverse.

Alter 45 Nov 29, 2022
RadioTimeKit - The Swift SDK for TuneIn RadioTimeKit is a Swift package to use the TuneIn API.

RadioTimeKit - The Swift SDK for TuneIn RadioTimeKit is a Swift package to use the TuneIn API. The goal for development was to have a Swift SDK to get

Frank Gregor 2 Jun 20, 2022
Swift SDK for Blockfrost.io API

Swift5 API client for Blockfrost Swift 5 SDK for Blockfrost.io API. Installation • Usage • API Endpoints Installation Swift package manager dependenci

blockfrost.io 10 Dec 24, 2022
Unofficial Notion API SDK for iOS & macOS

NotionSwift Unofficial Notion SDK for iOS & macOS. This is still work in progress version, the module interface might change. API Documentation This l

Wojciech Chojnacki 59 Jan 8, 2023
150,000+ stickers API & SDK for iOS Apps.

English | 한국어 Stipop UI SDK for iOS Stipop SDK provides over 150,000 .png and .gif stickers that can be easily integrated into mobile app chats, comme

Stipop, Inc. 19 Dec 20, 2022
iOS SDK for the Box Content API

Box iOS SDK Getting Started Docs: https://developer.box.com/guides/mobile/ios/quick-start/ NOTE: The Box iOS SDK in Objective-C (prior to v3.0.0) has

Box 112 Dec 19, 2022
iOS SDK for access the OpenCage Geocoding API

OpenCageSDK Requirements OpenCageSDK works on iOS 9+ and requires ARC to build. It depends on the following Apple frameworks, which should already be

OpenCage GmbH 1 Jun 30, 2020
Business-API - Business App an Application that show list business using the Yelp API

business-API Business App an Application that show list business using the Yelp

Edwin Niwarlangga 0 Jan 21, 2022
This is swift project example to connect VNPTSmartCA SDK using Swift Language.

Example source code to integrate with VNPTSmartCA iOS SDK To run the example project, clone repository, and run pod install Requirements Installation

null 1 Feb 14, 2022
Home-assistant-swift-sdk - Used to integrate the Home Assistant APIs with your Swift-based apps.

home-assistant-swift-sdk This open-source library allows you to interact with a Home Assistant instance in your Swift-based (e.g., iOS, macOS, etc.) a

Alexander Golden 0 Dec 31, 2021