Giter Site home page Giter Site logo

pablocordova / squarepointofsalesdk-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from square/squarepointofsalesdk-ios

0.0 2.0 0.0 211 KB

A simple library for letting Point of Sale take in-store payments for your app using the Point of Sale API.

Home Page: https://docs.connect.squareup.com

License: Apache License 2.0

Ruby 7.53% Objective-C 66.57% Swift 25.53% Shell 0.37%

squarepointofsalesdk-ios's Introduction

Square Point of Sale SDK

CI Status Carthage Compatibility Version License Platform

The Square Point of Sale SDK lets you quickly and easily add support to your application for completing in-store payments using Square Point of Sale.

Requirements

It is not currently possible to process a fake credit card payment with the Point of Sale API. If you are testing your integration, you can process small card payments (as low as $1) and then issue refunds from Square Point of Sale. Please visit squareup.com/activate to ensure your account is enabled for payment processing.

Getting started

Add the SDK to your project

platform :ios, '9.0'
pod 'SquarePointOfSaleSDK'

Be sure to call pod update and use pod install --repo-update to ensure you have the most recent version of the SDK installed.

github "Square/SquarePointOfSaleSDK-iOS"

Git Submodules

Checkout the submodule with git submodule add https://github.com/square/SquarePointOfSaleSDK-iOS.git, drag SquarePointOfSaleSDK.xcodeproj to your project, and add SquarePointOfSaleSDK as a build dependency.


Update your Info.plist

To get started with the Square Point of Sale SDK, you'll need to configure your Info.plist file with a few changes.

First, navigate to your project's settings in Xcode and click the "Info" tab. Under Custom iOS Target Properties:

  1. Add a new entry with key LSApplicationQueriesSchemes.
  2. Set the "Type" to Array.
  3. Add the value square-commerce-v1 to the array.

Next, create a URL scheme so that Square Point of Sale can re-open your app after a customer finishes a transaction. If your app already has a URL scheme, you can use that.

Finally, open the "URL Types" section and click the "+" in the bottom left to add a new URL type. Set the values to the following:

Property Value
Identifier Square
URL Schemes Your URL Scheme
Role Editor

Register your app with Square

  1. Create a new app in the Square Developer Portal.
  2. Under the Point of Sale API tab, add your application's bundle identifier and URL scheme, then click "Save".
  3. Get your Application ID from the Credentials tab.

Usage

Swift

Import Declaration: import SquarePointOfSaleSDK

// Replace with your app's URL scheme.
let yourCallbackURL = URL(string: "your-url-scheme://")!

// Your client ID is the same as your Square Application ID.
// Note: You only need to set your client ID once, before creating your first request.
SCCAPIRequest.setClientID("YOUR_CLIENT_ID")

do {
    // Specify the amount of money to charge.
    let money = try SCCMoney(amountCents: 100, currencyCode: "USD")

    // Create the request.
    let apiRequest =
        try SCCAPIRequest(
            callbackURL: yourCallbackURL,
            amount: money,
            userInfoString: nil,
            merchantID: nil,
            notes: "Coffee",
            customerID: nil,
            supportedTenderTypes: .all,
            clearsDefaultFees: false,
            returnAutomaticallyAfterPayment: false
        )

    // Open Point of Sale to complete the payment.
    try SCCAPIConnection.perform(apiRequest)

} catch let error as NSError {
    print(error.localizedDescription)
}

Finally, implement the UIApplication delegate method as follows:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let sourceApplication = options[.sourceApplication] as? String,
        sourceApplication.hasPrefix("com.squareup.square") else {
        return false
    }

    do {
        let response = try SCCAPIResponse(responseURL: url)

        if let error = response.error {
            // Handle a failed request.
            print(error.localizedDescription)
        } else {
            // Handle a successful request.
        }

    } catch let error as NSError {
        // Handle unexpected errors.
        print(error.localizedDescription)
    }

    return true
}

Objective C

Import Declaration: @import SquarePointOfSaleSDK;

// Replace with your app's callback URL.
NSURL *const callbackURL = [NSURL URLWithString:@"your-url-scheme://"];

// Specify the amount of money to charge.
SCCMoney *const amount = [SCCMoney moneyWithAmountCents:100 currencyCode:@"USD" error:NULL];

// Your client ID is the same as your Square Application ID.
// Note: You only need to set your client ID once, before creating your first request.
[SCCAPIRequest setClientID:@"YOUR_CLIENT_ID"];

SCCAPIRequest *request = [SCCAPIRequest requestWithCallbackURL:callbackURL
                                                        amount:amount
                                                userInfoString:nil
                                                    merchantID:nil
                                                         notes:@"Coffee"
                                                    customerID:nil
                                          supportedTenderTypes:SCCAPIRequestTenderTypeAll
                                             clearsDefaultFees:NO
                               returnAutomaticallyAfterPayment:NO
                                                         error:&error];

When you're ready to charge the customer, bring Point of Sale into the foreground to complete the payment:

[SCCAPIConnection performRequest:request error:&error];

Finally, implement the relevant UIApplication delegate.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)URL options:(NSDictionary<NSString *,id> *)options;
{
    NSString *const sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
    if ([sourceApplication hasPrefix:@"com.squareup.square"]) {
        SCCAPIResponse *const response = [SCCAPIResponse responseWithResponseURL:URL error:&decodeError];
        ...
        return YES;
    }
    return NO;
}

Contributing

We’re glad you’re interested in Square Point of Sale SDK, and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a Pull Request.

Support

If you are having trouble with using this SDK in your project, please create a question on Stack Overflow with the square-connect tag. Our team monitors that tag and will be able to help you. If you think there is something wrong with the SDK itself, please create an issue.

License

Copyright 2017 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

squarepointofsalesdk-ios's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.