Skip to main content

Posts

Showing posts from July, 2016

My Favourite iOS Development Bugs

There are some things in iOS development that can really catch you out the first time you encounter them and recently I was inspired to make a list as and when I remember them. This means that I will add to this post over time as I recall things. I begin with two issues. The first is a common issue on StackOverflow.
1. NSUserDefaults not storing values When testing something it is common to throw everything in viewDidLoad: but the problem in the case of NSUserDefaults is that it stores information asynchronously and so if you try and immediately retrieve what you have just stored then it usually isn't there. The solution is to delay the retrieval, using for example a button that triggers the retrieval later for testing purposes. Or synchronise() the user defaults.
2. UIDocumentInteractionController crashes my app when I try to open a file in another app When using a UIDocumentInteractionController it is very important to maintain a reference to the controller instance. If releas…

Adventures in PayPal: Executing the sale

In order to execute the sale you'll have a return page setup where PayPal redirects to after the customer has paid. Since the user is going away from the page and returning to either the same one or a new one you need to find a way of storing the access token so that you can use this again for execution.

While it's true that you can simply create a new access token, and this will be equally valid for performing the execution, what you are meant to do is to use access tokens until their expiry (which occurs 8–9 hours after their creation). So in all likelihood the access token will be active when the user returns from PayPal.

To address this it is possible to store the token as a cookie or in session storage. Session storage keeps the data on the server and cookies save to the user's machine. So session storage seems like the obvious choice.

To perform this we need to add a two lines of code to the original call to retrieve the PayPal access token. First we need to start …

Adventures in PayPal: Missing amount and items

The sample code included here will enable you to make a charge through PayPal for a certain amount but unless you provide a breakdown of the items being purchased then the fee being charged and the items within that charge won't be displayed.
<?php // http://stackoverflow.com/questions/15729167/paypal-api-with-php-and-curl // https://github.com/paypal/adaptivepayments-sdk-php/issues/24 // https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php // http://stackoverflow.com/questions/15885742/pay-with-paypal-through-paypal-rest-api-does-not-show-up-payment-description-on // Full payment capabilities // https://developer.paypal.com/docs/integration/direct/explore-payment-capabilities/ $host = 'https://api.sandbox.paypal.com'; $clientId = 'Replace with your clientId'; $secret = 'Replace with your secret'; $token = ''; function get_access_token($url, $postdata) { global $clientId, $clientSecret; $curl = curl_init($url); …

Adventures in PayPal: First steps to gaining an access token using the REST API

Spoiler alert: if you've come here to find a solution on how to use the PayPal API with MAMP, then I apologise in advance that I can't be of help. I can only report the issues that I encountered when testing its compatibility.
To begin So I've been dabbling in PayPal's REST APIs and have found that while using cURL from the OS X/macOS terminal is straightforward getting this stuff working on my hosted website wasn't as straightforward without piecing together some code from around the web. I'm not going to go through the steps of setting up a sandbox client id and secret here, for that you need to go over to http://developer.paypal.com. I am also not going to tackle the subject of setting up the necessary PayPal account for utilising the API. Neither am I going to enter into how you obtain SSL certificates. Here I'll be dealing with the real world hurdles of code being placed on your website that is going to work. And this is going to be reported as I go a…