I'm trying to integrate Salesforce and Stripe using Cirrus Path's Stripe SDK (https://github.com/cirruspath/stripeforce). I've successfully installed all of the Apex classes and other elements of their package. But, now I am trying to figure out how to actually call, presumably, a class which will call their API via REST in a Visualforce page (to create a customer and charge). I've done this through PHP, so I understand what needs to happen behind the scenes, but just haven't done this through Salesforce/the REST api yet.
The class designated as a @RestResource is based on this example:
@RestResource(urlMapping='/createCustomer/*')
global class CustomRestService {
@HttpPost
global static ResponseData createCustomer() {
String json = RestContext.request.requestBody.toString();
RequestPayload payload = (RequestPayload) System.JSON.deserialize(json, RequestPayload.class);
StripeCustomer customer = StripeCustomer.create(payload.token, payload.description);
StripeCustomer.updateSubscription(customer.id, 'ANNUAL_SUBSCRIPTION');
// Update the existing account to include the Stripe Customer ID
Account a = new Account(
Id = payload.accountId,
Stripe_Customer_ID__c = customer.id
);
update a;
ResponseData data = new ResponseData();
data.status = 'success';
return data;
}
global class RequestPayload {
global String token;
global String description;
global String accountId;
}
global class ResponseData {
global String status;
global String errorMessage;
}
}
The Visualforce page, containing the Stripe Checkout code is below:
<apex:page controller="CustomRestService">
<form action="https://cs16.salesforce.com/services/apexrest/createCustomer" method="POST">
<script
*** stripe checkout script ***
</script>
</form>
When I submit the form, I'm seeing an error that says there was an invalid session Id. What am I missing? Am I completely confusing myself and going about this the wrong way? Any help would be greatly appreciated!