[
  {
    "path": ".github/workflows/swift.yml",
    "content": "name: Swift\n\non:\n  push:\n    branches: [ master ]\n  pull_request:\n    branches: [ master ]\n\njobs:\n  build:\n    runs-on: macos-latest\n    steps:\n    - name: Checkout\n      uses: actions/checkout@v2\n    - name: Select Xcode 12\n      run: sudo xcode-select -s /Applications/Xcode_12.app && xcodebuild -version\n    - name: Linting podspec\n      run: pod lib lint\n    - name: Build\n      run: swift build -v\n    - name: Run tests\n      run: swift test -v\n"
  },
  {
    "path": ".gitignore",
    "content": ".DS_Store\n/.build\n/Packages\n/*.xcodeproj\nxcuserdata/\n"
  },
  {
    "path": ".swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n   version = \"1.0\">\n   <FileRef\n      location = \"self:\">\n   </FileRef>\n</Workspace>\n"
  },
  {
    "path": ".swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>IDEDidComputeMac32BitWarning</key>\n\t<true/>\n</dict>\n</plist>\n"
  },
  {
    "path": ".swiftpm/xcode/package.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>\n\t<true/>\n</dict>\n</plist>\n"
  },
  {
    "path": ".swiftpm/xcode/xcshareddata/xcschemes/BuyMeACoffee.xcscheme",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n   LastUpgradeVersion = \"1200\"\n   version = \"1.7\">\n   <BuildAction\n      parallelizeBuildables = \"YES\"\n      buildImplicitDependencies = \"YES\">\n      <BuildActionEntries>\n         <BuildActionEntry\n            buildForTesting = \"YES\"\n            buildForRunning = \"YES\"\n            buildForProfiling = \"YES\"\n            buildForArchiving = \"YES\"\n            buildForAnalyzing = \"YES\">\n            <BuildableReference\n               BuildableIdentifier = \"primary\"\n               BlueprintIdentifier = \"BuyMeACoffee_BuyMeACoffee\"\n               BuildableName = \"BuyMeACoffee_BuyMeACoffee\"\n               BlueprintName = \"BuyMeACoffee_BuyMeACoffee\"\n               ReferencedContainer = \"container:\">\n            </BuildableReference>\n         </BuildActionEntry>\n         <BuildActionEntry\n            buildForTesting = \"YES\"\n            buildForRunning = \"YES\"\n            buildForProfiling = \"YES\"\n            buildForArchiving = \"YES\"\n            buildForAnalyzing = \"YES\">\n            <BuildableReference\n               BuildableIdentifier = \"primary\"\n               BlueprintIdentifier = \"BuyMeACoffee\"\n               BuildableName = \"BuyMeACoffee\"\n               BlueprintName = \"BuyMeACoffee\"\n               ReferencedContainer = \"container:\">\n            </BuildableReference>\n         </BuildActionEntry>\n         <BuildActionEntry\n            buildForTesting = \"YES\"\n            buildForRunning = \"YES\"\n            buildForProfiling = \"NO\"\n            buildForArchiving = \"NO\"\n            buildForAnalyzing = \"YES\">\n            <BuildableReference\n               BuildableIdentifier = \"primary\"\n               BlueprintIdentifier = \"BuyMeACoffeeTests\"\n               BuildableName = \"BuyMeACoffeeTests\"\n               BlueprintName = \"BuyMeACoffeeTests\"\n               ReferencedContainer = \"container:\">\n            </BuildableReference>\n         </BuildActionEntry>\n      </BuildActionEntries>\n   </BuildAction>\n   <TestAction\n      buildConfiguration = \"Debug\"\n      selectedDebuggerIdentifier = \"Xcode.DebuggerFoundation.Debugger.LLDB\"\n      selectedLauncherIdentifier = \"Xcode.DebuggerFoundation.Launcher.LLDB\"\n      shouldUseLaunchSchemeArgsEnv = \"YES\">\n      <PostActions>\n         <ExecutionAction\n            ActionType = \"Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction\">\n            <ActionContent\n               title = \"Run Script\"\n               scriptText = \"cp ~/Library/Developer/CoreSimulator/Devices/$TARGET_DEVICE_IDENTIFIER/data/Library/Caches/snapshot-bmc-button.png $WORKSPACE_PATH/../../../Images&#10;\">\n               <EnvironmentBuildable>\n                  <BuildableReference\n                     BuildableIdentifier = \"primary\"\n                     BlueprintIdentifier = \"BuyMeACoffeeTests\"\n                     BuildableName = \"BuyMeACoffeeTests\"\n                     BlueprintName = \"BuyMeACoffeeTests\"\n                     ReferencedContainer = \"container:\">\n                  </BuildableReference>\n               </EnvironmentBuildable>\n            </ActionContent>\n         </ExecutionAction>\n      </PostActions>\n      <Testables>\n         <TestableReference\n            skipped = \"NO\">\n            <BuildableReference\n               BuildableIdentifier = \"primary\"\n               BlueprintIdentifier = \"BuyMeACoffeeTests\"\n               BuildableName = \"BuyMeACoffeeTests\"\n               BlueprintName = \"BuyMeACoffeeTests\"\n               ReferencedContainer = \"container:\">\n            </BuildableReference>\n         </TestableReference>\n      </Testables>\n   </TestAction>\n   <LaunchAction\n      buildConfiguration = \"Debug\"\n      selectedDebuggerIdentifier = \"Xcode.DebuggerFoundation.Debugger.LLDB\"\n      selectedLauncherIdentifier = \"Xcode.DebuggerFoundation.Launcher.LLDB\"\n      launchStyle = \"0\"\n      useCustomWorkingDirectory = \"NO\"\n      ignoresPersistentStateOnLaunch = \"NO\"\n      debugDocumentVersioning = \"YES\"\n      debugServiceExtension = \"internal\"\n      allowLocationSimulation = \"YES\">\n   </LaunchAction>\n   <ProfileAction\n      buildConfiguration = \"Release\"\n      shouldUseLaunchSchemeArgsEnv = \"YES\"\n      savedToolIdentifier = \"\"\n      useCustomWorkingDirectory = \"NO\"\n      debugDocumentVersioning = \"YES\">\n      <MacroExpansion>\n         <BuildableReference\n            BuildableIdentifier = \"primary\"\n            BlueprintIdentifier = \"BuyMeACoffee_BuyMeACoffee\"\n            BuildableName = \"BuyMeACoffee_BuyMeACoffee\"\n            BlueprintName = \"BuyMeACoffee_BuyMeACoffee\"\n            ReferencedContainer = \"container:\">\n         </BuildableReference>\n      </MacroExpansion>\n   </ProfileAction>\n   <AnalyzeAction\n      buildConfiguration = \"Debug\">\n   </AnalyzeAction>\n   <ArchiveAction\n      buildConfiguration = \"Release\"\n      revealArchiveInOrganizer = \"YES\">\n   </ArchiveAction>\n</Scheme>\n"
  },
  {
    "path": "Bundle.swift",
    "content": "//\n//  Bundle.swift\n//  BuyMeACoffee\n//\n//  Created by François Boulais on 01/07/2020.\n//  Copyright © 2020 App Craft Studio. All rights reserved.\n//\n\nimport Foundation\n\ninternal extension Bundle {\n    static let module = Bundle(for: BMCManager.self)\n}\n"
  },
  {
    "path": "BuyMeACoffee.podspec",
    "content": "Pod::Spec.new do |spec|\n  spec.name                  = 'BuyMeACoffee'\n  spec.version               = '1.0.6'\n  spec.license               = { :type => \"MIT\", :file => \"LICENSE\" }\n                               \n  spec.homepage              = 'https://www.buymeacoffee.com'\n  spec.author                = { 'François Boulais' => 'francois@appcraftstudio.com' }\n  spec.social_media_url      = 'https://twitter.com/frboulais'\n\n  spec.summary               = 'Buy Me a Coffee framework for iOS'\n  spec.source                = { :git => 'https://github.com/appcraftstudio/buymeacoffee.git', :tag => \"#{spec.version}\" }\n  \n  spec.screenshots           = [ 'https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-buymeacoffee-home.png',\n                                 'https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-buymeacoffee-apple-pay.png' ]\n                                 \n  spec.ios.deployment_target = '11.0'\n  spec.platform              = :ios, '11.0'\n  spec.swift_version         = '5.0'\n\n  spec.source_files          = 'Sources/**/*.swift', 'Bundle.swift'\n  spec.resources             = 'Sources/**/Resources/*'\n\n  spec.ios.framework         = 'UIKit', 'WebKit'\n  \n  spec.test_spec 'BuyMeACoffeeTests' do |test_spec|\n    test_spec.source_files   = 'Tests/BuyMeACoffeeTests/*.{swift}'\n  end\nend\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, sex characteristics, gender identity and expression,\nlevel of experience, education, socio-economic status, nationality, personal\nappearance, race, religion, or sexual identity and orientation.\n\n## Our Standards\n\nExamples of behavior that contributes to creating a positive environment\ninclude:\n\n* Using welcoming and inclusive language\n* Being respectful of differing viewpoints and experiences\n* Gracefully accepting constructive criticism\n* Focusing on what is best for the community\n* Showing empathy towards other community members\n\nExamples of unacceptable behavior by participants include:\n\n* The use of sexualized language or imagery and unwelcome sexual attention or\n advances\n* Trolling, insulting/derogatory comments, and personal or political attacks\n* Public or private harassment\n* Publishing others' private information, such as a physical or electronic\n address, without explicit permission\n* Other conduct which could reasonably be considered inappropriate in a\n professional setting\n\n## Our Responsibilities\n\nProject maintainers are responsible for clarifying the standards of acceptable\nbehavior and are expected to take appropriate and fair corrective action in\nresponse to any instances of unacceptable behavior.\n\nProject maintainers have the right and responsibility to remove, edit, or\nreject comments, commits, code, wiki edits, issues, and other contributions\nthat are not aligned to this Code of Conduct, or to ban temporarily or\npermanently any contributor for other behaviors that they deem inappropriate,\nthreatening, offensive, or harmful.\n\n## Scope\n\nThis Code of Conduct applies both within project spaces and in public spaces\nwhen an individual is representing the project or its community. Examples of\nrepresenting a project or community include using an official project e-mail\naddress, posting via an official social media account, or acting as an appointed\nrepresentative at an online or offline event. Representation of a project may be\nfurther defined and clarified by project maintainers.\n\n## Enforcement\n\nInstances of abusive, harassing, or otherwise unacceptable behavior may be\nreported by contacting the project team at francois@appcraftstudio.com. All\ncomplaints will be reviewed and investigated and will result in a response that\nis deemed necessary and appropriate to the circumstances. The project team is\nobligated to maintain confidentiality with regard to the reporter of an incident.\nFurther details of specific enforcement policies may be posted separately.\n\nProject maintainers who do not follow or enforce the Code of Conduct in good\nfaith may face temporary or permanent repercussions as determined by other\nmembers of the project's leadership.\n\n## Attribution\n\nThis Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,\navailable at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html\n\n[homepage]: https://www.contributor-covenant.org\n\nFor answers to common questions about this code of conduct, see\nhttps://www.contributor-covenant.org/faq\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 App Craft Studio\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "Package.swift",
    "content": "// swift-tools-version:5.3\n// The swift-tools-version declares the minimum version of Swift required to build this package.\n\nimport PackageDescription\n\nlet package = Package(\n    name: \"BuyMeACoffee\",\n    platforms: [\n        .iOS(.v11)\n    ],\n    products: [\n        // Products define the executables and libraries a package produces, and make them visible to other packages.\n        .library(name: \"BuyMeACoffee\", targets: [\"BuyMeACoffee\"]),\n        .library(name: \"BuyMeACoffeeDynamic\", type: .dynamic, targets: [\"BuyMeACoffee\"])\n    ],\n    dependencies: [\n        // Dependencies declare other packages that this package depends on.\n        // .package(url: /* package url */, from: \"1.0.0\"),\n    ],\n    targets: [\n        // Targets are the basic building blocks of a package. A target can define a module or a test suite.\n        // Targets can depend on other targets in this package, and on products in packages this package depends on.\n        .target(\n            name: \"BuyMeACoffee\",\n            dependencies: [],\n            resources: [\n                .process(\"Resources/Assets.xcassets\"),\n                .process(\"Resources/Cookie-Regular.ttf\"),\n                .process(\"Resources/Lato-Regular.ttf\")\n            ]),\n        .testTarget(\n            name: \"BuyMeACoffeeTests\",\n            dependencies: [\"BuyMeACoffee\"]),\n    ]\n)\n"
  },
  {
    "path": "README.md",
    "content": "![Swift](https://github.com/appcraftstudio/buymeacoffee/workflows/Swift/badge.svg)\n\n# A supporter is  worth a thousand  followers. \n\n### [Buy Me a Coffee](https://www.buymeacoffee.com) is a modern creator platform. It takes two minutes to start your page and has all the features that you need to build your creative business.\n\n**Donations :moneybag:**  \nGive your audience a friendly way to thank you.\n\n**Memberships :spiral_calendar:**  \nEarn recurring revenue by offering a monthly or yearly membership.\n\n**Sell Extras :sparkles:**  \nA new, creative way to offer Zoom calls, art commissions, anything.  \n\n<p align=\"center\">\n<br>\n<img src=\"https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-buymeacoffee-home.png\" width=\"320\">\n<img src=\"https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-buymeacoffee-apple-pay.png\" width=\"320\">\n</p>\n\n## Features\n\n- [X] Apple Pay\n- [X] iCloud Keychain\n\n## Requirements\n\nCocoaPods | Swift Package Manager\n:---: | :---:\nSwift 5.0 | Swift 5.3\nXcode 11.x | Xcode 12.x\n\n## App Store Review \n\nThese are the two App Store Review Guidelines articles you have to know before using this framework:\n\n[3.1.1 In-App Purchase](https://developer.apple.com/app-store/review/guidelines/#in-app-purchase)\n> - Apps may use in-app purchase currencies to enable customers to “tip” digital content providers in the app.\n\n[3.2.1 Acceptable](https://developer.apple.com/app-store/review/guidelines/#acceptable):\n> **(vii)** Apps may enable individual users to give a monetary gift to another individual without using in-app purchase, provided that (a) the gift is a completely optional choice by the giver, and (b) 100% of the funds go to the receiver of the gift. However, a gift that is connected to or associated at any point in time with receiving digital content or services must use in-app purchase.\n\n## Implement Buy Me a Coffee\n\n1. Import the BuyMeACoffee framework in your `UIApplicationDelegate`:\n```swift\nimport BuyMeACoffee\n```\n2. Configure the `BMCManager` shared instance with the username you've chosen on www.buymeacoffee.com, typically in your app's `application:didFinishLaunchingWithOptions:` method:\n```swift\nBMCManager.shared.configure(username: \"appcraftstudio\")\n```\n3. In the view controller, override the `viewDidLoad` method to set the presenting view controller of the `BMCManager` object.\n```swift\nBMCManager.shared.presentingViewController = self\n// You can also set a custom thank you message\nBMCManager.shared.thankYouMessage = \"Thank you for supporting 🎉 App Craft Studio !\"\n```\n4. Add a `BMCButton` to your storyboard, XIB file, or instantiate it programmatically. To add the button to your storyboard or XIB file, add a View and set its custom class to `BMCButton`.\n5. **Optional**: If you want to customize the button, do the following:\n```swift\nlet configuration = BMCButton.Configuration(color: .orange, font: .cookie)\nlet button = BMCButton(configuration: configuration)\n// or set the burtton configuration later\nbutton.configure(with: configuration)\n```\n\n<p align=\"center\">\n<br>\n<img src=\"https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/snapshot-bmc-button.png\" width=\"300\">\n</p>\n\n## (Optional) Configure In-App Purchase\n\nDepending the legal receiver of the gift configured on Buy Me a Coffee, App Store reviewers can ask for In-App Purchase implementation.  \nIf the following In-App Purchase if configured for your application, it will be displayed as primary flow when user tap on the `BMCButton`.\n\n**If the framework can't retrieve In-App Purchase informations, the web flow will be used as fallback.**\n\n### App Store Connect\n\nGo to [App Store Connect](https://appstoreconnect.apple.com), search for the *In-App Purchases* section of your app, and then, create a new one with the following informations:\n\n|||\n| --- | --- |\n| **Type** | Consumable |\n| **Reference Name** | *Buy Me a Coffee* |\n| **Product ID** | `your.app.bundle.identifier`*.buymeacoffee* |\n| **Cleared for Sale** | :white_check_mark: |\n| **Price** | Tier 4 |\n| **Display Name** | *Buy Me a Coffee* |\n| **Description** | *Hey there! You can now buy me a coffee!*\n| **Promotional Image** | [download here](https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/%20in-app-purchase-promotional-image.jpg) |\n| **Review Screenshot** | [download here](https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/%20in-app-purchase-review-screenshot.png) |\n| **Review Notes** | *Buy Me a Coffee enable customers to “tip” digital content providers in the app.* |\n\n### Capabilities\n\n1. Select the current workspace in the project navigator.\n2. Then, select the app target in the left panel.\n3. Go to the *Signing & Capabilities* tab.\n4. Add the *In-App Purchase* capability.\n\n<p align=\"center\">\n<img src=\"https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-xcode-capabilities.png\" width=\"600\">\n</p>\n\n## Installation\n\n### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)\n\nYou want to add pod `'BuyMeACoffee', '~> 1.0'` similar to the following to your Podfile:\n```rb\ntarget 'MyApp' do\n  pod 'BuyMeACoffee', '~> 1.0'\nend\n```\nThen run a `pod install` inside your terminal, or from CocoaPods.app.\n\n### [Swift Package Manager](https://swift.org/package-manager/)\n\n1. Using Xcode 11 or above go to *File* > *Swift Packages* > *Add Package Dependency*\n2. Paste the project URL: https://github.com/appcraftstudio/buymeacoffee.git\n3. Click on next and select the project target\n\n![Swift Package Manager](https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/screenshot-xcode-spm.png)\n\n---\n\n<a href=\"https://www.producthunt.com/posts/buy-me-a-coffee-framework-for-ios?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-buy-me-a-coffee-framework-for-ios\" target=\"_blank\"><img src=\"https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=233953&theme=dark\" alt=\"Buy Me a Coffee framework for iOS - Embed Buy Me a Coffee framework in your applications | Product Hunt Embed\" style=\"width: 250px; height: 54px;\" width=\"250px\" height=\"54px\" /></a>\n\n<a href=\"https://www.buymeacoffee.com/appcraftstudio\" target=\"_blank\"><img src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" ></a>\n\nCopyright © 2020 App Craft Studio. All rights reserved.\n"
  },
  {
    "path": "Sources/BuyMeACoffee/BMCButton.swift",
    "content": "//\n//  BMCButton.swift\n//\n//  Created by François Boulais on 26/06/2020.\n//  Copyright © 2020 App Craft Studio. All rights reserved.\n//\n\n#if canImport(UIKit)\nimport UIKit\n\n@IBDesignable\npublic class BMCButton: UIButton {\n    public struct Configuration {\n        let color: BMCColor\n        let font: BMCFont\n        let title: String\n        \n        public init(color: BMCColor, font: BMCFont, title: String = \"Buy me a coffee\") {\n            self.color = color\n            self.font = font\n            self.title = title\n        }\n        \n        public static let `default`: Self = .init(color: .default, font: .default)\n    }\n    \n    private lazy var numberFormatter: NumberFormatter = {\n        let numberFormatter = NumberFormatter()\n        numberFormatter.numberStyle = .currency\n        return numberFormatter\n    }()\n    \n    private var _configuration: Configuration = .default\n    \n    public override var isHighlighted: Bool {\n        didSet {\n            alpha = isHighlighted ? 0.85 : 1\n        }\n    }\n    \n    public convenience init(configuration: Configuration) {\n        self.init(type: .custom)\n        \n        self._configuration = configuration\n    }\n    \n    override init(frame: CGRect) {\n        super.init(frame: frame)\n        \n        setup()\n    }\n    \n    required init?(coder: NSCoder) {\n        super.init(coder: coder)\n        \n        setup()\n    }\n    \n    // MARK: - Interface Builder\n    \n    public override func prepareForInterfaceBuilder() {\n        super.prepareForInterfaceBuilder()\n        \n        setup()\n    }\n    \n    // MARK: - Public functions\n    \n    public func configure(with configuration: Configuration) {\n        titleLabel?.font = configuration.font.value\n        setTitleColor(configuration.color.title, for: .normal)\n        setImage(configuration.color.cup, for: .normal)\n        backgroundColor = configuration.color.background\n        \n        var title = configuration.title\n        if let product = BMCManager.shared.product {\n            numberFormatter.locale = product.priceLocale\n            if let price = numberFormatter.string(from: product.price) {\n                title.append(\" (\\(price))\")\n            }\n        }\n\n        setTitle(title, for: .normal)\n    }\n    \n    // MARK: - Private functions\n    \n    private func setup() {\n        layer.shadowOffset = .init(width: 4, height: 4)\n        layer.shadowColor = UIColor.black.cgColor\n        layer.shadowOpacity = 0.1\n        layer.shadowRadius = 2\n        layer.cornerRadius = 5\n\n        contentEdgeInsets = .init(top: 8, left: 12, bottom: 8, right: 12)\n        titleEdgeInsets = .init(top: 0, left: 6, bottom: 0, right: -6)\n        imageEdgeInsets = .init(top: 0, left: -6, bottom: 0, right: 6)\n        \n        imageView?.contentMode = .scaleAspectFit\n        \n        registerFonts()\n        \n        adjustsImageWhenHighlighted = false\n        \n        addTarget(BMCManager.shared, action: #selector(BMCManager.shared.start), for: .touchUpInside)\n        \n        configure(with: _configuration)\n    }\n    \n    private func registerFonts() {\n        if let url = Bundle.module.url(forResource: \"Cookie-Regular\", withExtension: \"ttf\") {\n            CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)\n        }\n        \n        if let url = Bundle.module.url(forResource: \"Lato-Regular\", withExtension: \"ttf\") {\n            CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)\n        }\n    }\n}\n#endif\n"
  },
  {
    "path": "Sources/BuyMeACoffee/BMCColor.swift",
    "content": "//\n//  BMCColor.swift\n//\n//  Created by François Boulais on 30/06/2020.\n//  Copyright © 2020 App Craft Studio. All rights reserved.\n//\n\n#if canImport(UIKit)\nimport UIKit\n\npublic enum BMCColor: String, CaseIterable {\n    case orange\n    case yellow\n    case purple\n    case black\n    case white\n    case blue\n    case green\n    case red\n    case pink\n    \n    public static let `default`: Self = .yellow\n    \n    internal var background: UIColor? {\n        UIColor(named: rawValue, in: .module, compatibleWith: nil)\n    }\n    \n    internal var title: UIColor {\n        switch self {\n        case .orange, .purple, .black, .blue, .green, .red, .pink:\n            return .white\n        case .yellow, .white:\n            return .black\n        }\n    }\n    \n    internal var cup: UIImage? {\n        switch self {\n        case .yellow:\n            return UIImage(named: \"cup-white\", in: .module, compatibleWith: nil)\n        default:\n            return UIImage(named: \"cup-yellow\", in: .module, compatibleWith: nil)\n        }\n    }\n\n}\n#endif\n"
  },
  {
    "path": "Sources/BuyMeACoffee/BMCFont.swift",
    "content": "//\n//  BMCFont.swift\n//  \n//  Created by François Boulais on 30/06/2020.\n//  Copyright © 2020 App Craft Studio. All rights reserved.\n//\n\n#if canImport(UIKit)\nimport UIKit\n\npublic enum BMCFont: String, CaseIterable {\n    case cookie\n    case lato\n    case arial\n    \n    public static let `default`: Self = .cookie\n    \n    internal var value: UIFont? {\n        switch self {\n        case .cookie:\n            return UIFont(name: rawValue.capitalized, size: 26)\n        case .lato:\n            return UIFont(name: rawValue.capitalized, size: 20)\n        case .arial:\n            return UIFont(name: rawValue.capitalized, size: 20)\n        }\n    }\n}\n#endif\n"
  },
  {
    "path": "Sources/BuyMeACoffee/BMCManager.swift",
    "content": "//\n//  BMCManager.swift\n//\n//  Created by François Boulais on 30/06/2020.\n//  Copyright © 2020 App Craft Studio. All rights reserved.\n//\n\n#if canImport(UIKit)\nimport UIKit\nimport SafariServices\nimport StoreKit\n\npublic final class BMCManager: NSObject, SKProductsRequestDelegate, SKPaymentTransactionObserver {\n    public static let shared = BMCManager()\n    \n    // MARK: - Public properties\n    \n    /// The view controller used to present donation flow.\n    public var presentingViewController: UIViewController?\n    \n    /// This text is displayed to supporters immediately after they make a payment.\n    public var thankYouMessage: String?\n    \n    // MARK: - Internal properties\n    \n    internal var product: SKProduct?\n\n    // MARK: - Private properties\n    \n    private var username = \"appcraftstudio\"\n    private var productsRequest: SKProductsRequest?\n    \n    private lazy var loadingViewController: UIViewController = {\n        let activityIndicatorView: UIActivityIndicatorView\n        if #available(iOS 13.0, *) {\n            activityIndicatorView = UIActivityIndicatorView(style: .large)\n        } else {\n            activityIndicatorView = UIActivityIndicatorView(style: .whiteLarge)\n        }\n        \n        activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false\n        activityIndicatorView.color = BMCColor.default.background\n        activityIndicatorView.startAnimating()\n        \n        let viewController = UIViewController()\n        viewController.view.backgroundColor = .white\n        viewController.view.addSubview(activityIndicatorView)\n        viewController.modalPresentationStyle = .formSheet\n        \n        if #available(iOS 13.0, *) {\n            viewController.isModalInPresentation = true\n        }\n\n        NSLayoutConstraint.activate([\n            activityIndicatorView.centerXAnchor.constraint(equalTo: viewController.view.centerXAnchor),\n            activityIndicatorView.centerYAnchor.constraint(equalTo: viewController.view.centerYAnchor)\n        ])\n        \n        return viewController\n    }()\n\n    private var url: URL? {\n        URL(string: \"https://www.buymeacoffee.com/\".appending(username))\n    }\n        \n    // MARK: - Public functions\n    \n    /**\n     Configure the manager for future donation requests.\n     - parameters:\n        - username: The username you've chosen on www.buymeacoffee.com.\n     */\n    public func configure(username: String) {\n        self.username = username\n\n        guard SKPaymentQueue.canMakePayments() else {\n            return\n        }\n        \n        if let productIdentifier = Bundle.main.bundleIdentifier?.appending(\".buymeacoffee\") {\n            productsRequest?.cancel()\n            productsRequest = SKProductsRequest(productIdentifiers: [productIdentifier])\n            productsRequest?.delegate = self\n            productsRequest?.start()\n        }\n    }\n    \n    /**\n     Start the donation flow on presenting view controller.\n     */\n    @objc public func start() {\n        guard let presentingViewController = presentingViewController else {\n            fatalError(\"presentingViewController must be set.\")\n        }\n        \n        guard SKPaymentQueue.canMakePayments(), let product = product else {\n            return fallback()\n        }\n        \n        presentingViewController.present(loadingViewController, animated: true) {\n            let payment = SKPayment(product: product)\n            SKPaymentQueue.default().add(self)\n            SKPaymentQueue.default().add(payment)\n        }\n    }\n    \n    // MARK: - Private functions\n    \n    private override init() { }\n    \n    private func fallback() {\n        guard let url = url else {\n            return\n        }\n        \n        let viewController = SFSafariViewController(url: url)\n        viewController.preferredControlTintColor = BMCColor.default.background\n        viewController.modalPresentationStyle = .formSheet\n        presentingViewController?.present(viewController, animated: true)\n    }\n    \n    private func showPurchasedMessage() {\n        let message = thankYouMessage ?? \"Thank you for supporting 🎉\"\n        let alertController = UIAlertController(title: \"Buy Me a Coffee\", message: message, preferredStyle: .alert)\n        \n        alertController.addAction(.init(title: \"Close\", style: .default, handler: { [weak self] _ in\n            self?.loadingViewController.dismiss(animated: true)\n        }))\n        \n        alertController.view.tintColor = BMCColor.default.background\n        loadingViewController.present(alertController, animated: true)\n    }\n    \n    // MARK: - SKProductsRequestDelegate\n    \n    public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {\n        product = response.products.first\n        productsRequest = nil\n    }\n    \n    // MARK: - SKPaymentTransactionObserver\n    \n    public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {\n        for transaction in transactions {\n            switch transaction.transactionState {\n            case .purchased:\n                showPurchasedMessage()\n                SKPaymentQueue.default().finishTransaction(transaction)\n            case .failed:\n                loadingViewController.dismiss(animated: true) { [weak self] in\n                    if (transaction.error as? SKError)?.code != .paymentCancelled {\n                        self?.fallback()\n                    }\n                }\n            case .restored:\n                break\n            case .deferred:\n                break\n            case .purchasing:\n                break\n            @unknown default:\n                break\n            }\n        }\n    }\n    \n    public func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool {\n        true\n    }\n}\n#endif\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/Contents.json",
    "content": "{\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/black.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"0.000\",\n          \"green\" : \"0.000\",\n          \"red\" : \"0.000\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/blue.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"1.000\",\n          \"green\" : \"0.498\",\n          \"red\" : \"0.373\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/green.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"0.710\",\n          \"green\" : \"0.839\",\n          \"red\" : \"0.475\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/orange.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"0.247\",\n          \"green\" : \"0.506\",\n          \"red\" : \"1.000\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/pink.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"1.000\",\n          \"green\" : \"0.443\",\n          \"red\" : \"0.957\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/purple.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"1.000\",\n          \"green\" : \"0.373\",\n          \"red\" : \"0.741\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/red.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"0.373\",\n          \"green\" : \"0.373\",\n          \"red\" : \"1.000\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/white.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"1.000\",\n          \"green\" : \"1.000\",\n          \"red\" : \"1.000\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Colors/yellow.colorset/Contents.json",
    "content": "{\n  \"colors\" : [\n    {\n      \"color\" : {\n        \"color-space\" : \"srgb\",\n        \"components\" : {\n          \"alpha\" : \"1.000\",\n          \"blue\" : \"0.000\",\n          \"green\" : \"0.867\",\n          \"red\" : \"1.000\"\n        }\n      },\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/Contents.json",
    "content": "{\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/cup-white.imageset/Contents.json",
    "content": "{\n  \"images\" : [\n    {\n      \"filename\" : \"cup-white.pdf\",\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  }\n}\n"
  },
  {
    "path": "Sources/BuyMeACoffee/Resources/Assets.xcassets/cup-yellow.imageset/Contents.json",
    "content": "{\n  \"images\" : [\n    {\n      \"filename\" : \"cup-yellow.pdf\",\n      \"idiom\" : \"universal\"\n    }\n  ],\n  \"info\" : {\n    \"author\" : \"xcode\",\n    \"version\" : 1\n  },\n  \"properties\" : {\n    \"template-rendering-intent\" : \"original\"\n  }\n}\n"
  },
  {
    "path": "Tests/BuyMeACoffeeTests/XCTestManifests.swift",
    "content": "import XCTest\n\n#if !canImport(ObjectiveC)\npublic func allTests() -> [XCTestCaseEntry] {\n    return [\n        testCase(buymeacoffeeTests.allTests),\n    ]\n}\n#endif\n"
  },
  {
    "path": "Tests/LinuxMain.swift",
    "content": "import XCTest\n\nimport BuyMeACoffeeTests\n\nvar tests = [XCTestCaseEntry]()\n#if canImport(UIKit)\ntests += BuyMeACoffeeTests.allTests()\n#endif\nXCTMain(tests)\n"
  },
  {
    "path": "Tests/buymeacoffeeTests/BuyMeACoffeeTests.swift",
    "content": "import Foundation\nimport XCTest\n@testable import BuyMeACoffee\n\n#if canImport(UIKit)\nfinal class BuyMeACoffeeTests: XCTestCase {\n    private let fileManager: FileManager = .default\n    \n    func testSnapshotButton() {\n        guard let url = fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first else {\n            XCTFail()\n            return\n        }\n        \n        var isDirectory: ObjCBool = false\n        if !fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory) || !isDirectory.boolValue {\n            XCTAssertNoThrow(try fileManager.createDirectory(at: url, withIntermediateDirectories: false))\n        }\n        \n        let button = BMCButton(frame: .init(x: 0, y: 0, width: 200, height: 50))\n        button.configure(with: .default)\n                \n        if let data = button.snapshot().pngData() {\n            let url = url.appendingPathComponent(\"snapshot-bmc-button\").appendingPathExtension(\"png\")\n            print(url.path)\n            XCTAssertNoThrow(try data.write(to: url))\n        } else {\n            XCTFail()\n        }\n    }\n\n    static var allTests = [\n        (\"snapshot button\", testSnapshotButton),\n    ]\n}\n\nfileprivate extension BMCButton {\n    var size: CGSize {\n        bounds.insetBy(dx: -layer.shadowOffset.width, dy: -layer.shadowOffset.height).size\n    }\n    \n    func snapshot() -> UIImage {\n        UIGraphicsImageRenderer(size: size).image { context in\n            layer.render(in: context.cgContext)\n        }\n    }\n}\n#endif\n"
  }
]