Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swish 2 #600

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ AUTH_REQUIRED='true'
EFFEKT_PORT='5050'
EFFEKT_HOST='localhost'

MIN_SIDE_URL=''
EFFEKT_API_URL=''
MIN_SIDE_URL='http://localhost:3000'
EFFEKT_API_URL='http://localhost:5050'

SWISH_CERT=''
SWISH_CERT_KEY=''
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The API is also responsible for handling payment processing.
- [Vipps](#vipps)
- [PayPal](#paypal)
- [Facebook](#facebook)
- [Swish](#swish)

---

Expand Down Expand Up @@ -599,15 +600,19 @@ gcloud run jobs create <SERVICE_NAME>-db-migrate \

### Bank

### Vipps 🇳🇴
### Vipps

🇳🇴

> ❗ **NOK only**

### PayPal

### Facebook

### Swish 🇸🇪
### Swish

🇸🇪

> ❗ **SEK only**

Expand Down
48 changes: 48 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@
"validator": "^13.7.0"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@faker-js/faker": "^8.0.2",
"@types/chai": "^4.3.5",
"@types/express": "^4.17.13",
"@types/express-fileupload": "1.4.1",
"@types/express-rate-limit": "6.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.16",
"@types/node-fetch": "^2.6.4",
"@types/request-promise-native": "^1.0.17",
"@types/sinon": "^7.5.2",
"@types/supertest": "^2.0.12",
Expand Down
19 changes: 19 additions & 0 deletions prisma/migrations/20230801082512_swish_rename_table/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALTER TABLE `Swish_order` RENAME TO `Swish_orders`;

-- DropForeignKey
ALTER TABLE `Swish_orders` DROP FOREIGN KEY `Swish_order_donationID_fkey`;

-- DropForeignKey
ALTER TABLE `Swish_orders` DROP FOREIGN KEY `Swish_order_donorID_fkey`;

-- AddForeignKey
ALTER TABLE `Swish_orders` ADD CONSTRAINT `Swish_orders_donorID_fkey` FOREIGN KEY (`donorID`) REFERENCES `Donors`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Swish_orders` ADD CONSTRAINT `Swish_orders_donationID_fkey` FOREIGN KEY (`donationID`) REFERENCES `Donations`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE;

-- RenameIndex
ALTER TABLE `Swish_orders` RENAME INDEX `Swish_order_donationID_key` TO `Swish_orders_donationID_key`;

-- RenameIndex
ALTER TABLE `Swish_orders` RENAME INDEX `Swish_order_instructionUUID_key` TO `Swish_orders_instructionUUID_key`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- DropIndex
DROP INDEX `Swish_order_KID_key` ON `Swish_orders`;
30 changes: 15 additions & 15 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ model Distribution {
}

model Donations {
ID Int @id @unique(map: "ID_UNIQUE") @default(autoincrement()) /// Unik donasjonsID
ID Int @id @unique(map: "ID_UNIQUE") @default(autoincrement()) /// Unik donasjonsID
Donor_ID Int /// Foreign key til donor_id
Payment_ID Int /// Foreign key til Payment_ID
PaymentExternal_ID String? @unique(map: "PaymentExternal_ID_UNIQUE") @db.VarChar(32) /// Payment ID in external system (ex: Vipps)
sum_confirmed Decimal @db.Decimal(16, 2) /// Donert sum bekreftet fra betalingstjeneste (NOK)
timestamp_confirmed DateTime @default(now()) @db.Timestamp(0) /// Timestamp/dato når donasjon er bekreftet fra betalingstjeneste
transaction_cost Decimal? @db.Decimal(16, 2) /// beregnet transaction cost basert på Payment_ID (oppslag på kostnad) og sum confirmed
KID_fordeling String @db.VarChar(16) /// Same as KID. Used to join to Combining_table for distribution percentages (registrert KID fra betalingstjeneste, oppslag i donations_distribution for Donor_ID)
inserted DateTime? @default(now()) @db.Timestamp(0)
last_updated DateTime? @default(now()) @db.Timestamp(0)
Meta_owner_ID Int @default(3)
Donors Donors @relation(fields: [Donor_ID], references: [ID], onDelete: Cascade, map: "fk_Donations_to_Donors_ID")
Payment Payment @relation(fields: [Payment_ID], references: [ID], onDelete: Cascade, map: "fk_Donations_to_Payment")
Swish_order Swish_order?
PaymentExternal_ID String? @unique(map: "PaymentExternal_ID_UNIQUE") @db.VarChar(32) /// Payment ID in external system (ex: Vipps)
sum_confirmed Decimal @db.Decimal(16, 2) /// Donert sum bekreftet fra betalingstjeneste (NOK)
timestamp_confirmed DateTime @default(now()) @db.Timestamp(0) /// Timestamp/dato når donasjon er bekreftet fra betalingstjeneste
transaction_cost Decimal? @db.Decimal(16, 2) /// beregnet transaction cost basert på Payment_ID (oppslag på kostnad) og sum confirmed
KID_fordeling String @db.VarChar(16) /// Same as KID. Used to join to Combining_table for distribution percentages (registrert KID fra betalingstjeneste, oppslag i donations_distribution for Donor_ID)
inserted DateTime? @default(now()) @db.Timestamp(0)
last_updated DateTime? @default(now()) @db.Timestamp(0)
Meta_owner_ID Int @default(3)
Donors Donors @relation(fields: [Donor_ID], references: [ID], onDelete: Cascade, map: "fk_Donations_to_Donors_ID")
Payment Payment @relation(fields: [Payment_ID], references: [ID], onDelete: Cascade, map: "fk_Donations_to_Payment")
Swish_orders Swish_orders?

@@index([KID_fordeling, timestamp_confirmed], map: "KidAndTimestamp")
@@index([timestamp_confirmed], map: "Timestamp")
Expand All @@ -133,7 +133,7 @@ model Donors {
Funds_donations Funds_donations[]
Tax_unit Tax_unit[]
Vipps_agreements Vipps_agreements[]
Swish_orders Swish_order[]
Swish_orders Swish_orders[]

@@index([full_name(length: 63)], map: "full_name")
@@index([email(length: 63), full_name(length: 63)], map: "search")
Expand Down Expand Up @@ -266,9 +266,9 @@ model Seeded {
@@ignore
}

model Swish_order {
model Swish_orders {
ID Int @id @default(autoincrement())
KID String @unique @db.VarChar(15)
KID String @db.VarChar(15)
instructionUUID String @unique @db.VarChar(36) /// Swish uses this to identify the order
donorID Int
donationID Int? @unique
Expand Down
22 changes: 19 additions & 3 deletions src/__test__/donations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,23 @@ describe("donations", () => {
newsletter: true,
},
};
await request(server).post("/donations/register").send(body).expect(200);
const response = await request(server).post("/donations/register").send(body).expect(200);

expect(donorsAddStub.calledOnce).to.be.true;
expect(donorsAddStub.firstCall.args[0]).to.deep.equal({
email: body.donor.email,
full_name: body.donor.name,
newsletter: body.donor.newsletter,
});

expect(response.body).to.deep.equal({
content: {
hasAnsweredReferral: false,
paymentProviderUrl: "",
swishOrderID: null,
},
status: 200,
});
});

it("should add tax unit to added donor", async () => {
Expand Down Expand Up @@ -144,9 +153,11 @@ describe("donations", () => {
});

it("should initiate swish order", async () => {
const stub = sinon.stub(swish, "initiateOrder");
const KID = "1234567890";
withCreatedKID(KID);
const stub = sinon.stub(swish, "initiateOrder");
const orderID = "123";
stub.resolves({ orderID, paymentRequestToken: "123" });

const body = {
method: methods.SWISH,
Expand All @@ -155,11 +166,16 @@ describe("donations", () => {
recurring: false,
donor: {},
};
await request(server).post("/donations/register").send(body).expect(200);
const response = await request(server).post("/donations/register").send(body).expect(200);

expect(stub.calledOnce).to.be.true;
expect(stub.firstCall.args[0]).to.equal(KID);
expect(stub.firstCall.args[1]).to.deep.equal({ amount: body.amount, phone: body.phone });

expect(response.body)
.to.have.property("content")
.that.has.property("swishOrderID")
.equal(orderID);
});

it("should return 400 if missing body", async () => {
Expand Down
Loading