• This repository has been archived on 09/Apr/2021
  • Stars
    star
    193
  • Rank 194,729 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Test your Apple Pay integration without Apple Pay

ApplePayStubs

First, some big news!

This library exists because as of iOS8 it was impossible to display a PKPaymentAuthorizationViewController (a.k.a. an Apple Pay payment sheet) in the iOS simulator. Fortunately, this is no longer necessary - as of iOS 9, Apple Pay works in the simulator, and returns dummy test cards. In other words, ApplePayStubs has been sherlocked! As such, consider this library deprecated as of iOS 9. If you're interested in using it until the iOS 9 / Xcode 7 release, though, read on!

What is this?

ApplePay is awesome. However, since it isn't available in every country yet, and only then on the newest iOS devices, we want to make it easier for developers to plan and test their Apple Pay integrations.

We've created a replacement component for PKPaymentAuthorizationViewController (the primary class involved in ApplePay transactions) for businesses interested in working with ApplePay called STPTestPaymentAuthorizationViewController. These classes appear visually similar and behave almost identically. The primary difference is that STPTestPaymentAuthorizationViewController yields test credit cards and addresses instead of accessing actual information stored on a user's iPhone. You can use it to build and test all of your UI and application logic around ApplePay, and switch it out for the real thing once you have access to a proper testing device.

Please note that this is for testing and development purposes only.

Dependencies

  • Xcode 6+
  • iOS 8+

ApplePayStubs also depends on the PassKit framework.

Installation

Use Cocoapods or manually add the files to your repository.

Usage

You create and use instances of STPTestPaymentAuthorizationViewController exactly the same way as with PKPaymentAuthorizationViewController.

// ViewController.m
- (void)checkoutButtonTapped {
    PKPaymentRequest *request = ...;
    UIViewController *controller;
#if DEBUG
    controller = [[STPTestPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
    controller.delegate = self;
#else
    controller = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
    controller.delegate = self;
#endif

    [self presentViewController:controller];
}

STPTestPaymentAuthorizationViewController will trigger the same PKPaymentAuthorizationViewControllerDelegate callbacks at the appropriate time on its delegate.

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                  didSelectShippingAddress:(ABRecordRef)address
                                completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *shippingMethods, NSArray *summaryItems))completion {
    [self fetchShippingCostsForAddress:address completion:^(NSArray *shippingMethods, NSError *error) {
        if (error) {
            completion(PKPaymentAuthorizationStatusFailure, nil, nil);
            return;
        }
        completion(PKPaymentAuthorizationStatusSuccess, shippingMethods, [self summaryItemsForShippingMethod:shippingMethods.firstObject]);
    }];
}

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                   didSelectShippingMethod:(PKShippingMethod *)shippingMethod
                                completion:(void (^)(PKPaymentAuthorizationStatus, NSArray *summaryItems))completion {
    completion(PKPaymentAuthorizationStatusSuccess, [self summaryItemsForShippingMethod:shippingMethod]);
}

- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller {
    [self dismissViewControllerAnimated:YES completion:nil];
}

When the user finishes selecting a card, as usual STPTestPaymentAuthorizationViewController will call paymentAuthorizationViewController:didAuthorizePayment:completion on its delegate. This delegate method includes a PKPayment object, which itself has an instance of PKPaymentToken that contains encrypted credit card data that you'd pass off to your payment processor (such as Stripe). While the PKPayment and PKPaymentToken returned by ApplePayStubs have stubbed (and invalid) versions of this data, the Stripe API will be able to recognize them in testmode. As such, you shouldn't have to modify your existing PKPaymentAuthorizationViewControllerDelegate methods:

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                       didAuthorizePayment:(PKPayment *)payment
                                completion:(void (^)(PKPaymentAuthorizationStatus))completion {
                                
    [[STPAPIClient sharedClient] createTokenWithPayment:payment
        completion:^(STPToken *token, NSError *error) {
            [self createBackendChargeWithToken:token
                                    completion:^(STPBackendChargeResult status, NSError *error) {
                if (status == STPBackendChargeResultSuccess) {
                    completion(PKPaymentAuthorizationStatusSuccess);
                } else {
                    completion(PKPaymentAuthorizationStatusFailure);
                }
        }];
    }];
}

(Note: Stripe tokens created from Apple Pay work interchangeably with those created using manually-collected credit card details).

If you're not using Stripe, you can find the selected card information on the PKPayment's PKPaymentToken in the transactionIdentifier field, in the format "ApplePayStubs~{card_number}~{amount_in_cents}~{currency}~{uuid}".

Example App / Learn More

If you'd like to see more examples of how to use this, we use ApplePayStubs in the example app for our main iOS library.

If you'd like to learn more about accepting payments on iOS with Stripe in general, read our iOS tutorial.

More Repositories

1

jquery.payment

[DEPRECATED] A general purpose library for building credit card forms, validating inputs and formatting numbers.
CoffeeScript
3,543
star
2

react-stripe-elements

Moved to stripe/react-stripe-js.
JavaScript
3,026
star
3

mosql

MongoDB β†’ PostgreSQL streaming replication
Ruby
1,628
star
4

stripe-payments-demo

Sample store accepting universal payments on the web with Stripe Elements, Payment Request, Apple Pay, Google Pay, Microsoft Pay, and the PaymentIntents API. πŸ’³πŸŒβœ¨
JavaScript
1,465
star
5

shop

Single-page shop
CSS
1,129
star
6

flow-to-typescript-codemod

Codemod Stripe used to migrate 6.5m+ lines of code from Flow to TypeScript
TypeScript
654
star
7

safesql

Static analysis tool for Golang that protects against SQL injections
Go
563
star
8

PaymentKit

Easily accept payments on iOS
Objective-C
472
star
9

brushfire

Distributed decision tree ensemble learning in Scala
Scala
395
star
10

stripe-webhook-monitor

Stripe Webhook Monitor provides a real-time feed and graph of Stripe events received via webhooks. πŸ“ˆβœ¨
JavaScript
363
star
11

accept-a-card-payment

Learn how to accept a basic card payment on web, iOS, Android
Java
348
star
12

jquery.mobilePhoneNumber

[DEPRECATED] A general purpose library for validating and formatting mobile phone numbers.
CoffeeScript
331
star
13

nextjs-typescript-react-stripe-js

Full-stack TypeScript example using Next.js, react-stripe-js, and stripe-node.
TypeScript
324
star
14

topmodel

Standard evaluations for binary classifiers so you don't have to
Python
318
star
15

gaps

Easy management of your Google Groups subscriptions.
Ruby
284
star
16

developer-office-hours

A collection of Stripe Developer Office Hours demos 🎬
Ruby
242
star
17

timberlake

Timberlake is a Job Tracker for Hadoop.
Go
177
star
18

wilde-things

A tutorial integrating Stripe in PHP
PHP
175
star
19

sequins

A key/value store for serving static batch data
Go
175
star
20

checkout-subscription-and-add-on

Uses Stripe Checkout to create a payment page that starts a subscription for a new customer.
CSS
162
star
21

mongoriver

A library for writing MongoDB oplog tailers.
Ruby
153
star
22

stripe-demo-connect-kavholm-marketplace

Demo app for Global Marketplace using Stripe Connect
JavaScript
138
star
23

herringbone

Tools for working with parquet, impala, and hive
Thrift
135
star
24

pd2pg

Import PagerDuty data into Postgres for analysis
Ruby
110
star
25

payment-form-modal

How to implement Stripe Elements within a modal dialog.
JavaScript
106
star
26

datadog-checks

Checks for the Datadog Agent that Stripe finds useful.
Python
97
star
27

set-up-subscriptions

Getting started with Stripe Elements and Stripe Billing to charge a customer for a monthly subscription.
CSS
95
star
28

macgyver

A Chrome extension which duct tapes an SSH agent to the platformKey API
Go
90
star
29

react-elements-card-payment

Learn how to build a checkout form with React
CSS
87
star
30

chalk-log

Chalk::Log adds a logger object to any class, which can be used for unstructured or semi-structured logging.
Ruby
72
star
31

agate

Scoring ONNX models on the JVM in scala
Scala
69
star
32

charging-for-multiple-plan-subscriptions

Getting started with Stripe Elements and Stripe Billing to charge a customer for a monthly subscription with multiple items.
JavaScript
54
star
33

sbt-bazel

Easily convert SBT projects to Bazel workspaces
Scala
54
star
34

firebase-mobile-payments

Firebase Cloud Functions to create payments in native Android and iOS applications.
Kotlin
50
star
35

checkout-remember-me-with-twilio-verify

Use Stripe Checkout to collect payment details for future payments and Twilio Verify to authenticate the customer via SMS code and charge their stored card.
JavaScript
49
star
36

identity-verification

Securely collect and verify identity documents
JavaScript
44
star
37

falconer

High throughout, unsampled tracing span buffer with streaming search
Go
41
star
38

web-elements-sepa-debit-payment

Collect SEPA Debit mandates and payments.
Objective-C
37
star
39

payment-tag

CoffeeScript
34
star
40

stripe-stdlib-demo

Sample store accepting universal payments built with @Stripe and @StdLib.
JavaScript
33
star
41

chalk-config

Maps on-disk config files into a loaded global configatron instance, taking into account your current environment.
Ruby
28
star
42

go-einhorn

Talk to einhorn from your Go worker
Go
25
star
43

sample-terminal-ios-app

Learn how to take in-person payments with a physical reader and Terminal in your iOS app
Swift
19
star
44

adding-sales-tax

Learn how to use PaymentIntents to build a simple checkout flow
CSS
18
star
45

javascript-style

Javascript linter with rules for Stripe projects
JavaScript
16
star
46

scrooge-shapes

Shapeless generic instances for Scrooge types
Scala
14
star
47

datadog-cli-tools

CLI tools we find useful for Datadog
Ruby
13
star
48

submigrate

Combine multiple subscriptions into a single subscription with multiple items
Go
12
star
49

web-elements-fpx-payment

Accept Malaysian online bank transfers with the Stripe FPX Element.
JavaScript
12
star
50

siv-go

A pure Go implementation of the SIV AEAD.
Go
11
star
51

au-becs-debit-payment

Collecting AU BECS Direct Debit mandates and payments.
Java
10
star
52

round-up-and-donate

Build a round up and donate feature with Connect
CSS
10
star
53

oxxo-payment

Learn how to accept OXXO and card payments
JavaScript
10
star
54

random

A collection of random utilities
Shell
9
star
55

web-elements-ideal-payment

Learn how to accept iDEAL and cards in your website
Objective-C
8
star
56

web-elements-card-payment

Learn how to accept a basic card payment on the web
JavaScript
7
star
57

grabpay-payment

Accept GrabPay Payments with Stripe, a popular digital wallet in Southeast Asia.
CSS
5
star
58

yard-sorbet

Types are documentation
Ruby
5
star
59

terraform-provider-confidant

A terraform provider for confidant. See https://github.com/terraform-providers
Go
5
star
60

simple-powershell-dsc

Simple Powershell DSC pull server in Go
Go
4
star
61

stripe-magento1-releases

4
star
62

pb

Lint protocol buffers
Go
2
star
63

mobile-elements-card-payment

Learn how to accept a basic card payment on iOS & Android
Java
2
star
64

bazel-bloop-exporter

This proof of concept exports a bazel project to bloop. The motivation is to allow the use of any tooling that already has a bloop integration, such as the metals language server.
Starlark
2
star
65

sentry-restricted-github

Python
2
star
66

time-utils

Ruby
1
star