Skip to content

Commit

Permalink
Merge pull request #125 from afterpay/pay-now-button
Browse files Browse the repository at this point in the history
Add 'Pay Now' button to Afterpay framework and example project
  • Loading branch information
adamjcampbell authored Dec 1, 2020
2 parents 1b4da58 + 77f98a3 commit f06194f
Show file tree
Hide file tree
Showing 17 changed files with 512 additions and 50 deletions.
4 changes: 4 additions & 0 deletions Afterpay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
6602EF0F25358A8000A0468C /* ColorScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6602EF0E25358A8000A0468C /* ColorScheme.swift */; };
6605666324E5199500DA588E /* Locales.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6605666224E5199500DA588E /* Locales.swift */; };
6615F99B24D14620005036F1 /* SVG.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6615F99A24D14620005036F1 /* SVG.swift */; };
661CFDB62570E7F000D8A1E8 /* PaymentButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */; };
662A3AED24A999A500EFD826 /* CheckoutResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662A3AEC24A999A500EFD826 /* CheckoutResult.swift */; };
6635B95F24CAA9F000EBB3A6 /* ConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6635B95E24CAA9F000EBB3A6 /* ConfigurationTests.swift */; };
6640C15224D8E1A700F7F4CC /* Macaw in Frameworks */ = {isa = PBXBuildFile; productRef = 6640C15124D8E1A700F7F4CC /* Macaw */; };
Expand Down Expand Up @@ -48,6 +49,7 @@
6602EF0E25358A8000A0468C /* ColorScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorScheme.swift; sourceTree = "<group>"; };
6605666224E5199500DA588E /* Locales.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locales.swift; sourceTree = "<group>"; };
6615F99A24D14620005036F1 /* SVG.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SVG.swift; sourceTree = "<group>"; };
661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButton.swift; sourceTree = "<group>"; };
662A3AEC24A999A500EFD826 /* CheckoutResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckoutResult.swift; sourceTree = "<group>"; };
6632E0AE248A0171007F0BD9 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
6635B95E24CAA9F000EBB3A6 /* ConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -111,6 +113,7 @@
66EE9BD624DCEC3D00A81C19 /* LinkTextView.swift */,
66483F3A24D7A164000BE6B5 /* PriceBreakdownView.swift */,
66639B5324D2619200C68558 /* SVGView.swift */,
661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -438,6 +441,7 @@
6689536C24C96CB5005090B4 /* Configuration.swift in Sources */,
15F7DDB725393BD30011EC25 /* CurrencyFormatter.swift in Sources */,
66DAAC8B24E0CF0100127460 /* PriceBreakdown.swift in Sources */,
661CFDB62570E7F000D8A1E8 /* PaymentButton.swift in Sources */,
662A3AED24A999A500EFD826 /* CheckoutResult.swift in Sources */,
667AD3542497121200BF94E5 /* CheckoutWebViewController.swift in Sources */,
66F9767C2499A11A001D38FA /* Afterpay.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Configurations/Afterpay-Shared.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ TARGETED_DEVICE_FAMILY = 1,2
// This setting defines the user-visible version of the project. The value corresponds to
// the `CFBundleShortVersionString` key in your app's Info.plist.

MARKETING_VERSION = 1.3.0
MARKETING_VERSION = 1.4.0
10 changes: 5 additions & 5 deletions Example/Example/Purchase/CartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2020 Afterpay. All rights reserved.
//

import Afterpay
import Foundation

final class CartViewController: UIViewController, UITableViewDataSource {
Expand Down Expand Up @@ -44,9 +45,8 @@ final class CartViewController: UIViewController, UITableViewDataSource {
tableView.register(ProductCell.self, forCellReuseIdentifier: productCellIdentifier)
tableView.register(TitleSubtitleCell.self, forCellReuseIdentifier: titleSubtitleCellIdentifier)

let payButton: UIButton = .primaryButton
let payButton: UIButton = PaymentButton()
payButton.isEnabled = cart.payEnabled
payButton.setTitle("Pay with Afterpay", for: .normal)
payButton.addTarget(self, action: #selector(didTapPay), for: .touchUpInside)

view.addSubview(tableView)
Expand All @@ -57,9 +57,9 @@ final class CartViewController: UIViewController, UITableViewDataSource {
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: payButton.topAnchor),
payButton.leadingAnchor.constraint(equalTo: view.leadingAnchor),
payButton.trailingAnchor.constraint(equalTo: view.trailingAnchor),
payButton.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor),
payButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
payButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
payButton.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor, constant: -16),
])
}

Expand Down
Binary file added Images/button_black_on_mint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/button_black_on_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/button_mint_on_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/button_white_on_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
"object": {
"pins": [
{
"package": "SwiftSVG",
"repositoryURL": "https://github.com/mchoe/SwiftSVG.git",
"package": "Macaw",
"repositoryURL": "https://github.com/exyte/Macaw.git",
"state": {
"branch": null,
"revision": "c3a8866a25ace169ee8e5c037670ba14aa59606f",
"version": "2.3.2"
"revision": "7cb4f5876423435e1a41628417230accc37284c6",
"version": "0.9.7"
}
},
{
"package": "SWXMLHash",
"repositoryURL": "https://github.com/drmohundro/SWXMLHash",
"state": {
"branch": null,
"revision": "a4931e5c3bafbedeb1601d3bb76bbe835c6d475a",
"version": "5.0.1"
}
}
]
Expand Down
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Add the Afterpay SDK as a [git submodule][git-submodule] by navigating to the ro
```
git submodule add https://github.com/afterpay/sdk-ios.git Afterpay
cd Afterpay
git checkout 1.3.0
git checkout 1.4.0
```

#### Project / Workspace Integration
Expand Down Expand Up @@ -163,18 +163,11 @@ BOOL (^challengeHandler)(NSURLAuthenticationChallenge *, CompletionHandler) = ^B
[APAfterpay setAuthenticationChallengeHandler:challengeHandler];
```
## Badge
## Views
The Afterpay badge is a simple UIView that can be scaled to suit the needs of your app. As per branding guidelines it has a minimum width constraint of 64 points.
### Color Schemes
```swift
let badgeView = BadgeView()
```

The badge has four styles to fit light and dark themes:
![Black on Mint badge][badge-black-on-mint] ![Mint on Black badge][badge-mint-on-black] ![White on Black badge][badge-white-on-black] ![Black on White badge][badge-black-on-white]

Color schemes can be set on the badge view to have a single style in both light and dark mode or to change automatically.
Color schemes can be set on the badge view or payment button to either have a single style in both light and dark mode or to change automatically.
```swift
// Always black on mint
Expand All @@ -184,6 +177,27 @@ badgeView.colorScheme = .static(.blackOnMint)
badgeView.colorScheme = .dynamic(lightPalette: .whiteOnBlack, darkPalette: .blackOnWhite)
```

### Badge

The Afterpay badge is a simple `UIView` that can be scaled to suit the needs of your app. As per branding guidelines it has a minimum width constraint of 64 points.

```swift
let badgeView = BadgeView()
```

Below are examples of the badge in each of the color schemes:
![Black on Mint badge][badge-black-on-mint] ![Mint on Black badge][badge-mint-on-black] ![White on Black badge][badge-white-on-black] ![Black on White badge][badge-black-on-white]

### Payment Button

The Afterpay Payment Button is a subclass of `UIButton` that can be scaled to suit your layout, to guarantee legibility it has a maximum width constraint of 256 points.

Below are examples of the button in each of the color schemes:
| Mint and Black | Black and White |
| -- | -- |
| ![Black on Mint button][button-black-on-mint] | ![White on Black button][button-white-on-black] |
| ![Mint on Black button][button-mint-on-black] | ![Black on White button][button-black-on-white] |

## Price Breakdown

The price breakdown component displays information about Afterpay instalments and handles a number of common scenarios.
Expand Down Expand Up @@ -351,6 +365,10 @@ This project is licensed under the terms of the Apache 2.0 license. See the [LIC
[badge-mint-on-black]: Images/badge_mint_on_black.png
[badge-white-on-black]: Images/badge_white_on_black.png
[badge-black-on-white]: Images/badge_black_on_white.png
[button-black-on-mint]: Images/button_black_on_mint.png
[button-mint-on-black]: Images/button_mint_on_black.png
[button-white-on-black]: Images/button_white_on_black.png
[button-black-on-white]: Images/button_black_on_white.png
[bootstrap]: Scripts/bootstrap
[carthage]: https://github.com/Carthage/Carthage
[ccp]: https://cocoapods.org/pods/Afterpay
Expand Down
4 changes: 4 additions & 0 deletions Sources/Afterpay/Afterpay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ public func setConfiguration(_ configuration: Configuration?) {

notificationCenter.post(name: .configurationUpdated, object: previousConfiguration)
}

func getLocale() -> Locale {
getConfiguration()?.locale ?? Locales.unitedStates
}
Loading

0 comments on commit f06194f

Please sign in to comment.