Skip to content

Commit

Permalink
adds payment error, fixes checkout payment urls (#13)
Browse files Browse the repository at this point in the history
* adds payment error, fixes checkout url

* changes retrieve co payment url

* formats code with prettier

* fixes failing tests

Co-authored-by: Burak Baldırlıoğlu <[email protected]>
  • Loading branch information
Berkay and MasterSlave authored Feb 4, 2021
1 parent ad1cefd commit fb28d1a
Show file tree
Hide file tree
Showing 19 changed files with 5,605 additions and 57 deletions.
5,576 changes: 5,558 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/CraftgateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import BaseAdapter from './adapter/BaseAdapter';
import InstallmentAdapter from './adapter/InstallmentAdapter';
import OnboardingAdapter from './adapter/OnboardingAdapter';
import PaymentAdapter from './adapter/PaymentAdapter';
import WalletAdapter from "./adapter/WalletAdapter";

import WalletAdapter from './adapter/WalletAdapter';
import {ClientCreationOptions} from './lib/HttpClient';

export default class CraftgateAdapter extends BaseAdapter {
Expand Down
18 changes: 9 additions & 9 deletions src/adapter/PaymentAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import {ClientCreationOptions} from '../lib/HttpClient';

import ApprovePaymentTransactionsRequest from '../request/ApprovePaymentTransactionsRequest';
import CompleteThreeDSPaymentRequest from '../request/CompleteThreeDSPaymentRequest';
import CreateDepositPaymentRequest from '../request/CreateDepositPaymentRequest';
import CreatePaymentRequest from '../request/CreatePaymentRequest';
import DeleteStoredCardRequest from '../request/DeleteStoredCardRequest';
import DisapprovePaymentTransactionsRequest from '../request/DisapprovePaymentTransactionsRequest';
import InitCheckoutPaymentRequest from '../request/InitCheckoutPaymentRequest';
import InitThreeDSPaymentRequest from '../request/InitThreeDSPaymentRequest';
import RefundDepositPaymentRequest from '../request/RefundDepositPaymentRequest';
import RefundPaymentRequest from '../request/RefundPaymentRequest';
import RefundPaymentTransactionRequest from '../request/RefundPaymentTransactionRequest';
import SearchPaymentTransactionRefundsRequest from '../request/SearchPaymentTransactionRefundsRequest';
import SearchStoredCardsRequest from '../request/SearchStoredCardsRequest';
import StoreCardRequest from "../request/StoreCardRequest";
import RefundDepositPaymentRequest from "../request/RefundDepositPaymentRequest";
import CreateDepositPaymentRequest from "../request/CreateDepositPaymentRequest";
import InitCheckoutPaymentRequest from "../request/InitCheckoutPaymentRequest";
import StoreCardRequest from '../request/StoreCardRequest';

import DataResponse from '../response/DataResponse';
import DepositPaymentRefundResponse from '../response/DepositPaymentRefundResponse';
import DepositPaymentResponse from '../response/DepositPaymentResponse';
import InitCheckoutPaymentResponse from '../response/InitCheckoutPaymentResponse';
import InitThreeDSPaymentResponse from '../response/InitThreeDSPaymentResponse';
import PaymentRefundResponse from '../response/PaymentRefundResponse';
import PaymentResponse from '../response/PaymentResponse';
import PaymentTransactionApprovalListResponse from '../response/PaymentTransactionApprovalListResponse';
import PaymentTransactionRefundListResponse from '../response/PaymentTransactionRefundListResponse';
import PaymentTransactionRefundResponse from '../response/PaymentTransactionRefundResponse';
import StoredCardResponse from '../response/StoredCardResponse';
import DepositPaymentResponse from "../response/DepositPaymentResponse";
import DepositPaymentRefundResponse from "../response/DepositPaymentRefundResponse";
import InitCheckoutPaymentResponse from "../response/InitCheckoutPaymentResponse";

import BaseAdapter from './BaseAdapter';

Expand All @@ -51,11 +51,11 @@ export default class PaymentAdapter extends BaseAdapter {
}

async initCheckoutPayment(request: InitCheckoutPaymentRequest): Promise<InitCheckoutPaymentResponse> {
return this._client.post('/payment/v1/checkout-payment/init', request);
return this._client.post('/payment/v1/checkout-payments/init', request);
}

async retrieveCheckoutPayment(token: string): Promise<PaymentResponse> {
return this._client.get(`/payment/v1/checkout-payment?token=${token}`);
return this._client.get(`/payment/v1/checkout-payments/${token}`);
}

async createDepositPayment(request: CreateDepositPaymentRequest): Promise<DepositPaymentResponse> {
Expand Down
16 changes: 8 additions & 8 deletions src/adapter/WalletAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ClientCreationOptions} from '../lib/HttpClient';

import SearchWalletsRequest from "../request/SearchWalletsRequest";
import SearchWalletTransactionsRequest from "../request/SearchWalletTransactionsRequest";
import CreateRemittanceRequest from "../request/CreateRemittanceRequest";

import DataResponse from "../response/DataResponse";
import WalletResponse from "../response/WalletResponse";
import RemittanceResponse from "../response/RemittanceResponse";
import WalletTransactionResponse from "../response/WalletTransactionResponse";
import CreateRemittanceRequest from '../request/CreateRemittanceRequest';
import SearchWalletsRequest from '../request/SearchWalletsRequest';
import SearchWalletTransactionsRequest from '../request/SearchWalletTransactionsRequest';

import DataResponse from '../response/DataResponse';
import RemittanceResponse from '../response/RemittanceResponse';
import WalletResponse from '../response/WalletResponse';
import WalletTransactionResponse from '../response/WalletTransactionResponse';

import BaseAdapter from './BaseAdapter';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function generateRandomString(length = 6): string {
*
* @param components the components to calculate the signature from
*/
export function calculateSignature({apiKey, secretKey, url, body, randomStr}: { apiKey: string; secretKey: string; url: string; randomStr: string; body?: string }): string {
export function calculateSignature({apiKey, secretKey, url, body, randomStr}: {apiKey: string; secretKey: string; url: string; randomStr: string; body?: string}): string {
const hashStr: string = [url, apiKey, secretKey, randomStr, body].filter(s => !!s).join('');
const hash = crypto.SHA256(hashStr);
return crypto.enc.Base64.stringify(hash);
Expand Down
4 changes: 2 additions & 2 deletions src/request/CreateMemberRequest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MemberType from '../model/MemberType';
import SettlementEarningsDestination from "../model/SettlementEarningsDestination";
import SettlementEarningsDestination from '../model/SettlementEarningsDestination';

type CreateMemberRequest = {
isBuyer?: boolean,
isBuyer?: boolean;
isSubMerchant?: boolean;
memberType?: MemberType;
memberExternalId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/request/CreateRemittanceRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RemittanceReasonType from "../model/RemittanceReasonType";
import RemittanceReasonType from '../model/RemittanceReasonType';

type CreateRemittanceRequest = {
memberId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/request/InitThreeDSPaymentRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Currency from '../model/Currency';
import Installment from '../model/Installment';
import PaymentGroup from '../model/PaymentGroup';
import PaymentPhase from '../model/PaymentPhase';

import {Card} from './dto/Card';
import PaymentItem from './dto/PaymentItem';
import PaymentPhase from "../model/PaymentPhase";

type InitThreeDSPaymentRequest = {
price: number;
Expand Down
2 changes: 1 addition & 1 deletion src/request/SearchWalletTransactionsRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WalletTransactionType from "../model/WalletTransactionType";
import WalletTransactionType from '../model/WalletTransactionType';

type SearchWalletTransactionsRequest = {
walletTransactionType?: WalletTransactionType;
Expand Down
6 changes: 3 additions & 3 deletions src/request/UpdateMemberRequest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MemberType from "../model/MemberType";
import SettlementEarningsDestination from "../model/SettlementEarningsDestination";
import MemberType from '../model/MemberType';
import SettlementEarningsDestination from '../model/SettlementEarningsDestination';

type UpdateMemberRequest = {
isBuyer?: boolean,
isBuyer?: boolean;
isSubMerchant?: boolean;
memberType?: MemberType;
name?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/response/InstallmentListResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Installment from './dto/Installment'
import Installment from './dto/Installment';

type InstallmentListResponse = {
items: Installment[];
Expand Down
4 changes: 2 additions & 2 deletions src/response/MemberResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Status from '../model/Status';
import MemberType from '../model/MemberType';
import SettlementEarningsDestination from "../model/SettlementEarningsDestination";
import SettlementEarningsDestination from '../model/SettlementEarningsDestination';
import Status from '../model/Status';

type MemberResponse = {
id: number;
Expand Down
4 changes: 3 additions & 1 deletion src/response/PaymentResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import PaymentStatus from '../model/PaymentStatus';
import PaymentType from '../model/PaymentType';

import PaymentTransaction from './dto/PaymentTransaction';
import MerchantPos from "./dto/MerchantPos";
import MerchantPos from './dto/MerchantPos';
import PaymentError from './dto/PaymentError';

type PaymentResponse = {
id: number;
Expand Down Expand Up @@ -36,6 +37,7 @@ type PaymentResponse = {
cardAssociation: CardAssociation;
cardBrand: string;
pos: MerchantPos;
paymentError: PaymentError;
paymentTransactions: PaymentTransaction[];
};

Expand Down
2 changes: 1 addition & 1 deletion src/response/PaymentTransactionRefundListResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PaymentTransactionRefundResponse from './PaymentTransactionRefundResponse'
import PaymentTransactionRefundResponse from './PaymentTransactionRefundResponse';

type PaymentTransactionRefundListResponse = {
size: number;
Expand Down
4 changes: 2 additions & 2 deletions src/response/RemittanceResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RemittanceReasonType from '../model/RemittanceReasonType';
import RemittanceType from '../model/RemittanceType';
import Status from '../model/Status';
import RemittanceReasonType from "../model/RemittanceReasonType";
import RemittanceType from "../model/RemittanceType";

type RemittanceResponse = {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion src/response/WalletResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Currency from "../model/Currency";
import Currency from '../model/Currency';

type WalletResponse = {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion src/response/WalletTransactionResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WalletTransactionType from "../model/WalletTransactionType";
import WalletTransactionType from '../model/WalletTransactionType';

type WalletTransactionResponse = {
id: number;
Expand Down
7 changes: 7 additions & 0 deletions src/response/dto/PaymentError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type PaymentError = {
errorCode: string;
errorDescription: string;
errorGroup: string;
};

export default PaymentError;
4 changes: 2 additions & 2 deletions test/adapter/PaymentAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ test('should create deposit payment', async t => {

test('should init checkout payment', async t => {
const scope = nock('http://localhost:8000')
.post('/payment/v1/checkout-payment/init')
.post('/payment/v1/checkout-payments/init')
.reply(200, {
data: {
token: 'd1811bb0-25a2-40c7-ba71-c8b605259611',
Expand Down Expand Up @@ -367,7 +367,7 @@ test('should retrieve payment', async t => {

test('should retrieve checkout payment', async t => {
const scope = nock('http://localhost:8000')
.get('/payment/v1/checkout-payment?token=d1811bb0-25a2-40c7-ba71-c8b605259611')
.get('/payment/v1/checkout-payments/d1811bb0-25a2-40c7-ba71-c8b605259611')
.reply(200, {
data: {
id: 1,
Expand Down

0 comments on commit fb28d1a

Please sign in to comment.