So we have implemented the Paymill subscriptions in our app. The problem is that after the user submits his credit card info and we create the subscription on the back-end, the first transaction isn't made immediately. Only after a few minutes, we receive the first subscription.succeeded web-hook denoting the first transaction. It gets the job done, but how can we get the first transaction at the same time as we create the subscription? Through pre-authorization?
The thing is, there isn't much info on the Paymill website, nor in the API docs regarding use cases like this one.
You are right a Webhook does not allow you to get an instant response for your API call.
However, you can get an instant response by creating a transaction:
curl https://api.paymill.com/v2.1/transactions \
-u <YOUR_PRIVATE_KEY>: \
-d "amount=4200" \
-d "currency=EUR" \
-d "payment=<CLIENT_PAYMENT>" \
-d "client=<YOUR_CLIENT>" \
-d "description=Transaction"
The transaction response is instantly given back to your server which allows you to inform your customer without delay.
If the transaction is successful you also want to debit your customer in the future by creating a subscription:
curl https://api.paymill.com/v2.1/subscriptions \
-u <YOUR_PRIVATE_KEY>: \
-d "client=<YOUR_CLIENT>" \
-d "payment=<CLIENT_PAYMENT>" \
-d "amount=4200" \
-d "currency=EUR" \
-d "interval=1 week,monday" \
-d "name=Example Subscription" \
-d "period_of_validity=2 YEAR" \
-d "start_at=<SUBSCRIPTION_STARTING_DATE"
The start_at parameter needs to contain the date when the subscription starts(future):
current_date + subscription_interval(E.g. 1 week)
If this parameter is not set you will charge the credit card of your customer twice on the same date!