I am trying to integrate Apple Pay in iOS using flutter. I am using method channels to communicate with swift and get the payment process completed. I have followed the documentation which is in this link
However, I believe I have stuck in the very ending part which I don't understand how to continue the flow. Since I am using flutter UIs, I don't need iOS ViewControllers.
This is the code that I have tried so far in the AppDelegate.swift:
func handleApplePayButtonTapped(result: FlutterResult){
let merchantIdentifier = "my.apple.merchant.id"
let paymentRequest = Stripe.paymentRequest(withMerchantIdentifier:merchantIdentifier, country:"US", currency:"USD")
paymentRequest.paymentSummaryItems = [
PKPaymentSummaryItem(label:"Fancy Hat", amount:50.00),
PKPaymentSummaryItem(label:"iHats, Inc", amount:50.00),
]
if Stripe.canSubmitPaymentRequest(paymentRequest){
//next steps ???
result(String("Can submit payment request"))
}else{
result(String("Can't submit payment request"))
}
}
I am calling this code in flutter UI using this code:
Future<void> _doPayment() async {
String returnMsg;
try {
final bool result = await platform.invokeMethod('checkIfDeviceSupportsApplePay');
if(result){
final String status = await platform.invokeMethod('handleApplePayButtonTapped');
print(status);
}
returnMsg = '$result';
} on PlatformException catch (e) {
returnMsg = "Failed: '${e.message}'.";
}
print(returnMsg);}
I already have a Stripe publishable key as well as a Heroku deployed backend. If you checked my swift code, you will see where I am stuck at the moment.
As I have understood the flow, what is remaining to be done is
send the card details to the backend and get a token
using the token, send the payment details to the Stripe server
I am very new to swift language and code samples will be greatly helpful for me to continue with.
Thank you.
It looks like you're following the Stripe Custom iOS Integration, using the native PKPaymentAuthorizationViewController.
You should read through the integration steps here: https://stripe.com/docs/mobile/ios/custom#apple-pay
Basically, your next steps would be
instantiate a PKPaymentAuthorizationViewController with the paymentRequest
Set yourself to its delegate
present the PKPaymentAuthorizationViewController
implement the relevant delegate methods to get back an Apple Pay token (PKToken)
convert PKToken to STPToken (a Stripe token)
All these steps and more are detailed in the link above.
Related
I try to integrate google drive into my app to list mp3, m4a music files. Now I have made Google sign working, means I could signIn and signOut google account.
But when I follow google's api doc to this step Make an API call with fresh tokens, I got above error on line let authorizer = authentication.fetcherAuthorizer(). This function fetcherAuthorizer is not found.
I think maybe this doc is not up to date with latest google sdk. So I did a few search on Google...then it appears there is really rare stuff about this topic. What I found is all used this same code authentication.fetcherAuthorizer().
Thus, guys. Is there any update about this code?
user.authentication.do { authentication, error in
guard error == nil else { return }
guard let authentication = authentication else { return }
// Get the access token to attach it to a REST or gRPC request.
let accessToken = authentication.accessToken
// Or, get an object that conforms to GTMFetcherAuthorizationProtocol for
// use with GTMAppAuth and the Google APIs client library.
let authorizer = authentication.fetcherAuthorizer()
}
Today, I find the answer in this thread googlesignin-ios
The reason is Swift cannot find the fetcherAuthorizer from Objective-C library, we must manually import it import GTMSessionFetcher.
I'm using Firebase PhoneAuth to authenticate users. I have done all the integrations as per instructions from reliable sources on the net.
The error that I'm facing is that, I'm not receiving call back for the code sent handler in verifyPhoneNumber method of Firebase Auth.
Here is methods used, once the user enters the phone number, the signInWithPhone() is called which in turn calls the verifyPhoneNumber().
Future<AuthUser> signInWithPhone(String phone) async {
await _firebaseAuth.verifyPhoneNumber(
phoneNumber: phone,
timeout: Duration(seconds: 60),
verificationCompleted: _phoneVerificationCompleted,
verificationFailed: _phoneVerificationFailed,
codeSent: _phoneCodeSent,
codeAutoRetrievalTimeout: _phoneCodeAutoRetrievalTimeout);
print("Phone Authentication Ended");
return null;
}
_phoneCodeSent(String verificationId, [int forceResendingToken]) async {
phoneVerificationId = verificationId;
}
Here the _phoneCodeSent() should get called when the otp has been sent. The verificationId received in this method is required for authentication purpose. Since the function doesn't get invoked I'm not receiving the verificationId but the otp is getting generated.
Any help will be appreciated.
Please make sure that you have followed these docs of firebase integration with flutter,
https://firebase.flutter.dev/docs/installation/ios
And iOS Specific setup as per this https://firebase.flutter.dev/docs/auth/phone#setup along with 4 specific handlers.
I am implementing braintree on IOS Client in order to receive payments through credit cards and PayPal
But whenever I tap on PayPal it takes times to open it on browser, so in this mean time I want to show Loader so user can't feel any thing weird.
I am unable to find any delegate methods of BTDropInController which allow me to show loader when user press PayPal option.
Thanks in advance.
Happy Coding :)
You need to start your activity indicator when you call paypal request from braintree. Below is the code for your reference:
SVProgressHUD .show(withStatus: "Proccessing")
let payPalRequest = BTPayPalRequest(amount: "1.20")
payPalRequest.currencyCode = "USD"
payPalRequest.landingPageType = .default
payPalRequest.intent = .authorize
payPalDriver.requestOneTimePayment(payPalRequest) { (tokenizedPayPalAccount, error) -> Void in
if let tokenizedResult = tokenizedPayPalAccount{
print("Get a nonce: \(tokenizedResult)")
SVProgressHUD .dismiss()
}
}
How do I use plivo SMS API in my iOS app using Swift. I read lot of documentation regarding this. I'm not sure how to implement it on swift.
var plivo = require('plivo');
var p = plivo.RestAPI({
authId: 'Your AUTH_ID',
authToken: 'Your AUTH_TOKEN'
});
var params = {
'src': '1111111111', // Sender's phone number with country code
'dst' : '2222222222', // Receiver's phone Number with country code
'text' : "Hi, text from Plivo", // Your SMS Text Message - English
//'text' : "こんにちは、元気ですか?", // Your SMS Text Message - Japanese
//'text' : "Ce est texte généré aléatoirement", // Your SMS Text Message - French
'url' : "http://example.com/report/", // The URL to which with the status of the message is sent
'method' : "GET" // The method used to call the url
};
// Prints the complete response
p.send_message(params, function (status, response) {
console.log('Status: ', status);
console.log('API Response:\n', response);
console.log('Message UUID:\n', response['message_uuid']);
console.log('Api ID:\n', response['api_id']);
});
The above code is in Node.js, I want it to write in swift, and also I'm not sure how to integrate plivo into iOS app. I'm developing an app where it should send a sms to admin whenever user requests an order. So I just want the outgoing message from Plivo to admin. Any suggestions is really helpfull.
Plivo Sales Engineer here. Our recommendation is to host a server to which your iOS app would make a request to send the SMS. Then your server can use a Plivo helper library to make the API request which would send the SMS. This way your AuthID and AuthToken are stored on your server (to which only you have complete access) and you don't expose your Plivo credentials in your iOS app.
If you make a direct request of the Plivo API from your iOS app, then users potentially could find and misuse your credentials.
tl;dr - don't put your authentication credentials in places other people can read it.
So without a helper library you will have to just make use of their REST API. From their site, sending an SMS can be done by POSTing your information to
https://api.plivo.com/v1/Account/{auth_id}/Message/
As for the Swift part take a look at NSMutableURLRequest or if you need help with the networking request you can look at Alamofire
If you want to use Rest API you can do like this:
lazy var plivoRestAPI: PlivoRest = {
let rest = PlivoRest(authId: Constants.Credentials.Plivo.AuthId,
andAuthToken: Constants.Credentials.Plivo.AuthToken)!
rest.delegate = self
return rest
}()
let params = ["to": phoneNumberToCall,
"from": "1111111111",
"answer_url": "",
"answer_method": "GET"]
plivoRestAPI.callOutbound(params)
I am coding an IOS app with Payment feature.
I decided to use Braintree V Zero.
At the very beginning, I use their excellent DropIn UI feature, and everything works fine.
But when payment happen, the Drop In UI required end-user to input his credit card or Paypal information every time.
Does any expect know how to implement one automatic charge solution by BrainTree V zero?
Like Uber's charge solution.
I guess maybe need to mark the user's credit card information from app side or service side?
router.get('/token', function (req, res) {
console.log('Kevin in token be called %s', req.param('aCustomerId'));
var aCustomerId = req.param('aCustomerId');
console.log('Kevin %s', aCustomerId);
gateway.clientToken.generate({customerId: aCustomerId}, function (error, response) {
res.send(response.clientToken);
console.log(response.clientToken);
});
});
Thank you in advanced!
Full disclosure: I work for Braintree.
The Braintree drop-in will display previously used payment methods for a customer, if you pass the customer_id in when generating a client token on your server.
Here's an example of how to do it in Node:
gateway.clientToken.generate({
customerId: aCustomerId
}, function (err, response) {
var clientToken = response.clientToken
});
Once a payment method is used, it will be saved in the drop-in and the customer will not have to enter it again. Pass the token of the saved payment method when creating a transaction:
gateway.transaction.sale({
amount: "10.00",
paymentMethodToken: theToken,
options: {
submitForSettlement: true
}
}, function (err, result) {
});
If you have any further questions, please feel free to contact Braintree support.
3133e