Skip to content

rodneymandap/paymongo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Paymongo Python Library

The Paymongo Python library provides convenient access to the Paymongo API from applications written in the Python language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Paymongo API.

INSTALLATION

You don't need this source code unless you want to modify the package. If you just want to use the package, just run:

pip install --upgrade paymongo

Install from source with:

python setup.py install

USAGE

from paymongo import Paymongo

secret_key = 'sk_test_......'
payment_intent_payload = {
    "data": {
        "attributes": {"amount": 10000, "payment_method_allowed": ["card"], "description": "test1",
                       "statement_descriptor": "test2",
                       "payment_method_options": {"card": {"request_three_d_secure": "automatic"}}, "currency": "PHP"}
    }
}

payment_method_payload = {
    "data": {
        "attributes": {"type": "card",
                       "details": {"card_number": "4343434343434345", "exp_month": 10, "exp_year": 22, "cvc": "123"}
                       }
    }
}

paymongo = Paymongo(secret_key)

PAYMENT METHODS

Official Docs

A PaymentMethod resource describes which payment method was used to fulfill a payment. It is used with a PaymentIntent to collect payments.

paymongo.payment_methods

Payment Methods - Create

/**
 * These are the required properties
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {string} data.attributes.type The type of payment method. The possible value is card for now.
 * @param {string} data.attributes.details.card_number Credit/Debit Card number of the PaymentMethod.
 * @param {number} data.attributes.details.exp_month Expiry month of the Credit/Debit Card.
 * @param {number} data.attributes.details.exp_year Expiry year of the Credit/Debit Card.
 * @param {string} data.attributes.details.cvc CVC of the Credit/Debit Card.
 */
result = paymongo.payment_methods.create(data);

Payload

payment_method_payload = {
    "data": {
        "attributes": {"type": "card",
                       "details": {"card_number": "4343434343434345", "exp_month": 10, "exp_year": 22, "cvc": "123"}
                       }
    }
}

Payment Methods - Retrieve

/**
 * @param {string} id The PaymentMethod id
 */
result = paymongo.payment_method.retrieve(id);

PAYMENT INTENTS

Official Docs

A PaymentIntent resource is used to track and handle different states of the payment until it succeeds.

paymongo.payment_intents

Payment Intents - Create

/**
 * These are the required properties
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {number} data.attributes.amount Amount to be collected by the PaymentIntent.
 * @param {string[]} data.attributes.payment_method_allowed The list of payment method types that the PaymentIntent is allowed to use. Possible value is card for now.
 * @param {string} data.attributes.currency Three-letter ISO currency code, in uppercase. PHP is the only supported currency as of the moment.
 */
result = paymongo.payment_intents.create(data);

Payload

payment_intent_payload = {
    "data": {
        "attributes": {"amount": 10000, "payment_method_allowed": ["card"], "description": "test1",
                       "statement_descriptor": "test2",
                       "payment_method_options": {"card": {"request_three_d_secure": "automatic"}}, "currency": "PHP"}
    }
}

Payment Intents - Retrieve

/**
 * @param {string} id token id
 */
result = paymongo.payment_intents.retrieve(id);

Attach to PaymentIntent

/**
 * These are the required properties
 * @param {string} id PaymentIntent id.
 * @param {Object} data The payload.
 * @param {Object} data.attributes Payload attributes.
 * @param {string} data.attributes.payment_method Id of PaymentMethod to attach to the PaymentIntent.
 */
result = paymongo.payment_intents.attach(id, data);

Payload

payload = {
    "data": {
        "attributes": {"client_key": "card",
                       "payment_method": method_id
                       }
    }
}

SOURCES

Official Docs

A Source is a resource to generate your customer's payment instrument. This is normally used to generate check out URLs for e-wallet payments. To learn more about e-wallet integrations, you can visit GCash or GrabPay integration.

paymongo.sources

Sources - Create

/**
 * These are the required properties
 * @param {Object} data payload
 * @param {Object} data.attributes payload attributes
 * @param {string} data.attributes.type The type of source. Possible values are gcash and grab_pay.
 * @param {number} data.attributes.amount amount int32
 * @param {string} data.attributes.currency Three-letter ISO currency code, in uppercase. PHP is the only supported currency as of the moment.
 * @param {Object} data.attributes.redirect
 * @param {string} data.attributes.redirect.success success url
 * @param {string} data.attributes.redirect.failed error url
 */
result = paymongo.sources.create(data);

Payload

payment_source_payload = {
    "data": {
        "attributes": {"type": "gcash",
                       "amount": 10000,
                       "currency": "PHP",
                       "redirect": {
                           "success": "https://wela.online",
                           "failed": "https://bai.ph"
                       }
                       }
    }
}

PAYMENTS

Official Docs

A Payment resource is an attempt by your customer to send you money in exchange for your product. This is a reference to an amount that you are expecting to receive if a payment resource with paid status becomes a part of a payout. If the payment status is failed, you can determine the reason for failure.

paymongo.payments

Payments - Create

/**
 * These are the required properties
 * @param {Object} data payload
 * @param {Object} data.attributes payload attributes
 * @param {number} data.attributes.amount amount int32
 * @param {number} data.attributes.currency Three-letter ISO currency code, in uppercase. PHP is the only supported currency as of the moment.
 * @param {Object} data.attributes.source the source object from checkout
 * @param {string} data.attributes.source.id id of a Source resource
 * @param {string} data.attributes.source.type type of a Source resource. Possible value is 'source'.
 */
result = paymongo.payments.create(data);

Payload

payment_payload = {
    "data": {
        "attributes": {"description": "test2",
                       "statement_descriptor": "test3",
                       "amount": 10000,
                       "currency": "PHP",
                       "source": {
                           "id": payment_source_id,
                           "type": "source"
                       }
                       }
    }
}

Payments - List

result = paymongo.payments.list();

Result

{
  data: [] // array of payments
}

Payments - Retrieve

/**
 * @param {string} id payment id
 */
result = paymongo.payments.retrieve();

WEBHOOKS

Official Docs

A Webhook resource primarily refers to a certain URL where we send events that are happening from your account. You can check our GCash and GrabPay integrations to find out some good use cases for webhooks.

paymongo.webhooks

Webhooks - Create

/**
 * These are the required properties
 * @param {Object} data payload
 * @param {Object} data.attributes payload attributes
 * @param {string} data.attributes.url The destination URL of the events that happened from your account. Please make sure that the URL is publicly accessible in order for you to receive the event.
 * @param {string[]} data.attributes.events The list of events to be sent to this webhook. Possible value in the meantime is source.chargeable.
 */
const result = await paymongo.webhooks.create(data);

Payload

{
  data: {
    attributes: {
      url: 'https://yourwebsite.com/webook-listener', // Developer's note: this is unique in paymongo. You can't create multiple webhooks with same url.
      events: ['source.chargeable'] // The only event supported for now is 'source.chargeable'.
    }
  }
}

Webhooks - List

result = paymongo.webhooks.list();

Result

{
  data: [] // Array of webhooks
}

Webhooks - Retrieve

/**
 * @param {string} id Webhook id
 */
result = paymongo.webhooks.retrieve(id);

Webhooks - Toggle

Enable or disable a webhook.

/**
 * @param {string} id webhook id
 * @param {string} action 'enable' or 'disable'
 */
result = paymongo.webhooks.toggle(id, action);

TEST CARDS

Card Number Brand CVC Expiration Date
4343434343434345 Visa Any 3 digits Any future date
4571736000000075 Visa (debit) Any 3 digits Any future date
5555444444444457 Mastercard Any 3 digits Any future date
2221000000000918 Mastercard (2-series) Any 3 digits Any future date
5455590000000009 Mastercard (debit) Any 3 digits Any future date
5339080000000003 Mastercard (prepaid) Any 3 digits Any future date

More cards here, including 3D Secure Test Cards.

FAQs

Made with ❤️ by Chris Ian Fiel / Wela School System

This package and documentaion is base on https://github.com/jofftiquez/paymongo. Thanks to Jofferson Ramirez Tiquez @jofftiquez!

About

Paymongo Python Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%