Register transactions from your backend

This feature allows you to register transactions on your backend instead of in the app. Use this if you'd like your backend to initiate the transaction, e.g. because of architectural reasons. You'll receive a sessionIdentifier that you can send down to your app, and then execute the transaction from the app. Use WebHooks to keep your backend informed about the status of the transaction.

Register a Charge Transaction from your backend

Before there's anything to pay, your app will most likely be offering some sort of checkout functionality: Information about the purchased items will be transmitted to your backend and your backend will then be able to determine the final amount to be charged.

You will use this information to register a new transaction via an API call to the platform:

post /v2/merchants/{merchantIdentifier}/transactionSessions Try it out! Request
{
	"transaction" : {
		"amount": 123.34,
		"currency": "EUR",
		"type": "CHARGE",
		"subject": "My subject",
		"customIdentifier": "My custom identifier"
	}
}

Important Parameters:

$.transaction.amount
The amount of money that is about to be charged.
$.transaction.currency
The currency used for the transaction.
$.transaction.type
Use CHARGE to receive money from the shopper.
$.transaction.customIdentifier
An identifier that you can assign to the transaction.

The response body will look something this this:

Response
{
	"status": "ok",
	"data": {
		"validUntil": "2013-09-03 11:18:34",
		"identifier": "0f487dc3-35cd-4125-8b82-631c7d5b328c",
		"transaction": {
			"identifier": "3fe8fe7c-b620-4b45-b128-545b8c16f236",
			"customIdentifier": "1234",
			"status": "INITIALIZED",
			"subject":  "My subject",
			"groupIdentifier": "59b57c79-7a04-4e68-9bc1-78dbf71adf32",
			"processingDetails": {…},
			"receiptDetails": {…},
			"type": "CHARGE",
			"paymentDetails": {…},
			"locationDetails": {…},
			"currency": "EUR",
			"mode": "TEST",
			"amount": 123.34,
			"created": "2013-09-03 11:03:34",
			"statusDetails": {…},
			"reader": {…}
		}
	}
}

Among various other information about the transaction, the response body contains two important identifiers:

$.data.identifier
This is the sessionIdentifier that should be returned by you to the app. The app will then use this identifier to start processing the transaction from the mobile device.
$.data.transaction.identifier
The transactionIdentifier should be kept by your backend as a reference to the just registered transaction. It can then be used to do different things such as querying the platform to fetch the current status of a transaction or to cancel the transaction if necessary.

Complete the Transaction in the app with the PayButton

On iOS, provide the sessionIdentifier to createTransactionViewControllerWithSessionIdentifier:

[ui createTransactionViewControllerWithSessionIdentifier:@"sessionIdentifier"
                                               completed:^(UIViewController *controller,
                                                           MPUTransactionResult result,
                                                           MPTransaction *transaction)
{
    if (result == MPUTransactionResultApproved) {
        // Payment was approved!
    } else {
        // Payment was declined/aborted!
    }
}];

On Android, provide the sessionIdentifier to createTransactionIntent:

Intent intent = ui.createTransactionIntent(sessionIdentifier);

Complete the transaction in the application if you are using the SDK Integration

Once you have a sessionIdentifier, you can execute the transaction from the app. For iOS, use

[transactionProvider startPaymentWithSessionIdentifier: /* put your sessionIdentifier here! */  ...];

For Android, use

transactionProvider.startPayment(/* put your sessionIdentifier here! */, ...);
How to handle the callbacks of these methods is described here.

Register a Refund Transaction

You'll only need this if you do card present refunds. For card not present refunds there is a different API call.

To refund a previous charge transaction, register a refund transaction and pass the transactionIdentifier of the charge transaction as the referencedTransactionIdentifier. Provide the exact same amount and currency.

post /v2/merchants/{merchantIdentifier}/transactionSessions Try it out! Request
{
	"transaction" : {
		"referencedTransactionIdentifier": "3fe8fe7c-b620-4b45-b128-545b8c16f236",
		"amount": 123.34,
		"currency": "EUR",
		"type": "REFUND",
		"mode": "TEST",
		"subject": "My Refund"
	}
}	

Important Parameters:

$.transaction.referencedTransactionIdentifier
The transactionIdentifier of the previous charge transaction.
$.transaction.amount
The amount of money that is about to be refunded.
$.transaction.currency
The currency used for the transaction.
$.transaction.type
Use REFUND to send money to the shopper.
$.transaction.mode
Use TEST on the test platform, use LIVE on the live platform.

Can we help you?

If you cannot find your answer, contact us and we'll get in touch with you soon.

© Copyright 2017 Payworks GmbH. Legal.