Integrated Paytm sdk 2.1 in iOS (Xcode 7) and configured to make payment .
I have a form in which amount and other fields need to filled then there is a button for Payment .
Here is code which i am using :
//Step 1: Create a default merchant config object
PGMerchantConfiguration *mc = [PGMerchantConfiguration defaultConfiguration];
//Step 2: If you have your own checksum generation and validation url set this here. Otherwise use the default Paytm urls
mc.checksumGenerationURL = #"generate checksum url";
mc.checksumValidationURL = #"checksum validation url";
//Step 3: Create the order with whatever params you want to add. But make sure that you include the merchant mandatory params
NSMutableDictionary *orderDict = [NSMutableDictionary new];
//Merchant configuration in the order object
orderDict[#"MID"] = #"abc1111";
orderDict[#"CHANNEL_ID"] = #"WAP";
orderDict[#"INDUSTRY_TYPE_ID"] = #"Education";
orderDict[#"WEBSITE"] = #"companyname";
//Order configuration in the order object
orderDict[#"TXN_AMOUNT"] = #"100";
orderDict[#"ORDER_ID"] = [Feepayment generateOrderIDWithPrefix:#"111"];
orderDict[#"REQUEST_TYPE"] = #"DEFAULT";
orderDict[#"CUST_ID"] = #"abc7777";
PGOrder *order = [PGOrder orderWithParams:orderDict];
//Step 4: Choose the PG server. In your production build dont call selectServerDialog. Just create a instance of the
//PGTransactionViewController and set the serverType to eServerTypeProduction
[PGServerEnvironment selectServerDialog:self.view completionHandler:^(ServerType type)
{
PGTransactionViewController *txnController = [[PGTransactionViewController alloc] initTransactionForOrder:order];
//show title var
UIView *mNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
mNavBar.backgroundColor = [UIColor grayColor];
txnController.topBar = mNavBar;
//Cancel button
UIButton *mCancelButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 70, 40)];
[mCancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
mCancelButton.titleLabel.textColor = PURPLE_COLOR;
[mCancelButton setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
txnController.cancelButton = mCancelButton;
//add title
UILabel *mTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 10, 1, 100, 50)];
[mTitleLabel setText:#"Payment"];
[mTitleLabel setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
mTitleLabel.textColor = [UIColor whiteColor];
[mNavBar addSubview:mTitleLabel];
if (type!=eServerTypeNone) {
txnController.serverType = type;
txnController.merchant = mc;
txnController.loggingEnabled = YES;
txnController.sendAllChecksumResponseParamsToPG = YES;
txnController.delegate = self;
[self showController:txnController];
}
}];
//show controller method
-(void)showController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController pushViewController:controller animated:YES];
else
[self presentViewController:controller animated:YES
completion:^{
}];
}
//remove controller
-(void)removeController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController popViewControllerAnimated:YES];
else
[controller dismissViewControllerAnimated:YES
completion:^{
}];
}
#pragma mark PGTransactionViewController delegate
- (void)didSucceedTransaction:(PGTransactionViewController *)controller
response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didSucceedTransactionresponse= %#", response);
NSString *title = [NSString stringWithFormat:#"Your order was completed successfully. \n %#", response[#"ORDERID"]];
[[[UIAlertView alloc] initWithTitle:title message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFailTransaction:(PGTransactionViewController *)controller error:(NSError *)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFailTransaction error = %# response= %#", error, response);
if (response)
{
[[[UIAlertView alloc] initWithTitle:error.localizedDescription message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
else if (error)
{
[[[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
[self removeController:controller];
}
- (void)didCancelTransaction:(PGTransactionViewController *)controller error:(NSError*)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didCancelTransaction error = %# response= %#", error, response);
NSString *msg = nil;
if (!error) msg = [NSString stringWithFormat:#"Successful"];
else msg = [NSString stringWithFormat:#"UnSuccessful"];
[[[UIAlertView alloc] initWithTitle:#"Transaction Cancel" message:msg delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFinishCASTransaction:(PGTransactionViewController *)controller response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFinishCASTransaction:response = %#", response);
}
Here is screenshot while using staging directly showing this page :
*Note - Actually i am trying for staging not for production .
When i execute then it doesnt showing Paytm feepayment form instead it showing orderid and amount with transaction id dirctly .
How to open Paytm payment form when user enter fee amount in the form then it should calcualte the amount with extraa tax and then clicking on Fee payment button it should open PAYTM PAYMENT FORM.
PLEASE HELP ME TO SOLVE THIS PROBLEM ( I HAVE GO THROUGH THE PAYTM SDK DOC STEP BY STEP BUT DINT ABLE TO FIND IT ).
THANKS.
Important : **As far as checksumGenerationURL and checksumValidationURL is concerned , we need to create it . Initially i tried to use from Paytm but it dint work so finally our server team did it , this is most important point for Integrating Paytm
Finally , Solved by testing it on the Production and its working fine . As far as Staging server is concerned i guess there is hard coded information is in the sdk so hope in the next version of PGSDK we could test it on Staging too.
Thanks .
#Pradeep k ... thank you very much for all your valuable support .
Have you populated the mc.checksumGenerationURL and mc.checksumValidationURL properly? Also there is a 2.7 version of the SDK that you should be using. Ask your Paytm contact point for the latest iOS SDK.
Now about the amount, Paytm does not calculate the tax. You have to add it to the amount that you are sending to Paytm.
Related
I am new to Xcode I need an app to send a email. Background: the destination email Id is typed in a text and by clicking the send button the message body Sample should go to the destination Email ID I tried this code in the function button clicked but it is not working when ever i try this code I get error in function can any one guide me with a step by step tutorial
mailTransfer[673:207] delegate - error(-5): timeout sending message
2014-07-05 10:54:05.393 mailTransfer[673:207] * stopping watchdog * I had added the SMTP files from google documents ... any other way to correct this code
- (IBAction)sendMessageInBack:(id)anObject
{
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = #"Yours mail ids";
testMsg.toEmail = emailField.text;
testMsg.relayHost = #"smtp.gmail.com";
testMsg.requiresAuth = YES;
testMsg.login = #"Your mail ids";
testMsg.pass = #"id password";
testMsg.subject = #"Test application ";
testMsg.wantsSecure = YES;
testMsg.delegate = self;
NSDictionary *plainPart = [NSDictionarydictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,#"Sample",kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];
[testMsg send];
}
-(void)messageSent:(SKPSMTPMessage *)message{
[message release];
NSLog(#"delegate - message sent");
}
-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{
[message release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Unable to send email" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
NSLog(#"delegate - error(%d): %#", [error code], [error localizedDescription]);
}
in SKPSMTPMessage.m
update the following line
CFDictionarySetValue(sslOptions,kCFStreamSSLLevel,kCFStreamSocketSecurityLevelTLSv1);
with
CFDictionarySetValue(sslOptions, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelSSLv3);
Download SMTP framework and import SKPSMTPMessage class..
#import "SKPSMTPMessage.h"
-(void)sendEmailVideo:(NSString*)_toEmailAddress andCC:(NSString*)ccEmail
{
#try
{
// Message =[data getContentOfPanic];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
SKPSMTPMessage *emailMessage = [[SKPSMTPMessage alloc] init];
emailMessage.fromEmail=#"nikki.varsha#gmail.com";//sender email address
emailMessage.toEmail=_toEmailAddress;
//receiver email address
emailMessage.relayHost=#"smtp.gmail.com";
//emailMessage.ccEmail =ccEmail;
emailMessage.requiresAuth = YES;
emailMessage.login = #"nikki.varsha#gmail.com"; //sender email address
emailMessage.pass = #"123";
//sender email password
emailMessage.subject =#"Panic Video Message";
emailMessage.wantsSecure = YES;
emailMessage.delegate = self;
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
Message,kSKPSMTPPartMessageKey,#"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];
NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"Video.mov\"",kSKPSMTPPartContentTypeKey,
#"attachment;\r\n\tfilename=\"Video.mov\"",kSKPSMTPPartContentDispositionKey,[webData encodeBase64ForData],kSKPSMTPPartMessageKey,#"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
emailMessage.parts=[NSArray arrayWithObjects:plainPart,vcfPart,nil];
dispatch_queue_t backgroundVideoQueue = dispatch_queue_create("com.VideoQue", 0);
dispatch_sync(backgroundVideoQueue, ^{
[emailMessage send];
});
}
#catch (NSException *exception)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No Host" message:#"No Reciever Email Ids Available! " delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}
}
pragma mark - sendEmail delegate (SKPSMTPMessage)
-(void)messageSent:(SKPSMTPMessage *)message
{
NSLog(#"delegate - Email sent");
NSLog(#"Mesg %#",message);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Email sent." message:nil delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
}
-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"err=%#" ,message);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Unable to send email Please Check EmailId & Password"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
});
}
in SKPSMTPMessage.m file do change the following line
Remove this line
//CFDictionarySetValue(sslOptions,kCFStreamSSLLevel,kCFStreamSocketSecurityLevelTLSv1);
Add this line
CFDictionarySetValue(sslOptions, kCFStreamSSLLevel, kCFStreamSocketSecurityLevelSSLv3);
Thanks
I am trying to display my friends from Facebook in my app in a UITableView. However, my TableView is staying empty. Here is my code for pulling up the UITableView.
-(IBAction)testfriends {
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *innerSender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString *message;
if (friendPickerController.selection.count == 0) {
message = #"<No Friends Selected>";
} else {
NSMutableString *text = [[NSMutableString alloc] init];
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in friendPickerController.selection) {
if ([text length]) {
[text appendString:#", "];
}
[text appendString:user.name];
}
message = text;
}
[[[UIAlertView alloc] initWithTitle:#"You Picked:"
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
}];
}
What am I missing here? It is taken straight from the Facebook Sample, but even in the sample app, it won't work.
As of 4/30/2014, with the launch of the Graph API v2.0, you'll need to request the user_friends permission and you will only receive friends who also use the app.
I am using latest Paypal SDK for iOS, trying to test login and payment transaction in sandbox environment. I have already created a business account in Sandbox test accounts page. So I have a user email, password and a signature. But I am unable to login using those credentials. I get following error in response:
PayPal SDK: Request has failed with error: invalid_user - Incorrect username/password. Please try again. (401) | PayPal Debug-ID: c3dd83c83d43e | Details: (
{
"error_description" = "Invalid user credentials";
}
).
I am unable to understand the reason for invalid credentials. What credentials I must use in order to login sandbox account from iOS SDK? Or am I missing something in my code?
Code
- (void)viewDidLoad
{
//paypal setup
// Set up payPalConfig
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = YES;
_payPalConfig.languageOrLocale = #"en";
_payPalConfig.merchantName = #"Merchant nmae";
_payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/privacy-full"];
_payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:#"https://www.paypal.com/webapps/mpp/ua/useragreement-full"];
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
self.environment = PayPalEnvironmentSandbox;
self.payPalConfig.acceptCreditCards = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Preconnect to PayPal early
[PayPalMobile preconnectWithEnvironment:self.environment];
}
- (IBAction)makePayment:(UIButton *)sender {
if([self.amount.text isEqualToString:#""])
{
[[[UIAlertView alloc] initWithTitle:#"Message" message:#"Please enter amount to proceed" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
return;
}
self.resultText = nil;
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = [[NSDecimalNumber alloc] initWithString:self.amount.text];
payment.currencyCode = #"GBP";
payment.shortDescription = #"Payment for Web77";
if (!payment.processable) {
// This particular payment will always be processable. If, for
// example, the amount was negative or the shortDescription was
// empty, this payment wouldn't be processable, and you'd want
// to handle that here.
[[[UIAlertView alloc] initWithTitle:#"Message" message:#"Payment is unprocessable" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
return;
}
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfig delegate:self];
[self presentViewController:paymentViewController animated:YES completion:nil];
}
#pragma mark PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(#"PayPal Payment Success!");
self.resultText = [completedPayment description];
[[[UIAlertView alloc] initWithTitle:#"Message" message:#"Please enter amount to proceed" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
NSLog(#"PayPal Payment Canceled");
self.resultText = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark Proof of payment validation
- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
// TODO: Send completedPayment.confirmation to server
NSLog(#"Here is your proof of payment:\n\n%#\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
}
Note: I have already initialized PayPalMobile with paypal client ID for sandbox environment.
Side Question:
What should merchantName contain? Should it be same as mentioned on paypal site?
#engr-anum does this information help?
While testing your app, when logging in to PayPal in the SDK's UI you should use a personal Sandbox account email and password. I.e., not your Sandbox business credentials.
You can create both business and personal Sandbox accounts on the Sandbox accounts page.
Regarding merchantName: As you'll see in the header file's comments for this property, merchantName applies only when you are using a PayPalFuturePaymentViewController. It is not relevant for a PayPalPaymentViewController.
Every time I try to save my NSManagedObjectContex, it takes 1-8 seconds each time. Here is my code:
- (IBAction)save
{
if (self.managedObjectContext == nil) {
self.managedObjectContext = [(RootAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
if (self.brandText.text.length == 0 || self.modelText.text.length == 0) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Please fill out the required fields" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(125, 40, 31, 7)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"bullet.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[alertView addSubview:imageView];
[alertView show];
} else {
Hand *a = [NSEntityDescription insertNewObjectForEntityForName:#"Hand" inManagedObjectContext:self.managedObjectContext];
a.brand = self.brandText.text;
a.caliber = self.cText.text;
self.managedObjectContext = self.app.managedObjectContext;
a.notes = self.notesView.text;
a.serialNumber = self.serialNumberText.text;
a.nickname = self.nicknameText.text;
a.model = self.modelText.text;
a.gunImage = self.image.image;
a.roundsFired = [NSString stringWithFormat:#"0"];
a.cleanRounds = [NSString stringWithFormat:#"500"];
a.showBadge = [NSNumber numberWithBool:YES];
[self dismissViewControllerAnimated:YES completion:nil];
NSError *error;
if (![self.managedObjectContext save:&error]) {
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"There was an internal error. \n Please restart the app and try again, Thank You" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[errorAlert show];
}
}
}
The code just saves the all of the textFields text. What is the reason its so slow? Any help is greatly appreciated.
Based on your question is quite difficult to understand what is going on but I would modify the else statement as follows...
else {
Hand *a = [NSEntityDescription insertNewObjectForEntityForName:#"Hand" inManagedObjectContext:self.managedObjectContext];
a.brand = self.brandText.text;
a.caliber = self.cText.text;
// why this?
// self.managedObjectContext = self.app.managedObjectContext;
a.notes = self.notesView.text;
a.serialNumber = self.serialNumberText.text;
a.nickname = self.nicknameText.text;
a.model = self.modelText.text;
a.gunImage = self.image.image;
a.roundsFired = [NSString stringWithFormat:#"0"];
a.cleanRounds = [NSString stringWithFormat:#"500"];
a.showBadge = [NSNumber numberWithBool:YES];
NSError *error;
if (![self.managedObjectContext save:&error]) { // error during saving
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"There was an internal error. \n Please restart the app and try again, Thank You" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[errorAlert show];
} else { // the save completes correctly, dismiss the view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
}
If you want to monitor Core Data you should do it through Instrument. In addition you could set up Xcode as follows: XCode4 and Core Data: How to enable SQL Debugging.
Edit
Since the slow saving is due (based on your comment) to images, you should relies on these rules.
Core Data - Storing Images (iPhone)
Edit 2
Ok, since you don't know in advance about the size (in bytes) of your image, I really suggest to store the image in the filesystem and not in the Core Data store. In the db save only the path to your image. The image will be saved in background. This to prevent the UI to block.
Otherwise, if iOS 5 is the minimum requirement, use the External Storage flag.
How to enable External Storage for Binary Data in Core Data
Hope that helps.
I got app, which can send twits.
I do it in this way:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"])
[tweet addImage:dream.image];
NSString *twitMsg = [dreamField.text stringByAppendingString:#" send via Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
//can't tweet!
}
}
What should i do when [TWTweetComposeViewController canSendTweet] is equal to NO ? And when it is equal to NO ?
That is full solution code:
- (IBAction)twitDream:(id)sender
{
if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweet =
[[TWTweetComposeViewController alloc] init];
if (dream.image != [UIImage imageNamed:#"blank-photo.png"]) {[tweet addImage:dream.image];}
NSString *twitMsg = [dreamField.text stringByAppendingString:#" #Dreamer"];
[tweet setInitialText:twitMsg];
[self presentModalViewController:tweet animated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Sorry"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}