Skip to content

Commit 50ea899

Browse files
committed
Updated usage details in README
1 parent e125ce8 commit 50ea899

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,61 @@ The Opayo (formerly SagePay) Form Integration Library for JavaScript is a librar
1414
npm install opayo-form-integration-for-js
1515
```
1616

17+
## Usage
18+
19+
### Initiating a payment
20+
21+
```js
22+
import { TransactionService, ITransaction, ITransactionDetail } from 'opayo-form-integration-for-js';
23+
24+
var transactionService = new TransactionService();
25+
26+
var transactionDetail = {
27+
"VendorTxCode": "PaymentReference-1",
28+
"Amount": "10.00",
29+
"Currency": "GBP",
30+
"Description": "Test transaction",
31+
"SuccessURL": "https://www.example.com/success",
32+
"FailureURL": "https://www.example.com/failure",
33+
"CustomerName": "John Smith",
34+
"CustomerEMail": "john.smith@email.com",
35+
"BillingSurname": "Smith",
36+
"BillingFirstnames": "John",
37+
"BillingAddress1": "1 High Street",
38+
"BillingCity": "London",
39+
"BillingPostCode": "EC1N 2TD",
40+
"BillingCountry": "GB",
41+
"DeliverySurname": "Smith",
42+
"DeliveryFirstnames": "John",
43+
"DeliveryAddress1": "1 High Street",
44+
"DeliveryCity": "London",
45+
"DeliveryPostCode": "EC1N 2TD",
46+
"DeliveryCountry": "GB",
47+
} as ITransactionDetail;
48+
49+
/*
50+
* Initiate transaction will return the object that has been transmitted to Opayo's Form Integration page in case you need it for reference.
51+
* Calling this method will automatically submit the data to Opayo and redirect the user to Opayo's Form Integration page.
52+
*/
53+
var transaction = await transactionService.initiateTransaction(transactionDetail, "opayotest", "your_encryption_password") as ITransaction;
54+
```
55+
56+
### Handling a response
57+
58+
```js
59+
import { TransactionService, ITransactionResponse } from 'opayo-form-integration-for-js';
60+
61+
var transactionService = new TransactionService();
62+
63+
/*
64+
* You will first need to grab the crypt value from the query string of the return URL from Opayo's Form Integration page.
65+
* Passing that value into the `handleTransactionResponse` method will decrypt the response using your Opayo Form Integration encryption password and return it.
66+
*/
67+
var urlParams = new URLSearchParams(window.location.search);
68+
var crypt = urlParams.get('crypt');
69+
var response = await transactionService.handleTransactionResponse(crypt, "your_encryption_password") as ITransactionResponse;
70+
```
71+
1772
## Contributing 🤝🏻
1873

1974
Contributions, issues and feature requests are welcome!

src/TransactionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class TransactionService implements ITransactionService {
5959
"PurchaseInstalData": new ValidatorArray(() => { }, new RegexValidator(/^\d+$/), new MaxLengthValidator(3)),
6060
}
6161

62-
constructor(isTestEnvironment: boolean) {
62+
constructor(isTestEnvironment: boolean = false) {
6363
this.isTestEnvironment = isTestEnvironment;
6464
}
6565

0 commit comments

Comments
 (0)