Skip to content

Instantly share code, notes, and snippets.

View zalun's full-sized avatar

Piotr Zalewa zalun

View GitHub Profile
@zalun
zalun / test_b_get_field.py
Created February 13, 2023 17:46
Coder's Adventures: Triggering an old bug with a new code
# test_b_get_field.py
from .get_field import get_field
from .resource import IMPORTANT_DICT
def test_get_field_minimal():
assert get_field() is None
def test_get_field_another_key():
@zalun
zalun / plugins.js
Created May 9, 2022 18:22
email plugin with Sendgrid credentials
// ...
email: {
config: {
provider: "sendgrid",
providerOptions: {
apiKey: env("SENDGRID_API_KEY")
}
},
settings: {
defaultFrom: 'some@email.com',
curl -X 'POST' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"order": {
"orderId": "MB45CC6D2V220424GUEST000P01",
"extOrderId": "600f0125-6595-4633-a701-f8a2f480d70e",
"orderCreateDate": "2022-04-24T11:20:59.521+02:00",
"notifyUrl": "https://webhook.site/5e25fb1d-a0cb-47ef-b8f7-f71ca7f7d5cc",
"customerIp": "127.0.0.1",
{
"transaction": {
"id": 76,
"customerIp": "127.0.0.1",
"description": "test",
"currencyCode": "PLN",
"totalAmount": "1000",
"buyer": null,
"products": [
{
curl \
-X 'POST' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"currencyCode":"PLN",
"totalAmount": "1000",
"description":"test",
"customerIp": "127.0.0.1",
"products": [{
// src/index.js
"use strict";
module.exports = {
register(/*{ strapi }*/) {},
bootstrap({ strapi }) {
strapi.db.lifecycles.subscribe((event) => {
if (
event.action === "afterUpdate" &&
event.model.uid == "plugin::payu.transaction"
// api/product/services/product.js
"use strict";
const { createCoreService } = require("@strapi/strapi").factories;
module.exports = createCoreService("api::product.product", ({ strapi }) => ({
async handleTransactionUpdate(event) {
const { result } = event;
strapi.log.info(
`Acting upon an updated transaction - id: ${result.id}, status: ${result.status}`
// config/plugins.js
module.exports = {
payu: {
enabled: true,
resolve: "./src/plugins/payu",
},
shop: {
enabled: true,
resolve: "./src/plugins/shop",
{
action: 'afterUpdate',
model: {
singularName: 'transaction',
uid: 'plugin::payu.transaction',
tableName: 'transactions',
attributes: {
id: [Object],
uid: [Object],
configurationMode: [Object],
// src/index.js
module.exports = {
register(/*{ strapi }*/) {},
bootstrap({ strapi }) {
strapi.db.lifecycles.subscribe((event) => {
if (event.action === "afterUpdate") {
console.log(event);
}
});