syahmiabbas / test-repository-research

0 stars 0 forks source link

Workflow does not fulfill all criterias #6

Open syahmiabbas opened 5 months ago

syahmiabbas commented 5 months ago

Selected Files: hello.txt, main.py, test.txt

{ step 1: "Student filter and select the study resources he/she wants to purchase on Marketplace UI, go to the cart page, enter their credit card details (Number, Expiration Date, CVC) and click on the submit payment button. UI generates paymentmethodID via Stripe API and invokes Purchase Study Resource(PSR) microservice (MS) and send all information to PSR" (not fulfilled, Reason: "The provided code does not include any implementation or interaction with the Marketplace UI or the payment process, indicating that this step is not executed.")

step 2: "PSR complex MS then invokes User MS via HTTP GET to get seller payment credentials (StripeAccountID)." (not fulfilled, Reason: "There is no evidence of the PSR microservice making an HTTP GET request to the User MS for seller payment credentials in the provided code.")

step 3: "User MS validates the request using its JWT middleware and retrieves the seller's payment credentials, specifically the Stripe Account ID." (not fulfilled, Reason: "The code does not show any interaction with User MS or validation processes, indicating this step is not fulfilled.")

step 4: "PSR MS then invokes Payment MS via HTTP POST and sends userID, sellerID, total price, description of purchase, sellers stripeAccountID and paymentMethodID." (not fulfilled, Reason: "There is no implementation of the PSR MS invoking the Payment MS or sending the required data.")

step 5: "Payment MS then processes the payment using Stripe API and returns the payment outcome generated from StripeAPI." (not fulfilled, Reason: "The code does not include any processing of payments or interaction with the Stripe API.")

step 6: "Successful outcome from Payment MS leads to PSR MS invoking StudyResource MS via HTTP GET to get study resource links." (not fulfilled, Reason: "There is no indication of a successful payment outcome or subsequent invocation of the StudyResource MS.")

step 7: "StudyResource MS looks for 1-1 match of sent resourceID(s) to url of resources stored on AWS S3 Bucket (resourceS3URL) and returns the URL(s)." (not fulfilled, Reason: "The code does not show any interaction with the StudyResource MS or retrieval of resource URLs.")

step 8: "PSR MS then sends a notification message to Notification MS via [RKEY] order.notification, which Notification MS then sends a message to the user's Telegram via a Telegram bot." (not fulfilled, Reason: "There is no implementation of sending notifications or interaction with the Notification MS.")

step 9: "PSR returns resource link(s) back to Marketplace UI which it then routes users to /marketplace/resource-links for students to see the resources they have purchased." (not fulfilled, Reason: "The code does not show any return of resource links to the Marketplace UI.")

step 10: "User submits invoice." (not fulfilled, Reason: "There is no implementation or indication of an invoice submission process.")

step 11: "User acknowledges." (not fulfilled, Reason: "The code does not include any acknowledgment process from the user.")

}

syahmiabbas commented 4 months ago

@kaenugget I need your help with this, here is my progress:

To address the issues you've outlined regarding the workflow, we need to implement a series of microservices that interact with each other to fulfill the entire process from selecting study resources to acknowledging the invoice. Below, I will provide a high-level overview and code snippets for each step of the workflow.

Step 1: Marketplace UI and Payment Processing

You will need a web framework (like Flask) to create the UI and handle payment processing. Below is a simplified example of how to implement the UI and payment processing:

{python}
from flask import Flask, request, jsonify
import stripe

app = Flask(__name__)

# Set your secret key. Remember to switch to your live secret key in production!
stripe.api_key = 'your_secret_key'

@app.route('/checkout', methods=['POST'])
def checkout():
    data = request.json
    try:
        # Create a payment method
        payment_method = stripe.PaymentMethod.create(
            type="card",
            card={
                "number": data['card_number'],
                "exp_month": data['exp_month'],
                "exp_year": data['exp_year'],
                "cvc": data['cvc'],
            },
        )
        # Invoke the Purchase Study Resource (PSR) microservice
        psr_response = requests.post('http://psr-ms-url/purchase', json={
            "user_id": data['user_id'],
            "seller_id": data['seller_id'],
            "payment_method_id": payment_method.id,
            "total_price": data['total_price'],
            "description": data['description']
        })
        return psr_response.json(), psr_response.status_code
    except Exception as e:
        return jsonify(error=str(e)), 403

if __name__ == '__main__':
    app.run(debug=True)

Step 2: PSR Microservice

The PSR microservice will handle the purchase logic and communicate with the User MS to retrieve seller payment credentials.

{python}
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)

@app.route('/purchase', methods=['POST'])
def purchase():
    data = request.json
    seller_id = data['seller_id']

    # Invoke User MS to get seller payment credentials
    user_response = requests.get(f'http://user-ms-url/seller/{seller_id}/credentials')

    if user_response.status_code == 200:
        seller_credentials = user_response.json()
        # Now invoke Payment MS
        payment_response = requests.post('http://payment-ms-url/process', json={
            "user_id": data['user_id'],
            "seller_id": seller_id,
            "total_price": data['total_price'],
            "description": data['description'],
            "stripe_account_id": seller_credentials['StripeAccountID'],
            "payment_method_id": data['payment_method_id']
        })

        if payment_response.status_code == 200:
            # Successful payment, now get resource links
            resource_response = requests.get('http://studyresource-ms-url/resources', params={"seller_id": seller_id})
            return resource_response.json(), resource_response.status_code
        else:
            return jsonify({"error": "Payment processing failed"}), 400
    else:
        return jsonify({"error": "Failed to retrieve seller credentials"}), 400

if __name__ == '__main__':
    app.run(port=5001, debug=True)

Step 3: User Microservice

This microservice will validate requests and provide seller payment credentials.

{python}
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/seller/<seller_id>/credentials', methods=['GET'])
def get_seller_credentials(seller_id):
    # Here you would typically fetch the seller's credentials from a database
    return jsonify({"StripeAccountID": "acct_1234567890"}), 200

if __name__ == '__main__':
    app.run(port=5002, debug=True)

Step 4: Payment Microservice

This microservice will process payments using the Stripe API.

{python}
from flask import Flask, request, jsonify
import stripe

app = Flask(__name__)

stripe.api_key = 'your_secret_key'

@app.route('/process', methods=['POST'])
def process_payment():
    data = request.json
    try:
        # Process the payment
        charge = stripe.Charge.create(
            amount=int(data['total_price'] * 100),  # Amount in cents
            currency='usd',
            source=data['payment_method_id'],
            description=data['description'],
            destination={
                'account': data['stripe_account_id'],
            },
        )
        return jsonify({"status": "success", "charge_id": charge.id}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 400

if __name__ == '__main__':
    app.run(port=5003, debug=True)

Step 5: Study Resource Microservice

This microservice will retrieve resource links based on the seller ID.

{python}
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/resources', methods=['GET'])
def get_resources():
    seller_id = request.args.get('seller_id')
    # Here you would typically fetch the resource URLs from a database or S3
    return jsonify({"resource_links": ["https://s3.amazonaws.com/bucket/resource1", "https://s3.amazonaws.com/bucket/resource2"]}), 200

if __name__ == '__main__':
    app.run(port=5004, debug=True)

Step 6: Notification Microservice

This microservice will handle sending notifications.

{python}
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/notify', methods=['POST'])
def notify():
    data = request.json
    # Here you would send a notification to the user via Telegram
    return jsonify({"status": "notification sent"}), 200

if __name__ == '__main__':
    app.run(port=5005, debug=True)

Step 7: Invoice Submission and Acknowledgment

You can implement endpoints for invoice submission and acknowledgment in the appropriate microservice.

{python}
@app.route('/invoice', methods=['POST'])
def submit_invoice():
    data = request.json
    # Process the invoice submission
    return jsonify({"status": "invoice submitted"}), 200

@app.route('/acknowledge', methods=['POST'])
def acknowledge():
    data = request.json
    # Process the acknowledgment
    return jsonify({"status": "acknowledged"}), 200

Summary

  1. Step 1: Implement the Marketplace UI to handle payment processing and invoke the PSR microservice.
  2. Step 2: Create the PSR microservice to handle purchases and communicate with the User MS.
  3. Step 3: Implement the User microservice to provide seller payment credentials.
  4. Step 4: Create the Payment microservice to process payments using Stripe.
  5. Step 5: Implement the Study Resource microservice to retrieve resource links.
  6. Step 6: Create the Notification microservice to send notifications.
  7. Step 7: Implement endpoints for invoice submission and acknowledgment.

Make sure to replace placeholder values and implement proper error handling and security measures in a production environment. This structure should help fulfill all the criteria outlined in your issue description.