Last active
December 23, 2015 23:29
-
-
Save aydiv/6710668 to your computer and use it in GitHub Desktop.
Save a credit card using PayPal's REST APIs. Code snippet uses the rest-api-sdk-java SDK from PayPal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.paypal.api.payments.CreditCard; | |
import com.paypal.core.rest.APIContext; | |
import com.paypal.core.rest.PayPalRESTException; | |
import java.util.HashMap; | |
CreditCard cc = new CreditCard(); | |
cc.setExpireMonth(11) | |
.setExpireYear(2018).setFirstName("Joe") | |
.setLastName("Shopper").setNumber("4111111111111111").setType("visa") | |
.setCvv2("874"); | |
// Collect configuration values for the API call. | |
Map<String, String> configurationMap = new HashMap<String, String>(); | |
configurationMap.put("service.EndPoint", "http://api.mydomain.com"); | |
try { | |
// Create an APIContext with optional OAuth access token for API calls | |
// that require authentication. | |
String accessToken = new OAuthTokenCredential("clientID", "clientSecret").getAccessToken(); | |
APIContext apiContext = new APIContext(accessToken); | |
// Carry out the create credit card API operation. | |
CreditCard creditCard = cc.create(apiContext); | |
} catch (PayPalRESTException exe) { | |
// Handle Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment