Swift PKPayment Request error - ios

I'm currently working with a PKPaymentAuthorizationViewController and presenting it to validate a payment within my application. I am able to present the controller but receive an error stating "Invalid in-app payment request. PKPaymentRequest must contain a property 'countryCode' of type 'NSString'". I have set the country code for the payment request and still receive this error. Attached below if the code I'm using to create the payment request and present the controller. I have X'd out my merchant ID for the purpose of posting. Any help would be appreciated.
var applePayController = PKPaymentAuthorizationViewController()
applePayController.delegate = self
let request = PKPaymentRequest()
let supportedPaymentNetworks = [PKPaymentNetwork.visa, PKPaymentNetwork.masterCard, PKPaymentNetwork.amex, PKPaymentNetwork.discover]
let applePayMerchantID = "merchant.com.xxxxxxxxxx.XXXXXXXXXXX"
request.countryCode = "US"
request.currencyCode = "USD"
request.merchantIdentifier = applePayMerchantID
request.supportedNetworks = supportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.capability3DS
let price = Decimal(self.creditsPrice[index])
let priceDecimal = NSDecimalNumber(decimal: price)
request.paymentSummaryItems.append(PKPaymentSummaryItem(label: "for \(self.credits[index]) Credits", amount: priceDecimal))
applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
self.paymentName = self.credits[index]
self.paymentValue = self.creditsPrice[index]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: supportedPaymentNetworks) {
self.present(applePayController, animated: true, completion: nil)
} else {
self.displayAlert(title: "Error", message: "Please setup Apple Pay before trying to purchase credits")
}

Related

How to use pkpaymentsummaryitemtype.pending in ApplePay/Swift?

In my app I need to add pending pay (after user have got some service).
I'm implement apple pay and received token. But I don't get how to make payment with item type pkpaymentsummaryitemtype.pending?
Here is my pay method:
func makePay()
{
let request = PKPaymentRequest()
request.merchantIdentifier = ApplePaySwagMerchantID
request.supportedNetworks = SupportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.capability3DS
request.countryCode = "US"
request.currencyCode = "USD"
request.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Some service", amount: 0, type: PKPaymentSummaryItemType.pending)]
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)!
applePayController.delegate = self
var topVC = UIApplication.shared.keyWindow?.rootViewController
while((topVC!.presentedViewController) != nil) {
topVC = topVC!.presentedViewController
}
topVC?.present(applePayController, animated: true)
}
But when I have to show and debit final amount? I cant find examples of code on swift/IOS.
Or if I understood correct - with that type I just received authorization first and than with received token my bank/payment system will debit final amount after I send it?
Is it correct?

Add Shipping charge in Paypal checkout using Braintree SDK

I am implement the Braintree SDK for payment in my E-Commerce application(iOS and Android).but I am not able to and shipping charge in “BTPayPalRequest”.
How to add Shipping charge in this SDK?
My Code is below:
braintreeClient = BTAPIClient(authorization: “Key”)!
let payPalDriver = BTPayPalDriver(apiClient: braintreeClient)
payPalDriver.viewControllerPresentingDelegate = self
payPalDriver.appSwitchDelegate = self // Optional
// Specify the transaction amount here. "2.32" is used in this example.
let request = BTPayPalRequest(amount: strAmmount)
/// Cart Item
var items = [BTPayPalLineItem]()
for Dict in ArrMyCartDetails{
let item = BTPayPalLineItem(quantity: String(Q), unitAmount: String(SP), name: strProductName, kind: .debit)
items.append(item)
}
request.lineItems = items
request.intent = .sale
request.displayName = AppTitle
request.isShippingAddressRequired = false
request.isShippingAddressEditable = false
request.shippingAddressOverride = BTPostalAddress.init()
request.currencyCode = "AUD"
payPalDriver.requestOneTimePayment(request) { (tokenizedPayPalAccount, error) in
if let tokenizedPayPalAccount = tokenizedPayPalAccount {
print("Got a nonce: \(tokenizedPayPalAccount.nonce)")
} else if error != nil {
// Handle error here...
self.ShowMessage(strMsg: "something wrong in payment process.")
} else {
// Buyer canceled payment approval
self.ShowMessage(strMsg: "you cancel payment!")
}
}

Paypal Payment issue of credit card payment

I have integrate the paypal payment but when i entered the credit card detail on live mode it returns the error-
UNAUTHORIZED_PAYMENT - The merchant does not accept payments of this type. (401)
I am using the business account and permissions are enabled.
var payPalConfig = PayPalConfiguration()
var environment:String = PayPalEnvironmentProduction {
willSet(newEnvironment) {
if (newEnvironment != environment) {
PayPalMobile.preconnect(withEnvironment: newEnvironment)
}
}
}
var acceptCreditCards: Bool = true {
didSet {
payPalConfig.acceptCreditCards = acceptCreditCards
}
}
func paypalPaymentGatewaySetup(){
payPalConfig.acceptCreditCards = acceptCreditCards;
payPalConfig.merchantName = "User"
payPalConfig.merchantPrivacyPolicyURL = NSURL(string: "https://www.paypal.com/webapps/mpp/ua/privacy-full") as URL?
payPalConfig.merchantUserAgreementURL = NSURL(string: "https://www.paypal.com/webapps/mpp/ua/useragreement-full") as URL?
payPalConfig.languageOrLocale = NSLocale.preferredLanguages[0]
payPalConfig.payPalShippingAddressOption = .payPal;
PayPalMobile.preconnect(withEnvironment: environment)
}
override func viewDidLoad() {
super.viewDidLoad()
paypalPaymentGatewaySetup()
}
Now i am calling function makingRequestForPayment on click of make payment button and i have import payment status delegate as well. But in paypal delegate method i am getting "The merchant does not accept this type of payment Unauthorized 401". I did app delegate setup with client ID of Production as well
func makingRequestForPayment(){
// let globalPriceInStr = UserDefaults.standard.value(forKey: "PriceForPayment") as? String ?? ""
let globalPriceInStr = "1"
let totalPrice = NSDecimalNumber(string: globalPriceInStr)
let item1 = PayPalItem(name: "Membership", withQuantity: 1, withPrice: totalPrice, withCurrency: "USD", withSku: "SivaGanesh-0001")
print(item1)
let items = [item1]
print(items)
let subtotal = PayPalItem.totalPrice(forItems: items)
let shipping = NSDecimalNumber(string: "0.00")
let tax = NSDecimalNumber(string: "0.00")
let paymentDetails = PayPalPaymentDetails(subtotal: subtotal, withShipping: shipping, withTax: tax)
let total = subtotal.adding(shipping).adding(tax)
let payment = PayPalPayment(amount: total, currencyCode: "USD", shortDescription: "Advertisement Submission", intent: .sale)
payment.items = items
payment.paymentDetails = paymentDetails
if (payment.processable) {
let paymentViewController = PayPalPaymentViewController(payment: payment, configuration: payPalConfig, delegate: self)
present(paymentViewController!, animated: true, completion: nil)
}
else{
print("Payment not processable: \(payment)")
}
}

Apple pay money not withdraw

We have app in the App Store. When user have pay, the payment is success but money not withdraw from credit card. What can be a problem? Maybe we need add bank information or something like this?
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: supportedPaymentNetworks) {
let request = PKPaymentRequest(
request.merchantIdentifier = "merchant.com.my_app_identifier"
request.merchantCapabilities = .capability3DS
request.countryCode = "RU"
request.currencyCode = "RUR"
request.supportedNetworks = supportedPaymentNetworks
request.paymentSummaryItems = [PKPaymentSummaryItem(label: egrn.name, amount: NSDecimalNumber(value: price))]
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)!
applePayController.delegate = delegate
self.present(applePayController, animated: true, completion: nil)
}

iOS Swift PayPal Always In Sandbox

I have successfully integrated PayPal into my app. However, it seems to be stuck in Sandbox mode. Here is my code to initialize it:
PayPalMobile .initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction: "APP-0XU423690N0796541"])
As can been seen, I'm not even specifying a sandbox ID.
My code to initiate the payment is:
let payPalConfig = PayPalConfiguration()
payPalConfig.merchantName = "MacCrafters Software"
let item1 = PayPalItem(name: "Donation", withQuantity: 1, withPrice: NSDecimalNumber(string: amountField.text!), withCurrency: "USD", withSku: "Donation")
let items = [item1]
let subtotal = PayPalItem.totalPriceForItems(items)
// Optional: include payment details
let shipping = NSDecimalNumber(string: "0.00")
let tax = NSDecimalNumber(string: "0.00")
let paymentDetails = PayPalPaymentDetails(subtotal: subtotal, withShipping: shipping, withTax: tax)
let total = subtotal.decimalNumberByAdding(shipping).decimalNumberByAdding(tax)
let payment = PayPalPayment(amount: total, currencyCode: "USD", shortDescription: "Donation", intent: .Sale)
payment.items = items
payment.paymentDetails = paymentDetails
if (payment.processable) {
let paymentViewController = PayPalPaymentViewController(payment: payment, configuration: payPalConfig, delegate: self)
presentViewController(paymentViewController!, animated: true, completion: nil)
}
At the bottom of the PayPal view it always says "Mock Data". I get the same results no matter if I'm in the simulator or on a device. What am I doing wrong?

Resources