Skip to content

Commit

Permalink
Merge pull request #12 from AltaPay/agreement_engine_and_apple_pay
Browse files Browse the repository at this point in the history
support agreement parameters & new endpoints for Apple Pay
  • Loading branch information
emicha authored Jul 28, 2022
2 parents 90858b0 + cf8e9c7 commit 3623864
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 13 deletions.
6 changes: 6 additions & 0 deletions AltaPayFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,9 @@ AltaPayFactory.prototype.getUpdateOrderRequest = function(paymentId, orderLines)
return new UpdateOrderRequest(paymentId, orderLines, this.getBaseRequest());
};

/**
* @returns {AgreementConfig}
*/
AltaPayFactory.prototype.getAgreementConfig = function() {
return new AgreementConfig();
};
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.0.5]

- Add support for new 'Agreements Engine' parameters
- Add support for Apple Pay

## [1.0.4]

- Update format of the User-Agent header
Expand Down
32 changes: 32 additions & 0 deletions example/SimpleCreatePaymentRequestWithAgreementExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load('tests/basetest.js');

var factory = new RhinoAltaPayFactory(new AltaPayFactory());

var mapi = factory.getMerchantApi('shop api', 'testpassword', 'https://testgateway.altapaysecure.com');

var request = factory.getPaymentRequest();
request.terminal = 'AltaPay Test Terminal';
request.shopOrderid = "JS_AUI_simple_create_payment_"+makeid(16);
request.amount = '700';
request.currency = 'DKK';
request.type = AuthType.subscription;
var agreementConfig = factory.getAgreementConfig();
agreementConfig.agreementType = AgreementType.unscheduled;
agreementConfig.agreementUnscheduledType = AgreementUnscheduledType.incremental;
request.agreementConfig = agreementConfig;
var response = mapi.createPaymentRequest(request);
if(response.success()==true){
console.log("SimpleCreatePaymentRequestWithAgreementExample: success");
}
else {
console.log("SimpleCreatePaymentRequestWithAgreementExample: failed : "+response.getErrorMessage());
}

function makeid(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}

26 changes: 26 additions & 0 deletions lib/AgreementConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

function AgreementConfig() {
this.agreementId = null;
this.agreementType = null;
this.agreementUnscheduledType = null;
this.agreementExpiry = null;
this.agreementFrequency = null;
this.agreementNextChargeDate = null;
this.agreementAdminUrl = null;
this.agreementRetentionPeriod = null;
}

AgreementConfig.prototype.toHash = function() {
var result = {};

result.id = this.agreementId;
result.type = this.agreementType;
result.unscheduled_type = this.agreementUnscheduledType;
result.expiry = this.agreementExpiry;
result.frequency = this.agreementFrequency;
result.next_charge_date = this.agreementNextChargeDate;
result.admin_url = this.agreementAdminUrl;
result.retention_period = this.agreementRetentionPeriod;

return result;
};
9 changes: 9 additions & 0 deletions lib/AgreementType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Recognized agreement types (aka AgreementConfig.agreementType)
* @type {{recurring: string, instalment: string, unscheduled: string}}
*/
AgreementType = {
recurring: 'recurring'
, instalment: 'instalment'
, unscheduled: 'unscheduled'
}
12 changes: 12 additions & 0 deletions lib/AgreementUnscheduledType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Recognized agreement unscheduled types (aka AgreementConfig.agreementUnscheduledType)
* @type {{incremental: string, resubmission: string, delayedCharges: string, reauthorisation: string, noShow: string, charge: string}}
*/
AgreementUnscheduledType = {
incremental: 'incremental'
, resubmission: 'resubmission'
, delayedCharges: 'delayedCharges'
, reauthorisation: 'reauthorisation'
, noShow: 'noShow'
, charge: 'charge'
}
58 changes: 58 additions & 0 deletions lib/CardWalletAuthorizeRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @extends PaymentRequest
* @extends BaseRequest
* @constructor
* @param providerData
* @param terminal
* @param shopOrderid
* @param amount
* @param currency
*/
function CardWalletAuthorizeRequest(providerData, terminal, shopOrderid, amount, currency) {

// Required:
this.providerData = providerData;
this.terminal = terminal;
this.shopOrderid = shopOrderid;
this.amount = amount;
this.currency = currency;

// Optional:
this.paymentInfos = []; // transaction info
this.fraudService = null;
this.shippingMethod = null;
this.saleReconciliationIdentifier = null;
this.salesInvoiceNumber = null;
this.salesTax = null;
this.customerCreatedDate = null;
this.cookie = null;
this.language = null;

/**
* @type {CustomerInfo}
*/
this.customerInfo = null;

/**
* @type {OrderLine[]}
*/
this.orderLines = [];

// the order below matters:
ObjectHelper.extend(this, new PaymentRequest(new PaymentRequestBase(new PaymentRequestConfig(), new PaymentInfo()), this.customerInfo));
ObjectHelper.extend(this, new BaseRequest());

}

/**
* @param key {string}
* @returns {string}
*/
CardWalletAuthorizeRequest.prototype.transformHashKey = function(key) {

if (key == 'paymentInfos') {
return 'transaction_info';
}

return key.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
}
11 changes: 11 additions & 0 deletions lib/CardWalletAuthorizeResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param responseObject
* @extends BaseResponse
* @constructor
*/
function CardWalletAuthorizeResponse(responseObject)
{
this.responseObject = responseObject;

ObjectHelper.extend(this, new BaseResponse());
}
29 changes: 29 additions & 0 deletions lib/CardWalletSessionRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @constructor
* @param terminal
* @param validationUrl
* @param domain
*/
function CardWalletSessionRequest(terminal, validationUrl, domain)
{
this.terminal = terminal;
this.validationUrl = validationUrl;
this.domain = domain;

ObjectHelper.extend(this, new BaseRequest());
}

/**
*
* @param key {string}
* @returns {string}
* @private
*/
CardWalletSessionRequest.prototype.transformHashKey = function(key) {
if(key == 'validationUrl')
{
return 'validationUrl';
}

return key.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
}
11 changes: 11 additions & 0 deletions lib/CardWalletSessionResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param responseObject
* @extends BaseResponse
* @constructor
*/
function CardWalletSessionResponse(responseObject)
{
this.responseObject = responseObject;

ObjectHelper.extend(this, new BaseResponse());
}
7 changes: 6 additions & 1 deletion lib/ChargeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function ChargeRequest(baseRequest)
this.subscriptionPaymentId = '';
this.amount = null;
this.reconciliationIdentifier = null;
this.agreementUnscheduledType = null;

ObjectHelper.extend(this, baseRequest);
}
Expand All @@ -20,7 +21,11 @@ function ChargeRequest(baseRequest)
ChargeRequest.prototype.transformHashKey = function(key) {
if(key == 'subscriptionPaymentId')
{
return 'transaction_id';
return 'agreement[id]';
}
if(key == 'agreementUnscheduledType')
{
return 'agreement[unscheduled_type]';
}

return key.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion lib/JssdkVersion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

JssdkVersion = {
VERSION : 'sdk-js/1.0.4'
VERSION : 'sdk-js/1.0.5'
}
20 changes: 20 additions & 0 deletions lib/MerchantApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,23 @@ MerchantApi.prototype.getFundingCsv = function(link)
{
return this.http.post(link,{}, this.getHeaders());
};

/**
* @param request {CardWalletSessionRequest}
* @return {CardWalletSessionResponse}
*/
MerchantApi.prototype.cardWalletSession = function(request) {
var result = this.http.post(this.url+'/merchant/API/cardWallet/session', request.toHash(), this.getHeaders());
var responseObject = this.xml.deserialize(result);
return this.responseFactory.getCardWalletSessionResponse(responseObject)
};

/**
* @param request {CardWalletAuthorizeRequest}
* @return {CardWalletAuthorizeResponse}
*/
MerchantApi.prototype.cardWalletAuthorize = function(request) {
var result = this.http.post(this.url+'/merchant/API/cardWallet/authorize', request.toHash(), this.getHeaders());
var responseObject = this.xml.deserialize(result);
return this.responseFactory.getCardWalletAuthorizeResponse(responseObject)
};
10 changes: 10 additions & 0 deletions lib/PaymentRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function PaymentRequest(paymentRequestBase, customerInfo) {
*/
this.accountOffer = null;

/**
* @type {AgreementConfig}
*/
this.agreementConfig = null;


ObjectHelper.extend(this, new BaseRequest());
ObjectHelper.extend(this, paymentRequestBase);
}
Expand Down Expand Up @@ -105,6 +111,10 @@ PaymentRequest.prototype.transformHashKey = function(key) {
{
return 'type';
}
if(key == 'agreementConfig')
{
return 'agreement';
}

return key.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
}
4 changes: 4 additions & 0 deletions lib/ReservationRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ ReservationRequest.prototype.transformHashKey = function(key) {
else if (key == 'expiryYear') {
return 'eyear';
}
else if(key == 'agreementConfig')
{
return 'agreement';
}
else {
return key.replace(/([a-z])([A-Z])/g,'$1_$2').toLowerCase();
}
Expand Down
17 changes: 17 additions & 0 deletions lib/ResponseFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ ResponseFactory.prototype.getFundingRecord = function(data)
return new FundingRecord(data);
}

/**
* @param responseObject
* @returns {CardWalletSessionResponse}
*/
ResponseFactory.prototype.getCardWalletSessionResponse = function (responseObject)
{
return new CardWalletSessionResponse(responseObject);
};

/**
* @param responseObject
* @returns {CardWalletAuthorizeResponse}
*/
ResponseFactory.prototype.getCardWalletAuthorizeResponse = function (responseObject)
{
return new CardWalletAuthorizeResponse(responseObject);
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altapay-js-api",
"version": "1.0.4",
"version": "1.0.5",
"description": "This is an SDK for AltaPay written in JavaScript. It is written in a way that makes it possible to use in whatever JavaScript context is necessary (Node, Rhino etc).",
"main": "Rhino-AltaPay-Jssdk.js",
"directories": {
Expand Down
1 change: 1 addition & 0 deletions tasks/runExamples.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

java -jar tests/js.jar example/SimpleCreatePaymentRequestExample.js
java -jar tests/js.jar example/SimpleCreatePaymentRequestWithAgreementExample.js
java -jar tests/js.jar example/ComplexCreatePaymentRequestExample.js
java -jar tests/js.jar example/SimpleCaptureExample.js
java -jar tests/js.jar example/SimplePartialCaptureExample.js
Expand Down
Loading

0 comments on commit 3623864

Please sign in to comment.