In Xcode, follow the guide to add package dependencies to your app and enter https://github.com/paypal/paypal-ios as the repository URL. Tick the PaymentButtons
checkbox to add the Payment Buttons library to your app.
Include the PaymentButtons
sub-mobule in your Podfile
.
pod 'PayPal/PaymentButtons'
The PayPalUI module allows you to render three buttons that can offer a set of customizations like color, edges, size and labels:
PayPalButton
: generic PayPal buttonPayPalPayLater
: a PayPal button with a fixed PayLater labelPayPalCredit
: a PayPal button with the PayPalCredit logo
Each button as a UKit
and SwiftUI
implementation as follows:
| UIKit | SwiftUI |
| ----------- | ----------- |
| PayPalButton | PayPalButton.Representable |
| PayPalCreditButton | PayPalCreditButton.Representable |
| PayPalPayLaterButton | PayPalPayLaterButton.Representable |
Note: label customization only applies to
PayPalButton
when its size is.expanded
or.full
class MyViewController: ViewController {
lazy var payPalButton: PayPalButton = {
let payPalButton = PayPalButton()
payPalButton.addTarget(self, action: #selector(payPalButtonTapped), for: .touchUpInside)
return payPalButton
}()
@objc func paymentButtonTapped() {
// Insert your code here
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(payPalButton)
}
}
struct MyApp: View {
@ViewBuilder
var body: some View {
VStack {
PayPalButton.Representable() {
// Insert your code here
}
}
}
}